Skip to content

Configuration ​

Every option the library takes, in one place, with a link to where it is explained. An unknown option, or a value of the wrong type, throws TypeError when the object is created; an option given as undefined counts as left out.

createRepo(options) ​

OptionDefaultEffect
adapterrequiredThe database connection.
schemanoneThe default database schema.
logfalsetrue, a function receiving each query event, or { params: true }.
codegentrueWhether row decoders are generated with new Function.
warnOnRootUseInTransactionfalseDevelopment only: warn when the outer repo is used inside its transaction callback.

Details: Creating a repo.

Adapters ​

AdapterOptionsDetails
postgres(options?)connectionString or host/port/user/password/database/ssl, pool (max, idleTimeoutMs, connectionTimeoutMs, or a pg.Pool), planCacheSize, statementTimeoutMs, applicationNamePostgres
sqlite(options)filename (required), pragmas, attach, readonly, planCacheSizeSQLite
mysql(options?)connectionString or host/port/user/password/database/ssl, pool (max, idleTimeoutMs, connectionTimeoutMs), planCacheSizeMySQL

Per call ​

OptionOnEffectDetails
schemareads and writesThe database schema for this call.Parameters and options
timeoutMsreads, writes, transactionsOne time budget for the whole call.same
signalreads, writesAn AbortSignal that cancels the call.same
contextreads, writesPassed through to the query events.same
maxConcurrencyreadsPreload statements that may run at once. Default 1.same
batchSizestreamRows per fetch. Default 500.Streaming
returninginsert, insertAllRead back more fields, or rows.Insert
onConflictinsert, insertAllUpsert.Upserts
forceupdateUpdate even with no changes.Update
staleError, allowStaleupdate, deleteWhat a stale row does.same
isolation, readOnly, retriestransactionTransaction settings.Transactions

Schemas and fields ​

WhereOptionsDetails
Schema(table, fields, options?)schema, naming, primaryKey: false, codegenSchema options
Field modifiers.nullable(), .default(), .primaryKey(), .autogenerate(), .dbGenerated(), .virtual(), .column(), .redact(), .writable()Fields
AssociationsforeignKey, references, where, orderBy, onReplace, through, joinThrough, joinKeys, joinWhere, uniqueOptions

Migrations ​

WhereOptionsDetails
createMigrator(options)adapter, directory or migrations, table, schema, timestampColumn, lockTimeoutMs, timeoutMs, logRunning migrations
egon.config.tsadapter, migrations, databaseCLI configuration

egon-orm/migration also exports the helpers the CLI is built on: createDatabase(admin, name) and dropDatabase(admin, name, { ifExists }) run CREATE DATABASE and DROP DATABASE through an adapter connected to another database of the server, and parseMigrationFileName(file) reads the version and name from a file name such as 20261012093000_create_users.ts (undefined when it is not one).

Versions ​

Every package exports its version as VERSION (import { VERSION } from "egon-orm").