bs-sqlite
v1.1.0
Published
A wrapper for the sqlite3 driver
Downloads
8
Maintainers
Readme
bs-sqlite
Bindings to the better-sqlite3 module for interaction with Sqlite databases.
Usage
Basic Select
let db = Sqlite.Connection.make ~path:"test.db" ~memory:Js.true_ ()
let _ = Sqlite.Connection.prepare db "SELECT 1 + 1 AS result"
|> Sqlite.Statement.get [||]
|> Js.log
)
Use un-named parameters
let db = Sqlite.Connection.make ~path:"test.db" ~memory:Js.true_ ()
let _ = Sqlite.Connection.prepare db "SELECT ? + ? AS result"
|> Sqlite.Statement.get [|1; 1|]
|> Js.log
)
Use named parameters
Using :x format
let db = Sqlite.Connection.make ~path:"test.db" ~memory:Js.true_ ()
let _ = Sqlite.Connection.prepare db "SELECT :x + :y AS result"
|> Sqlite.Statement.get_named [%bs.obj { x = 1; y = 2 }]
|> Js.log
)
Using $x format
let db = Sqlite.Connection.make ~path:"test.db" ~memory:Js.true_ ()
let _ = Sqlite.Connection.prepare db "SELECT $x + $y AS result"
|> Sqlite.Statement.get_named [%bs.obj { x = 1; y = 2 }]
|> Js.log
)
Using @x format
let db = Sqlite.Connection.make ~path:"test.db" ~memory:Js.true_ ()
let _ = Sqlite.Connection.prepare db "SELECT @x + @y AS result"
|> Sqlite.Statement.get_named [%bs.obj { x = 1; y = 2 }]
|> Js.log
)
How do I install it?
Inside of a BuckleScript project:
yarn install --save bs-sqlite
Then add bs-sqlite
to your bs-dependencies
in bsconfig.json
:
{
"bs-dependencies": [ "bs-sqlite" ]
}