Basic libdbi implementation for QuickJS.
This code currently builds against QuickJS-2025-09-13
Edit Makefile and point QJSPATH to your quickjs root then just build with make.
Now you should be able to run the examples:
- example.js
DBI:
- open(type, opts) -> DBIHandle
- type - string - a valid dbd driver name
- opts - jsobject - dictionary containing connection parameters as keys and values
DBIHandle:
- exec(querystr, params) -> boolean
- querystr - string - the query string
- params - jsobject/array - parameters to fill placeholders within a query:
- if
paramsis an array, query placeholders "?" will be replaced, in turn, with the values - if
paramsis a dictionary object, query placeholders ":<key>" will be replaced with matching key values in the object
- query(querystr, params) -> DBIResult
- same parameters as
exec, but returns aDBIResult
- same parameters as
- close()
DBIResult:
- next() -> boolean
- first call will attempt to place the cursor at the first result row. subsequent calls will advance to the next row.
- if there are no (more) rows, returns FALSE, otherwise TRUE.
- get(field) -> variant
fieldmay be either the name of the field, or a numeric index within the results.- return value depends on the field type in the query result
- numfields() -> number
- numrows() -> number
- toArray(asdict) -> Array
- if
asdictis true, result rows will contain jsobject dictionaries associating each column name to each value. - if
asdictis false, result rows will contain Arrays of the values.
- if
See the example.
I'm aware that things like setting the current row, prepared statements, and other basic methods aren't implemented. Please don't hesitate to offer a PR if you get around to implementing such things before me.
This module hasn't been tested very thoroughly, bug reports are welcome.
Also check out my quickjs-net, quickjs-hash and quickjs-wolfssl modules.