Help us understand the problem. What is going on with this article?

AOJ day 18: Jajanmen, typed SQLite parameters

More than 1 year has passed since last update.

In previous posts, I wrote about using type-level parsing for URLs. While that's nice and all, it's not necessarily what seems readily usable to solve some problem. Luckily, I have a worse problem to talk about, but with a nice solution.

Often, I use SQLite from PureScript by using the sqlite3 library. This library lets me supply parameters by naming them, and providing a record that has properties where the labels match the ones in the query, so that the parameters are applied to the query. This is nice, but in typical usage, it's untyped in that I can easily forget to specify properties and cause my query to always fail.

Well, I can solve that, can't I? I have a static query that I'm going to be using the vast majority of the time, so I can put those Symbol parsing skills to use.

"Well-typed parameterized SQLite parameters with PureScript"

In this post, I wrote about how we can parse a type-level string to extract parameters that make up a record of parameters we need for our query, where the Symbol can be simply reflected to provide to sqlite3:


-- the type signature here is inferred:
  :: forall a b. J.AllowedParamType a => J.AllowedParamType b
  => SL.DBConnection -> { "$name" :: a, "$count" :: b } -> Aff Foreign
getEm db = J.queryDB db queryP
    queryP = SProxy :: SProxy "select name, count from mytable where name = $name and count = $count"

Since I wrote this post, I've given a couple of talks about this library and how people might get to using it.

Long form presented in Milan:

Short form presented in HaskellX as a lightning talk:

There's even a video of the HaskellX talk:

my new posts are on
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away