Engine
Database engine interface. All dialect-specific engines (SQLite, Postgres, MySQL, MongoDB) implement this contract so repositories can work against any backend without code changes.
Properties
Section titled “Properties”dialect
Section titled “dialect”
readonlydialect:Dialect
The dialect function used to translate checked filter expressions into database-specific queries. Set by each engine with a sensible default and optionally overridden by the user at engine creation.
maxParams
Section titled “maxParams”
readonlymaxParams:number
Maximum number of bind parameters the engine supports per statement. Used by the repository layer to chunk batch operations.
- SQLite: 999
- Postgres: 65535
- MySQL: 65535
- MongoDB: Infinity (no parameter limit)
Methods
Section titled “Methods”close()
Section titled “close()”close():
Promise<void>
Close the underlying connection or client. After calling this method the engine must not be used.
Returns
Section titled “Returns”Promise<void>
count()
Section titled “count()”count(
opts):Promise<number>
Count rows/documents matching the filter.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<number>
deleteMany()
Section titled “deleteMany()”deleteMany(
opts):Promise<number>
Delete multiple rows/documents matching the filter. Returns the number of rows deleted.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<number>
deleteOne()
Section titled “deleteOne()”deleteOne(
opts):Promise<boolean>
Delete a single row/document matching the filter. Returns true
if a row was deleted, false otherwise.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<boolean>
execute()
Section titled “execute()”execute<
T>(query,params?):Promise<T[]>
Execute a raw query against the underlying database. This is the escape hatch for queries that cannot be expressed through the higher-level methods.
For SQL engines, query is a SQL string and params contains bind
values. For document engines (e.g. MongoDB), query is a command
object and params is unused.
Type Parameters
Section titled “Type Parameters”T = Record<string, unknown>
Parameters
Section titled “Parameters”string | object
params?
Section titled “params?”unknown[]
Returns
Section titled “Returns”Promise<T[]>
findMany()
Section titled “findMany()”findMany<
T>(opts):Promise<T[]>
Find all rows/documents matching the filter.
Type Parameters
Section titled “Type Parameters”T = Record<string, unknown>
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T[]>
findOne()
Section titled “findOne()”findOne<
T>(opts):Promise<T|undefined>
Find a single row/document matching the filter.
Returns undefined if no match is found.
Type Parameters
Section titled “Type Parameters”T = Record<string, unknown>
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T | undefined>
insertMany()
Section titled “insertMany()”insertMany<
T>(opts):Promise<T[]>
Insert multiple rows/documents and return all inserted records. The engine automatically chunks the operation based on maxParams to stay within bind-parameter limits.
Type Parameters
Section titled “Type Parameters”T = Record<string, unknown>
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T[]>
insertOne()
Section titled “insertOne()”insertOne<
T>(opts):Promise<T>
Insert a single row/document and return the inserted record.
Type Parameters
Section titled “Type Parameters”T = Record<string, unknown>
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T>
replaceMany()
Section titled “replaceMany()”replaceMany<
T>(opts):Promise<T[]>
Replace multiple existing rows/documents identified by their key columns and return all updated records. Uses CASE-based UPDATE for SQL engines, which physically cannot create new rows.
The engine automatically chunks the operation based on maxParams to stay within bind-parameter limits.
Type Parameters
Section titled “Type Parameters”T = Record<string, unknown>
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T[]>
transaction()
Section titled “transaction()”transaction<
T>(fn):Promise<T>
Execute a function within a transaction. All engine method calls made through the transactional engine share the same transaction context. The transaction is committed when the callback resolves and rolled back if it throws.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”(tx) => Promise<T>
Returns
Section titled “Returns”Promise<T>
updateOne()
Section titled “updateOne()”updateOne<
T>(opts):Promise<T|undefined>
Update a single row/document matching the filter and return the updated record.
Type Parameters
Section titled “Type Parameters”T = Record<string, unknown>
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T | undefined>