Registry / database / meadow-connection-sqlite

meadow-connection-sqlite

JSON →
library1.0.20jsnpmunverified

A SQLite database connection plugin for the Meadow ORM, wrapping better-sqlite3 as a Fable service provider. Version 1.0.20 requires Node >=22.5.0 and provides synchronous, high-performance SQLite access via better-sqlite3. Key features include automatic WAL journal mode on connect, DDL generation from Meadow table schemas (supporting ID, GUID, ForeignKey, Numeric, Decimal, String, Text, DateTime, Boolean types), in-memory database support via ':memory:', connection safety guards, and direct access to the underlying better-sqlite3 database instance. Unlike general SQLite libraries, this integrates tightly with the Meadow ORM and Fable dependency injection framework, making it suitable for Meadow-based projects but less flexible as a standalone SQLite solution.

npm install meadow-connection-sqlite
INSTALL
IMPORT
SIG · MEADOW-CONNECTION-
M
meadow-connection-sqlite
databasejavascriptv1.0.20
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.

MeadowConnectionSQLite
const MeadowConnectionSQLite = require('meadow-connection-sqlite');
import MeadowConnectionSQLite from 'meadow-connection-sqlite';
CommonJS only - no ES module support. The package does not export a module field, so ESM imports will fail with ERR_REQUIRE_ESM or similar.
connectAsync
connection.connectAsync((err, db) => {});
connection.connectAsync().then(db => {});
connectAsync uses a callback, not Promises. There is no promise-based API.
db (getter)
let stmt = connection.db.prepare('SELECT 1');
let stmt = connection.db().prepare('SELECT 1');
db is a getter, not a method. Do not call it as a function.

Demonstrates in-memory SQLite database setup via Fable, Meadow schema DDL, and direct better-sqlite3 query execution

const libFable = require('fable'); const MeadowConnectionSQLite = require('meadow-connection-sqlite'); let fable = new libFable({ SQLite: { SQLiteFilePath: ':memory:' } }); let connection = fable.instantiateServiceProvider( 'MeadowConnectionSQLite', {}, MeadowConnectionSQLite ); connection.connectAsync((pError, pDatabase) => { if (pError) { console.error('Connection failed:', pError); return; } // Create a table and insert data const schema = { TableName: 'Users', Columns: [ { ColumnName: 'id', Type: 'ID' }, { ColumnName: 'name', Type: 'String', Length: 100 }, { ColumnName: 'createdAt', Type: 'DateTime' } ] }; connection.createTable(schema, (err) => { if (err) throw err; const insert = connection.db.prepare('INSERT INTO Users (name) VALUES (?)'); insert.run('Alice'); console.log('User inserted'); }); });
Debug
Known issues
breakingRequires Node.js >= 22.5.0 due to better-sqlite3 native module compatibility. Older Node versions will cause installation or runtime failures.
fix
Upgrade Node.js to 22.5.0 or later.
affects: < 1.0.0 || all versions
gotchaThe package uses CommonJS (require) only. Importing with ES module syntax (import) will fail. There is no ESM entry point.
fix
Use require('meadow-connection-sqlite') and ensure your project uses CommonJS or wrap it in a dynamic import.
affects: all
gotchaconnectAsync uses a callback pattern, not Promises. Attempting to await it will hang indefinitely.
fix
Use the callback parameter: connection.connectAsync((err, db) => { ... }).
affects: all
deprecatedThe synchronous connect() method logs a warning and should not be used in production. It may be removed in future versions.
fix
Use connectAsync instead.
affects: >= 1.0.0
gotchaThe db getter returns the underlying better-sqlite3 database object directly. Modifying it (e.g., closing it) may break the Meadow connection state.
fix
Avoid calling db.close() manually. Use meadow-connection-sqlite methods for cleanup.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'meadow-connection-sqlite'
Package not installed or wrong import syntax in ESM context.
fix
Install the package: npm install meadow-connection-sqlite. Ensure you use require(), not import.
TypeError: connection.db is not a function
Attempting to call db() as a method instead of accessing it as a property.
fix
Use connection.db (without parentheses) to access the better-sqlite3 database instance.
Error: The specified module could not be found. \\?\\...\\better_sqlite3.node
better-sqlite3 native addon failed to compile or load, often due to Node version mismatch or missing build tools.
fix
Ensure Node >= 22.5.0 and rebuild native modules: npm rebuild better-sqlite3. On Windows, install windows-build-tools.
Error: SQLITE_ERROR: no such table: Users
Table not created before querying it.
fix
Call connection.createTable() with the appropriate Meadow schema before running SELECT/INSERT queries.
Upgrade
Version history
1.0.20latest on npm
Audit
Dependencies
better-sqlite3requiredPeer dependency for underlying SQLite access; meadow-connection-sqlite wraps and re-exports better-sqlite3 functionality
fablerequiredRequired as the service provider framework; meadow-connection-sqlite registers as a Fable service
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
meadow-connection-sqlite — npm install meadow-connection-sqlite · libregistry