Registry / database / bs-sql-common

bs-sql-common

JSON →
library6.0.0jsnpmunverified

Common interface for SQL-based Node.js drivers (MySQL, PostgreSQL, sqlite) in BuckleScript/ReasonML. Version 6.0.0 exposes a Functor that accepts any module implementing the Queryable interface, using Belt.Result for responses. Key differentiators: provides a consistent API across SQL backends, response decoding/inspection functions, a large integer ID type (encoded as strings), batch inserts/queries, and parameter substitution with named placeholders. Designed for the ReasonML/BuckleScript ecosystem, not plain JavaScript.

npm install bs-sql-common
INSTALL
IMPORT
SIG · BS-SQL-COMMON
B
bs-sql-common
databasejavascriptv6.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SqlCommon
let Sql = SqlCommon.Make(MySql2)
let Sql = require('bs-sql-common')
Must use the functor Make with a provider module (e.g., MySql2). Plain require will not work; this is an ES module (BuckleScript) and not a CJS package.
Sql.Response.Select
Sql.Response.Select.flatMap(decoder)
Sql module is created via Make; Response submodules are accessed after module creation.
Sql.Params
Sql.Params.positional(...) or Sql.Params.named(...)
Sql.Params([...])
Use positional or named helpers; not a direct array.

Connects to MySQL using bs-mysql2 provider, queries SHOW DATABASES, and logs the result with error handling.

// Quickstart: Connect to MySQL, query databases, log result (ReasonML) module Sql = SqlCommon.Make(MySql2); let db = Sql.Connection.connect(~host="127.0.0.1", ~port=3306, ~user="root", ~password=process.env["MYSQL_PWD"] ?? "", ()); Sql.query(~db, ~sql="SHOW DATABASES", fun | Belt.Result.Error(e) => Js.log2("ERROR: ", e) | Belt.Result.Ok(select) => { select |. Sql.Response.Select.flatMap(Json.Decode.dict(Json.Decode.string)) |. Belt.Array.map(x => Js.Dict.get(x, "Database") |> Option.get) |. Js.log2("DATABASES: ", _) }; Sql.Connection.close(db);
Debug
Known issues
breakingVersion 3 completely rewrote the API as a Functor; v2 code is incompatible.
fix
Update to use SqlCommon.Make(Provider) pattern; see migration guide.
affects: >=3.0.0
deprecatedCallback-based query interface is not deprecated but use of Belt.Result is encouraged; try/catch around synchronous decoders may not be needed.
fix
Prefer Belt.Result for composability.
affects: >=3.0.0
gotchaThe package is not published as a CJS or ESM JavaScript module; it is a BuckleScript/ReasonML library. It cannot be imported using plain Node.js require or import.
fix
Use in a BuckleScript/ReasonML project with bsconfig.json bs-dependencies.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'bs-sql-common'
Trying to require/import bs-sql-common in a plain Node.js project without BuckleScript.
fix
Set up a BuckleScript/ReasonML project with bsconfig.json and add bs-sql-common to bs-dependencies.
Uncaught exception: SqlCommon is not a function
Using SqlCommon() directly instead of SqlCommon.Make(Provider).
fix
Define module Sql = SqlCommon.Make(MySql2) (or other provider).
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
bs-mysql2optionalCommon provider used in examples and tests; the library itself is provider-agnostic, but most users pair it with a concrete driver like bs-mysql2.
Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
bs-sql-common — npm install bs-sql-common · libregistry