Interfaces

@system-inc/base-foundation · 515c140 · 76 symbols

Dual-output product of each builder primitive: the runtime drizzle value (column builder, constraint, etc.) AND its source-code representation. The same code path produces both, so they're structurally guaranteed to stay in sync.

helpers carries the set of drizzle-orm helper names the source snippet uses (e.g. 'integer', 'primaryKey') so the assembled file can emit a minimal import line.

Members

  • helpers: Set<string>

  • runtime: T

  • source: string

View source ↗

Copy of the MigrationConfig type from Drizzle's migrator.

Members

View source ↗

Represents a single migration entry in the journal.

Members

  • breakpoints: boolean

  • idx: number

  • tag: string

  • when: number

View source ↗

Structural shape of a Drizzle relational query handle (db.query.{table}). The concrete type Drizzle exposes is heavily generic and not part of the public surface; we only need the two finders.

Members

  • findFirst(options?: unknown): Promise<unknown>

  • findMany(options?: unknown): Promise<unknown>

View source ↗

Members

  • joins?: readonly (OrmMappedJoin<any>)[]

    Mapped joins from the find options. Each arrives in the raw row as a JSON-aggregated column and is hydrated onto its property.

  • maxDepth?: number

    Maximum depth for hydrating nested relations

  • raw?: boolean

    If true, returns raw objects without hydration

View source ↗

OrmAdapter

interface

Members

View source ↗

Members

  • logging?: boolean

    Enable or disable logging of SQL queries.

    Defaults to false.

View source ↗

Members

  • adapterType: AdapterType

  • databaseType: OrmDatabaseType

  • getAdapter(database: string, settings: SettingsType, metadata: OrmTableMetadata[]): Adapter | Promise<Adapter>

View source ↗

extends OrmAdapterProvider<OrmSettingsBetterSQLite<AdapterType>, AdapterType>

Members

View source ↗

extends OrmAdapterProvider<OrmSettingsD1<AdapterType>, AdapterType>

Members

View source ↗

extends OrmAdapterProvider<OrmSettingsDurableSQLite<AdapterType>, AdapterType>

Members

View source ↗

extends OrmAdapterProvider<OrmSettingsPlanetScale<AdapterType>, AdapterType>

Members

View source ↗

OrmAndFilter

interface

AND logical operator: combines conditions that must all be true.

Generic over the operand value type so that, when used inside a typed OrmFindOptionsWhere<T>, the wrapped filters are constrained to the column's TS type. Mixing types — e.g. and(gte(<number>), lte(<Date>)) — becomes a type error.

Members

View source ↗

Result of OrmAdapter.writeBatch(...). results[i] corresponds to the operation at the same index in the input. affectedRows is the sum across all operations for convenience.

Members

View source ↗

Between filter operator: field BETWEEN min AND max

Members

View source ↗

Members

View source ↗

OrmDatabase

interface

Members

  • name: string

  • count(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<number>

    Counts entities that match given options. Useful for pagination.

  • decrement(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, column: keyof EntityType & string, value?: number): Promise<OrmUpdateResult<EntityType>>

  • delete(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>): Promise<OrmDeleteResult<EntityType>>

  • deleteBatch(target: Constructor<EntityType>, conditions: readonly (Partial<Pick<EntityType, NonFnKeys<EntityType>>>)[]): Promise<OrmDeleteResult<EntityType>>

  • dispose(): Promise<void>

  • execute(query: string | SQLWrapper): Promise<any>

  • executeRows(query: string | SQLWrapper): Promise<RowType[]>

    Runs a raw query and returns its result rows in a dialect-independent shape — the adapter normalizes the driver's result (MySQL drivers resolve to { rows }, SQLite drivers to the array itself), so callers never branch on the backend.

    Use this for raw SELECTs. For driver-specific results (insertId, affectedRows, DML statements), use execute.

  • find(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<(OrmRawData<EntityType>)[]>

  • findAndCount(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<[(OrmRawData<EntityType>)[], number]>

  • findOne(target: Constructor<EntityType>, options?: OrmFindOptions<EntityType>): Promise<OrmRawData<EntityType> | null>

  • getAdapter(): Promise<Pick<OrmAdapter, "adapterType" | "databaseType">>

  • getEntities(): OrmEntityClass[]

    All entity classes registered for this database.

  • getEntityByTableName(tableName: string): OrmEntityClass | undefined

    Resolves a registered entity class by its table name. Returns undefined if no registered entity maps to that table. Scoped to this database's configured entities, so it doubles as the allow-list for table-name-addressed access.

  • getMetadata(target: OrmEntityClass): OrmTableMetadata | undefined

    Gets entity metadata for the given entity class or schema name.

  • getRepository(target: Constructor<EntityType>): OrmRepository<EntityType>

  • hasMetadata(target: OrmEntityClass): boolean

    Checks if entity metadata exist for the given entity class, target name or table name.

  • increment(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, column: keyof EntityType & string, value?: number): Promise<OrmUpdateResult<EntityType>>

  • insert(target: Constructor<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmInsertResult<EntityType>>

  • insertBatch(target: Constructor<EntityType>, values: readonly (Partial<Pick<EntityType, NonFnKeys<EntityType>>>)[]): Promise<OrmInsertResult<EntityType>>

  • safeBatchSize(columnCount: number): Promise<number>

    Returns the largest chunk size that keeps a single statement's bound parameters under the underlying adapter's safe limit. Use this when chunking a large input array in caller code (e.g. for an IN (...) filter or a batched read). Pass 1 for a list of scalar IDs.

  • timeSeries(target: Constructor<EntityType>, column: OrmEntityKey<EntityType>, options: OrmTimeSeriesOptions<EntityType>): Promise<OrmTimeSeriesResult[]>

  • transaction(callback: (tx: OrmTransaction) => Promise<T>): Promise<T>

  • truncate(target: Constructor<EntityType>, options: { confirm: true }): Promise<OrmDeleteResult<EntityType>>

    Deletes every row in the table.

    Requires the target entity to be marked truncatable: true via @OrmTable({ truncatable: true }). Tables that are not explicitly marked as truncatable will throw at runtime.

    The confirm: true flag must be passed at every call site to make the intent visible in code review — this method cannot be called without spelling out that a full-table wipe is intended.

  • update(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmUpdateResult<EntityType>>

  • updateBatch(target: Constructor<EntityType>, operations: readonly ({ conditions: OrmPartialEntity<EntityType>; values: OrmPartialEntity<EntityType> })[]): Promise<OrmUpdateResult<EntityType>>

  • upsert(target: Constructor<EntityType>, conditions: OrmPartialEntity<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmInsertResult<EntityType>>

  • upsertBatch(target: Constructor<EntityType>, operations: readonly ({ conditions: OrmPartialEntity<EntityType>; values: OrmPartialEntity<EntityType> })[]): Promise<OrmInsertResult<EntityType>>

  • writeBatch(build: (batch: OrmDatabaseBatch) => void): Promise<OrmBatchResult>

    Atomically execute a batch of writes spanning one or more entity types. The portable primitive for atomic writes across all adapters (including D1).

View source ↗

Multi-entity batch builder used by OrmDatabase.writeBatch. The entity class is inferred from each value's constructor — no need to pre-declare which repository each call targets. Mixed-type arrays in a single call are split into run-length-encoded groups so call order is preserved (matters for FK-dependent writes that span entity types).

Members

  • delete(entity: EntityType | readonly EntityType[]): void

  • deleteWhere(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>): void

    Queue a delete by arbitrary conditions (the batch counterpart of OrmDatabase.delete(target, conditions)). No entity lifecycle hooks run because no entity instances are involved.

  • execute(query: string | SQLWrapper): void

    Queue a raw write statement (built with the drizzle sql template) to run inside the same atomic batch — the escape hatch for bulk updates the entity API can't express (computed SET clauses, conditional shifts, increments). No entity lifecycle hooks run for it.

  • insert(entity: EntityType | readonly EntityType[]): void

  • update(entity: EntityType | readonly EntityType[]): void

  • upsert(entity: EntityType | readonly EntityType[]): void

View source ↗

Credentials for the database stored individually.

Members

  • database: string

    Database name to connect to.

  • host: string

    Database host.

  • password: string

    Database password.

  • port?: number

    Database port. Defaults to 3306.

  • type: "discrete"

    Credentials stored as individual fields.

  • username: string

    Database username.

View source ↗

extends OrmAdapter

Members

View source ↗

extends OrmDatabase

Members

  • name: string

  • count(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<number>

    Counts entities that match given options. Useful for pagination.

  • decrement(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, column: keyof EntityType & string, value?: number): Promise<OrmUpdateResult<EntityType>>

  • delete(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>): Promise<OrmDeleteResult<EntityType>>

  • deleteBatch(target: Constructor<EntityType>, conditions: readonly (Partial<Pick<EntityType, NonFnKeys<EntityType>>>)[]): Promise<OrmDeleteResult<EntityType>>

  • dispose(): Promise<void>

  • execute(query: string | SQLWrapper): Promise<any>

  • executeRows(query: string | SQLWrapper): Promise<RowType[]>

    Runs a raw query and returns its result rows in a dialect-independent shape — the adapter normalizes the driver's result (MySQL drivers resolve to { rows }, SQLite drivers to the array itself), so callers never branch on the backend.

    Use this for raw SELECTs. For driver-specific results (insertId, affectedRows, DML statements), use execute.

  • find(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<(OrmRawData<EntityType>)[]>

  • findAndCount(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<[(OrmRawData<EntityType>)[], number]>

  • findOne(target: Constructor<EntityType>, options?: OrmFindOptions<EntityType>): Promise<OrmRawData<EntityType> | null>

  • getAdapter(): Promise<Pick<OrmAdapter, "adapterType" | "databaseType">>

  • getEntities(): OrmEntityClass[]

    All entity classes registered for this database.

  • getEntityByTableName(tableName: string): OrmEntityClass | undefined

    Resolves a registered entity class by its table name. Returns undefined if no registered entity maps to that table. Scoped to this database's configured entities, so it doubles as the allow-list for table-name-addressed access.

  • getMetadata(target: OrmEntityClass): OrmTableMetadata | undefined

    Gets entity metadata for the given entity class or schema name.

  • getRepository(target: Constructor<EntityType>): OrmRepository<EntityType>

  • hasMetadata(target: OrmEntityClass): boolean

    Checks if entity metadata exist for the given entity class, target name or table name.

  • increment(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, column: keyof EntityType & string, value?: number): Promise<OrmUpdateResult<EntityType>>

  • insert(target: Constructor<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmInsertResult<EntityType>>

  • insertBatch(target: Constructor<EntityType>, values: readonly (Partial<Pick<EntityType, NonFnKeys<EntityType>>>)[]): Promise<OrmInsertResult<EntityType>>

  • migrate(): Promise<void>

  • safeBatchSize(columnCount: number): Promise<number>

    Returns the largest chunk size that keeps a single statement's bound parameters under the underlying adapter's safe limit. Use this when chunking a large input array in caller code (e.g. for an IN (...) filter or a batched read). Pass 1 for a list of scalar IDs.

  • timeSeries(target: Constructor<EntityType>, column: OrmEntityKey<EntityType>, options: OrmTimeSeriesOptions<EntityType>): Promise<OrmTimeSeriesResult[]>

  • transaction(callback: (tx: OrmTransaction) => Promise<T>): Promise<T>

  • truncate(target: Constructor<EntityType>, options: { confirm: true }): Promise<OrmDeleteResult<EntityType>>

    Deletes every row in the table.

    Requires the target entity to be marked truncatable: true via @OrmTable({ truncatable: true }). Tables that are not explicitly marked as truncatable will throw at runtime.

    The confirm: true flag must be passed at every call site to make the intent visible in code review — this method cannot be called without spelling out that a full-table wipe is intended.

  • update(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmUpdateResult<EntityType>>

  • updateBatch(target: Constructor<EntityType>, operations: readonly ({ conditions: OrmPartialEntity<EntityType>; values: OrmPartialEntity<EntityType> })[]): Promise<OrmUpdateResult<EntityType>>

  • upsert(target: Constructor<EntityType>, conditions: OrmPartialEntity<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmInsertResult<EntityType>>

  • upsertBatch(target: Constructor<EntityType>, operations: readonly ({ conditions: OrmPartialEntity<EntityType>; values: OrmPartialEntity<EntityType> })[]): Promise<OrmInsertResult<EntityType>>

  • writeBatch(build: (batch: OrmDatabaseBatch) => void): Promise<OrmBatchResult>

    Atomically execute a batch of writes spanning one or more entity types. The portable primitive for atomic writes across all adapters (including D1).

View source ↗

Equality filter operator: field = value

Members

  • type: "eq"

  • value: T

View source ↗

Exists filter operator: checks if a subquery/condition returns any results

Members

View source ↗

Defines a special criteria to find specific entity.

Members

  • comment?: string

    Adds a comment with the supplied string in the generated query. This is helpful for debugging purposes, such as finding a specific query in the database server's logs, or for categorization using an APM product.

  • joins?: readonly (OrmMappedJoin<any>)[]

    Ad-hoc joins mapped onto properties of the entity, for related rows that are not declared relations (composite predicates, filtered loads). Compiled into the same SQL statement as the find, so they add no extra database round trips.

  • order?: Partial<Record<NonFnKeys<EntityType>, "ASC" | "DESC">>

    Order, in which entities should be ordered.

  • relations?: OrmFindOptionsRelations<EntityType>

    Indicates what relations of entity should be loaded (simplified left join form).

  • select?: OrmEntityKeys<EntityType>

    Specifies what columns should be retrieved.

  • where?: OrmFindOptionsWhere<EntityType> | (OrmFindOptionsWhere<EntityType>)[]

    Condition(s) to match entities. Fields within one object are ANDed; an array is OR across its elements.

View source ↗

Defines a special criteria to find specific entities.

extends OrmFindOptions<EntityType>

Members

  • comment?: string

    Adds a comment with the supplied string in the generated query. This is helpful for debugging purposes, such as finding a specific query in the database server's logs, or for categorization using an APM product.

  • joins?: readonly (OrmMappedJoin<any>)[]

    Ad-hoc joins mapped onto properties of the entity, for related rows that are not declared relations (composite predicates, filtered loads). Compiled into the same SQL statement as the find, so they add no extra database round trips.

  • limit?: number

    Limit (paginated) - max number of entities should be taken.

  • offset?: number

    Offset (paginated) where from entities should be taken.

  • order?: Partial<Record<NonFnKeys<EntityType>, "ASC" | "DESC">>

    Order, in which entities should be ordered.

  • relations?: OrmFindOptionsRelations<EntityType>

    Indicates what relations of entity should be loaded (simplified left join form).

  • select?: OrmEntityKeys<EntityType>

    Specifies what columns should be retrieved.

  • where?: OrmFindOptionsWhere<EntityType> | (OrmFindOptionsWhere<EntityType>)[]

    Condition(s) to match entities. Fields within one object are ANDed; an array is OR across its elements.

View source ↗

OrmGteFilter

interface

Greater than or equal filter operator: field >= value

Members

  • type: "gte"

  • value: T

View source ↗

OrmGtFilter

interface

Greater than filter operator: field > value

Members

  • type: "gt"

  • value: T

View source ↗

In array filter operator: field IN (values)

Members

  • type: "in"

  • value: T[]

View source ↗

A column inside an index, optionally indexed by only its leading characters.

MySQL sizes an index key by each column's DECLARED width, so a varchar(1024) in utf8mb4 reserves 4096 bytes and blows InnoDB's 3072-byte ceiling on its own — the index simply cannot be created. A prefix indexes the first N characters instead, which is what makes long titles, paths, and subjects indexable at all.

A prefix still serves equality and leading-wildcard-free LIKE, and still orders rows; it cannot serve a covering-index-only read, because the stored key is truncated.

Members

  • column: string

  • prefixLength: number

    Number of leading CHARACTERS to index (not bytes — MySQL's col(n) counts characters, and the byte cost is n × 4 under utf8mb4).

View source ↗

Members

  • columns: string[]

  • estimatedBytes: number

  • indexName: string

  • largestColumns: ({ bytes: number; name: string })[]

    The subset of columns responsible for most of the weight, widest first.

  • reason: "TooLong" | "TextWithoutPrefix"

  • tableName: string

View source ↗

Is not null filter operator: field IS NOT NULL

Members

View source ↗

Is null filter operator: field IS NULL

Members

View source ↗

Options for the @OrmJoinColumn decorator.

Members

  • name?: string

    Name of the column in the database

  • nullable?: boolean

    Whether this column can be NULL

  • referencedColumnName?: string

    Name of the column in the referenced entity to which this column refers Default is the primary key of the referenced table

View source ↗

OrmLikeFilter

interface

Like filter operator for pattern matching: field LIKE pattern Use % for wildcard (e.g., '%test%' matches any string containing 'test') Case sensitivity depends on database collation (MySQL/SQLite default to case-insensitive)

Members

  • pattern: string

  • type: "like"

View source ↗

OrmLteFilter

interface

Less than or equal filter operator: field <= value

Members

  • type: "lte"

  • value: T

View source ↗

OrmLtFilter

interface

Less than filter operator: field < value

Members

  • type: "lt"

  • value: T

View source ↗

Options for the @OrmManyToOne decorator. TargetType is inferred from the decorator's () => Target thunk so inverseSide is checked against the target's relation properties.

Members

  • inverseSide?: RelationKey<TargetType>

    The relation on the target entity that points back to this entity.

  • joinColumn?: string

    The column in this table that references the foreign entity If not specified, will be inferred as ${propertyKey}Id

  • nullable?: boolean

    Whether this relation can be null

View source ↗

OrmMappedJoin

interface

An ad-hoc join mapped onto a property of the found entity — the escape hatch for loading related rows that are not declared relations (composite predicates, filtered loads, cross-cutting lookups) without paying an extra database round trip.

Each mapped join compiles into a correlated JSON-aggregation subquery inside the same SQL statement as the main find, so a find with any number of mapped joins is still a single round trip. The JSON result is hydrated into entity instances and assigned to property on the parent.

sessionRepository.findOne({
    where: { id: sessionId },
    relations: { account: { emails: true } },
    joins: [
        {
            property: 'accessRoles',
            entity: AccessRoleAssignment,
            type: 'many',
            where: {
                accountId: parentColumn('accountId'),
                profileId: parentColumn('profileId'),
                status: AccessRoleStatus.Active,
            },
            relations: { accessRole: true },
        },
    ],
});

Limitations: where values may be plain values, scalar Orm filters (equals/notEquals/in/notIn/gt/gte/lt/lte/between/notBetween/like/ notLike/isNull/isNotNull), or parentColumn() references — composite and/or/not filters are not supported. Result ordering inside a many join is not guaranteed; sort in memory if it matters.

Members

  • entity: Constructor<JoinedType>

    The entity to join. Must be a registered @OrmTable.

  • joins?: readonly (OrmMappedJoin<any>)[]

    Nested mapped joins, with this join's entity as their parent.

  • property: string

    The property on the parent entity the result is assigned to.

  • relations?: OrmFindOptionsRelations<JoinedType>

    Declared relations of the joined entity to load along with it, nested into the same subquery.

  • type: "one" | "many"

    Whether the property receives a single entity (or null) or an array of entities.

  • where: Dictionary<unknown>

    Conditions on the joined entity, keyed by property key. All conditions are ANDed. Use parentColumn to reference columns of the parent entity (the join predicate); other values are constants or scalar Orm filters.

View source ↗

Not between filter operator: field NOT BETWEEN min AND max

Members

View source ↗

Not equal filter operator: field != value

Members

  • type: "ne"

  • value: T

View source ↗

Not exists filter operator: checks if a subquery/condition returns no results

Members

View source ↗

OrmNotFilter

interface

NOT logical operator: negates a condition.

Generic over the operand value type — see OrmAndFilter for rationale.

Members

View source ↗

Not in array filter operator: field NOT IN (values)

Members

  • type: "notIn"

  • value: T[]

View source ↗

Not like filter operator: field NOT LIKE pattern Use % for wildcard (e.g., '%test%' excludes any string containing 'test') Case sensitivity depends on database collation (MySQL/SQLite default to case-insensitive)

Members

View source ↗

Options for the @OrmOneToMany decorator.

Members

  • inverseSide: RelationKey<TargetType>

    The relation on the target entity that points back to this entity.

View source ↗

Options for the @OrmOneToOne decorator.

Members

  • inverseSide?: RelationKey<TargetType>

    The relation on the target entity that points back to this entity.

  • joinColumn?: string

    The column in this table that references the foreign entity If not specified, will be inferred as ${propertyKey}Id

  • nullable?: boolean

    Whether this relation can be null

View source ↗

OrmOrFilter

interface

OR logical operator: combines conditions where at least one must be true.

Generic over the operand value type — see OrmAndFilter for rationale.

Members

View source ↗

Members

  • joins?: readonly (OrmMappedJoin<any>)[]

    Mapped joins to load with each item (see OrmMappedJoin) — compiled into the same statement as the find, no extra round trips.

  • order?: Partial<Record<NonFnKeys<EntityType>, "ASC" | "DESC">>

  • pagination?: PaginationInput | OrmPaginationInput

    The wire PaginationInput (or a @PaginationInputFor subclass) can be passed directly — ormPaginatedFind bridges it to OrmPaginationInput internally, applying any declared allowlists. Pass an OrmPaginationInput you bridged yourself only when the resolver needs scopeWhere/narrowing first.

  • relations?: OrmFindOptionsRelations<EntityType>

  • repository: OrmRepository<EntityType>

  • where?: OrmFindOptionsWhere<EntityType>

View source ↗

A reference to a column on the parent entity of a mapped join. Used as a value inside OrmMappedJoin.where to express the join predicate, e.g. { accountId: parentColumn('accountId') }.

column is the property key on the parent entity (database column names are resolved from the parent's metadata).

Members

View source ↗

Members

View source ↗

Members

  • propertyKey: string

  • strategy: "uuid"

View source ↗

Members

View source ↗

Members

  • name?: string

View source ↗

Members

  • name: string

  • count(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<number>

    Counts entities that match given options. Useful for pagination.

  • find(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<readonly (Readonly<OrmRawData<EntityType>>)[]>

  • findAndCount(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<[readonly (Readonly<OrmRawData<EntityType>>)[], number]>

  • findOne(target: Constructor<EntityType>, options?: OrmFindOptions<EntityType>): Promise<Readonly<OrmRawData<EntityType>> | null>

  • getMetadata(target: Constructor): OrmTableMetadata | undefined

    Gets entity metadata for the given entity class or schema name.

  • getRepository(target: Constructor<EntityType>): OrmReadonlyRepository<EntityType>

  • hasMetadata(target: Constructor): boolean

    Checks if entity metadata exist for the given entity class, target name or table name.

View source ↗

Members

  • db: OrmDatabaseImpl<OrmSettings<"drizzle">>

  • tableName: string

  • target: Constructor<EntityType>

  • count(options?: OrmFindOptionsMany<EntityType>): Promise<number>

    Counts entities that match given options. Useful for pagination.

  • find(options?: OrmFindOptionsMany<EntityType>): Promise<readonly (Readonly<EntityType>)[]>

    Finds entities that match given find options.

  • findAndCount(options?: OrmFindOptionsMany<EntityType>): Promise<[readonly (Readonly<EntityType>)[], number]>

    Finds entities that match given find options. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

  • findOne(options?: OrmFindOptions<EntityType>): Promise<Readonly<EntityType> | null>

    Finds first entity by a given find options. If entity was not found in the database - returns null.

View source ↗

Callback-passed batch builder, mirroring the repository API. Each method queues an operation (no I/O) and runs the appropriate before* hooks synchronously. The repository's writeBatch submits the queued operations atomically and then runs the matching after* hooks.

Members

  • delete(entity: EntityType | readonly EntityType[]): void

  • insert(entity: EntityType | readonly EntityType[]): void

  • update(entity: EntityType | readonly EntityType[]): void

  • upsert(entity: EntityType | readonly EntityType[]): void

View source ↗

Members

View source ↗

Members

  • adapterType: AdapterType

    The type of ORM adapter to use.

  • entities?: OrmEntityClass[]

    The entities to load for the Worker.

    This represents the database tables that are specific to your Worker separate of the module tables.

    This should be each individual entity class.

  • externalEntities?: OrmEntityClass[]

    Entities this worker USES for queries but does NOT own — their schema is migrated by someone else (a sibling worker sharing the database). They are built into the runtime query schema, but excluded from migration generation (schema:diff/schema:check) and the schema:sync table scope. The direct-registration equivalent of a module registered with externalSchema: true.

  • inheritSchema?: string

    Inherit the entity set from another configured ORM database, by name (e.g. a read-replica that targets the same schema). The inherited entities are merged with this config's own entities (deduplicated), and resolution is transitive. Only the schema is inherited — this config keeps its own adapter, dialect, and credentials.

  • logging?: boolean

    Enable or disable logging of SQL queries.

    Defaults to false.

View source ↗

extends OrmSettingsBase<AdapterType>

Members

  • adapter: Constructor<OrmAdapterProviderBetterSQLite<AdapterType>>

  • adapterType: AdapterType

    The type of ORM adapter to use.

  • databaseType: { dialect: "sqlite"; driver: "better-sqlite" }

  • entities?: OrmEntityClass[]

    The entities to load for the Worker.

    This represents the database tables that are specific to your Worker separate of the module tables.

    This should be each individual entity class.

  • externalEntities?: OrmEntityClass[]

    Entities this worker USES for queries but does NOT own — their schema is migrated by someone else (a sibling worker sharing the database). They are built into the runtime query schema, but excluded from migration generation (schema:diff/schema:check) and the schema:sync table scope. The direct-registration equivalent of a module registered with externalSchema: true.

  • filePath: string

  • inheritSchema?: string

    Inherit the entity set from another configured ORM database, by name (e.g. a read-replica that targets the same schema). The inherited entities are merged with this config's own entities (deduplicated), and resolution is transitive. Only the schema is inherited — this config keeps its own adapter, dialect, and credentials.

  • logging?: boolean

    Enable or disable logging of SQL queries.

    Defaults to false.

View source ↗

OrmSettingsD1

interface

extends OrmSettingsBase<AdapterType>

Members

  • adapter: Constructor<OrmAdapterProviderD1<AdapterType>>

  • adapterType: AdapterType

    The type of ORM adapter to use.

  • binding: string

  • databaseType: { dialect: "sqlite"; driver: "d1" }

  • entities?: OrmEntityClass[]

    The entities to load for the Worker.

    This represents the database tables that are specific to your Worker separate of the module tables.

    This should be each individual entity class.

  • externalEntities?: OrmEntityClass[]

    Entities this worker USES for queries but does NOT own — their schema is migrated by someone else (a sibling worker sharing the database). They are built into the runtime query schema, but excluded from migration generation (schema:diff/schema:check) and the schema:sync table scope. The direct-registration equivalent of a module registered with externalSchema: true.

  • inheritSchema?: string

    Inherit the entity set from another configured ORM database, by name (e.g. a read-replica that targets the same schema). The inherited entities are merged with this config's own entities (deduplicated), and resolution is transitive. Only the schema is inherited — this config keeps its own adapter, dialect, and credentials.

  • logging?: boolean

    Enable or disable logging of SQL queries.

    Defaults to false.

View source ↗

extends OrmSettingsBase<AdapterType>

Members

  • adapter: Constructor<OrmAdapterProviderDurableSQLite<AdapterType>>

  • adapterType: AdapterType

    The type of ORM adapter to use.

  • databaseType: { dialect: "sqlite"; driver: "durable" }

  • entities?: OrmEntityClass[]

    The entities to load for the Worker.

    This represents the database tables that are specific to your Worker separate of the module tables.

    This should be each individual entity class.

  • externalEntities?: OrmEntityClass[]

    Entities this worker USES for queries but does NOT own — their schema is migrated by someone else (a sibling worker sharing the database). They are built into the runtime query schema, but excluded from migration generation (schema:diff/schema:check) and the schema:sync table scope. The direct-registration equivalent of a module registered with externalSchema: true.

  • inheritSchema?: string

    Inherit the entity set from another configured ORM database, by name (e.g. a read-replica that targets the same schema). The inherited entities are merged with this config's own entities (deduplicated), and resolution is transitive. Only the schema is inherited — this config keeps its own adapter, dialect, and credentials.

  • logging?: boolean

    Enable or disable logging of SQL queries.

    Defaults to false.

View source ↗

extends OrmSettingsDurableSQLiteBase<"drizzle">

Members

  • adapter: Constructor<OrmAdapterProviderDurableSQLite<"drizzle">>

  • adapterType: "drizzle"

    The type of ORM adapter to use.

  • databaseType: { dialect: "sqlite"; driver: "durable" }

  • entities?: OrmEntityClass[]

    The entities to load for the Worker.

    This represents the database tables that are specific to your Worker separate of the module tables.

    This should be each individual entity class.

  • externalEntities?: OrmEntityClass[]

    Entities this worker USES for queries but does NOT own — their schema is migrated by someone else (a sibling worker sharing the database). They are built into the runtime query schema, but excluded from migration generation (schema:diff/schema:check) and the schema:sync table scope. The direct-registration equivalent of a module registered with externalSchema: true.

  • inheritSchema?: string

    Inherit the entity set from another configured ORM database, by name (e.g. a read-replica that targets the same schema). The inherited entities are merged with this config's own entities (deduplicated), and resolution is transitive. Only the schema is inherited — this config keeps its own adapter, dialect, and credentials.

  • logging?: boolean

    Enable or disable logging of SQL queries.

    Defaults to false.

  • migrations: DrizzleMigrationConfig

    Drizzle migration bundle (the default export of drizzle-kit's generated migrations.js). Required for durable DOs because the DO runs migrations against its own SQLite at boot — there's no external migration runner.

  • released: string[]

    Tag list from release.ts. The runtime migration runner refuses to run any migration whose tag isn't in this list on non-Development environments — defense in depth in case base deploy's pre-flight check was somehow bypassed.

View source ↗

extends OrmSettingsBase<AdapterType>

Members

  • adapter: Constructor<OrmAdapterProviderPlanetScale<AdapterType>>

  • adapterType: AdapterType

    The type of ORM adapter to use.

  • credentials?: OrmCredentials

  • databaseType: { dialect: "mysql"; driver: "planetscale" }

  • entities?: OrmEntityClass[]

    The entities to load for the Worker.

    This represents the database tables that are specific to your Worker separate of the module tables.

    This should be each individual entity class.

  • externalEntities?: OrmEntityClass[]

    Entities this worker USES for queries but does NOT own — their schema is migrated by someone else (a sibling worker sharing the database). They are built into the runtime query schema, but excluded from migration generation (schema:diff/schema:check) and the schema:sync table scope. The direct-registration equivalent of a module registered with externalSchema: true.

  • inheritSchema?: string

    Inherit the entity set from another configured ORM database, by name (e.g. a read-replica that targets the same schema). The inherited entities are merged with this config's own entities (deduplicated), and resolution is transitive. Only the schema is inherited — this config keeps its own adapter, dialect, and credentials.

  • logging?: boolean

    Enable or disable logging of SQL queries.

    Defaults to false.

View source ↗

Members

  • columns: OrmIndexColumn[]

    The indexed columns. Usually plain property names; an entry may carry a prefixLength when the column is too wide to index whole (see OrmIndexColumn).

  • name?: string

  • options?: OrmTableIndexOptions

View source ↗

Members

  • dialect?: { mysql?: { clustered?: boolean } }

  • unique?: boolean

View source ↗

Members

View source ↗

Members

  • comment?: string

  • truncatable?: boolean

    Whether this table may be wiped via truncate().

    Defaults to false. Tables that are not explicitly marked as truncatable will throw at runtime when truncate() is called, preventing accidental full-table deletion.

    Typically only used for test fixtures, ephemeral caches, and tables whose rows are regenerated from a source of truth.

View source ↗

Members

  • columns: string[]

  • name?: string

View source ↗

Members

  • bucket: string

  • filterKeys: ({ count: number; key: string })[]

  • total: number

View source ↗

extends Omit<OrmDatabase, "transaction" | "dispose">

Members

  • name: string

  • count(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<number>

    Counts entities that match given options. Useful for pagination.

  • decrement(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, column: keyof EntityType & string, value?: number): Promise<OrmUpdateResult<EntityType>>

  • delete(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>): Promise<OrmDeleteResult<EntityType>>

  • deleteBatch(target: Constructor<EntityType>, conditions: readonly (Partial<Pick<EntityType, NonFnKeys<EntityType>>>)[]): Promise<OrmDeleteResult<EntityType>>

  • execute(query: string | SQLWrapper): Promise<any>

  • executeRows(query: string | SQLWrapper): Promise<RowType[]>

    Runs a raw query and returns its result rows in a dialect-independent shape — the adapter normalizes the driver's result (MySQL drivers resolve to { rows }, SQLite drivers to the array itself), so callers never branch on the backend.

    Use this for raw SELECTs. For driver-specific results (insertId, affectedRows, DML statements), use execute.

  • find(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<(OrmRawData<EntityType>)[]>

  • findAndCount(target: Constructor<EntityType>, options?: OrmFindOptionsMany<EntityType>): Promise<[(OrmRawData<EntityType>)[], number]>

  • findOne(target: Constructor<EntityType>, options?: OrmFindOptions<EntityType>): Promise<OrmRawData<EntityType> | null>

  • getAdapter(): Promise<Pick<OrmAdapter, "adapterType" | "databaseType">>

  • getEntities(): OrmEntityClass[]

    All entity classes registered for this database.

  • getEntityByTableName(tableName: string): OrmEntityClass | undefined

    Resolves a registered entity class by its table name. Returns undefined if no registered entity maps to that table. Scoped to this database's configured entities, so it doubles as the allow-list for table-name-addressed access.

  • getMetadata(target: OrmEntityClass): OrmTableMetadata | undefined

    Gets entity metadata for the given entity class or schema name.

  • getRepository(target: Constructor<EntityType>): OrmRepository<EntityType>

  • hasMetadata(target: OrmEntityClass): boolean

    Checks if entity metadata exist for the given entity class, target name or table name.

  • increment(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, column: keyof EntityType & string, value?: number): Promise<OrmUpdateResult<EntityType>>

  • insert(target: Constructor<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmInsertResult<EntityType>>

  • insertBatch(target: Constructor<EntityType>, values: readonly (Partial<Pick<EntityType, NonFnKeys<EntityType>>>)[]): Promise<OrmInsertResult<EntityType>>

  • onFailure(callback: OrmTransactionCallback): void

    Register a callback to be executed after transaction failure/rollback

  • onSuccess(callback: OrmTransactionCallback): void

    Register a callback to be executed after successful transaction commit

  • rollback(): never

    Forces the transaction to fail and rollback. This will execute all failure callbacks registered with onFailure.

  • safeBatchSize(columnCount: number): Promise<number>

    Returns the largest chunk size that keeps a single statement's bound parameters under the underlying adapter's safe limit. Use this when chunking a large input array in caller code (e.g. for an IN (...) filter or a batched read). Pass 1 for a list of scalar IDs.

  • timeSeries(target: Constructor<EntityType>, column: OrmEntityKey<EntityType>, options: OrmTimeSeriesOptions<EntityType>): Promise<OrmTimeSeriesResult[]>

  • truncate(target: Constructor<EntityType>, options: { confirm: true }): Promise<OrmDeleteResult<EntityType>>

    Deletes every row in the table.

    Requires the target entity to be marked truncatable: true via @OrmTable({ truncatable: true }). Tables that are not explicitly marked as truncatable will throw at runtime.

    The confirm: true flag must be passed at every call site to make the intent visible in code review — this method cannot be called without spelling out that a full-table wipe is intended.

  • update(target: Constructor<EntityType>, conditions: OrmFindOptionsWhere<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmUpdateResult<EntityType>>

  • updateBatch(target: Constructor<EntityType>, operations: readonly ({ conditions: OrmPartialEntity<EntityType>; values: OrmPartialEntity<EntityType> })[]): Promise<OrmUpdateResult<EntityType>>

  • upsert(target: Constructor<EntityType>, conditions: OrmPartialEntity<EntityType>, values: OrmPartialEntity<EntityType>): Promise<OrmInsertResult<EntityType>>

  • upsertBatch(target: Constructor<EntityType>, operations: readonly ({ conditions: OrmPartialEntity<EntityType>; values: OrmPartialEntity<EntityType> })[]): Promise<OrmInsertResult<EntityType>>

  • writeBatch(build: (batch: OrmDatabaseBatch) => void): Promise<OrmBatchResult>

    Atomically execute a batch of writes spanning one or more entity types. The portable primitive for atomic writes across all adapters (including D1).

View source ↗

Members

View source ↗

extends OrmTransactionBaseResult

Members

View source ↗

extends OrmTransactionBaseResult

Members

View source ↗

Credentials for the database formatted in a URL.

Members

  • type: "url"

    Credentials stored in a URL.

  • url: string

    The url parameter that should contain all credentials required to connect to the database.

    The format of the url parameter is: [connector]://[user_name]:[password]@[host]:[port]/[database]?[arguments]

    [connector] can be one of the following: mysql: MySQL database. planetscale-serverless: PlanetScale Serverless database.

    [user_name] is the username to connect to the database. [password] is the password to connect to the database. [host] is the host of the database. [port] is the port of the database. [database] is the name of the database to connect to. [arguments] is a key/value pair list of arguments to pass to the database connector.

View source ↗

Interface for transforming values between entity and database representations.

Members

  • from(value: DatabaseType): EntityType

    Transforms the value from the database to the entity property. Called during entity hydration.

  • to(value: EntityType): DatabaseType

    Transforms the value from the entity property to the database. Called during insert/update operations.

View source ↗

Members

  • endEpochSec: number

    Exclusive segment end.

  • offsetMinutes: number

  • startEpochSec: number

    Inclusive segment start (clamped to the queried range).

View source ↗