Drivers
SlintORM's DBAdapter abstracts across four database drivers. Each driver handles query placeholders, DDL syntax, and error codes differently. The adapter normalizes these differences behind a single exec() interface.
Feature matrix
SQLite
db.ts
// SQLite — better-sqlite3 (recommended)
// WAL mode enabled automatically for better concurrency
// Synchronous driver wrapped in async interface
import ORMManager from 'slintorm';
const orm = new ORMManager({
driver: 'sqlite',
databaseUrl: './dev.db', // file path
});
// In-memory database (tests / ephemeral):
const memOrm = new ORMManager({
driver: 'sqlite',
databaseUrl: ':memory:',
});
// Fallback: if better-sqlite3 is not installed,
// SlintORM automatically falls back to sqlite3/sqlite (async)PostgreSQL
db.ts
// PostgreSQL — pg
// Uses $1-style positional placeholders
// RETURNING * on INSERT to get the full row back
import ORMManager from 'slintorm';
const orm = new ORMManager({
driver: 'postgres',
databaseUrl: process.env.DATABASE_URL!,
// postgresql://user:password@host:5432/database
// postgresql://user:password@host:5432/database?sslmode=require
});MySQL
db.ts
// MySQL — mysql2/promise
// Backtick quoting for identifiers
// ON DUPLICATE KEY UPDATE for upsert
import ORMManager from 'slintorm';
const orm = new ORMManager({
driver: 'mysql',
databaseUrl: 'mysql://user:password@localhost:3306/mydb',
});MongoDB
db.ts
// MongoDB — uses a JSON command protocol
// Each query is translated to find/insert/update/delete/count
// DDL is a no-op (MongoDB is schemaless)
// Note: no transaction support, no UNION, limited JOIN support
import ORMManager from 'slintorm';
const orm = new ORMManager({
driver: 'mongodb',
databaseUrl: process.env.MONGO_URI!,
// mongodb://user:pass@host:27017/mydb
// mongodb+srv://user:pass@cluster.mongodb.net/mydb
});Prepared statement cache
// Prepared statement cache (SQLite only)
// DBAdapter caches up to 200 prepared statements
// Statements are keyed by SQL string — reused on repeat calls
// Example: repeated queries reuse the same prepared statement
for (const id of userIds) {
await User.get({ id }); // same SQL pattern -> cached statement
}Connection teardown
// DBAdapter.close() — clean connection teardown
// Call when shutting down (e.g. SIGTERM handler, test teardown)
import ORMManager from 'slintorm';
const orm = new ORMManager({ ... });
// ... use orm ...
process.on('SIGTERM', async () => {
await orm.adapter.close();
process.exit(0);
});Table introspection
// DBAdapter.getTableInfo(table)
// Introspects the column list for an existing table
// Per-driver implementation:
// SQLite: PRAGMA table_info(tableName)
// Postgres: information_schema.columns
// MySQL: information_schema.columns
// MongoDB: returns empty (schemaless)
const columns = await orm.adapter.getTableInfo('users');
// [{ name: 'id', type: 'INTEGER', ... }, ...]