I love parsing! I really do. There's something very satisfying about converting input into usable data structures that help me accomplish some task. P

Scrappy Parsing :: The Programmer's Stone

submited by
Style Pass
2024-10-26 03:00:02

I love parsing! I really do. There's something very satisfying about converting input into usable data structures that help me accomplish some task.

Parsing is important. How well we construct those data structures and the quality of the structures we choose can massively impact the work that comes after. We should probably all be worrying about parsing a little more than we do.

The good news is that Elixir is the best language I have ever worked with for doing serious parsing. Let's prove it. Let's pull the data out of a SQLite database file using vanilla Elixir and some tricks from my Scrappy Programmer Livebook series. (You don't need to have read that to follow along with this article. Everyone is welcome.)

We need a database, with some data in it, in order to have something interesting to parse. Let's programmatically create one. This is the one time we will reach for some helper libraries. We'll use one to talk directly to SQLite and another to invent fake data. Here's the code:

We're not really here to discuss this code, but, very briefly, it creates a new database table with four fields, adds on an index, and pumps 150 fake records into it. The only things in this code that effect what we are about to do are the fields in the table and index as well as the db_path variable. That holds the location of our database file in the temporary directory.

Leave a Comment
Related Posts