Skip to content

Bindings to the [better-sqlite3] module for interaction with Sqlite databases.

License

Notifications You must be signed in to change notification settings

elliotlaster/bs-sqlite

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

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" ]
}

About

Bindings to the [better-sqlite3] module for interaction with Sqlite databases.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • OCaml 100.0%