Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Ergonomic bindings to database drivers are so frustrating

$
0
0

I tried tuples but I didn’t know a way to writing a binding for a variable length tuple parameter, only an array worked, in this case I kludged it by using a string array.

i.e.

@module("mysql2/promise") external make: {..} => t = "createPool"
@send external query: (Pool.t, string, array<string>) => 'a = "query"

Even if I got the binding right, I’d have to send the created tuple immediately to the binding and not be able to build up a few layers around the driver, like I use Mysql.insert below

let create = async (~db: Mysql.Pool.t, ~userId: int, ~pageId: int, ~folderId: int) => {
  let sql = `insert into bookmarks (userId, pageId, folderId) values (?,?,?)`
  let args = [userId, pageId, folderId]->iatos // iatos is utility function that converts array<int> to array<string>
  // let args = (userId, pageId, folderId)
  let results = await Mysql.insert(~db, ~sql, ~args)
  results.insertId
}

Viewing all articles
Browse latest Browse all 2592

Trending Articles