Functions
@system-inc/base-foundation · 515c140 · 78 symbols
and
between
checkSchemaSet
checkTableSchema
columnFiltersToFindOperators
entityAfterDelete
entityAfterInsert
entityAfterUpdate
entityBeforeDelete
entityBeforeInsert
entityBeforeUpdate
equals
exists
formatIndexKeyLengthFindings
Renders findings as an error a human can act on without opening MySQL docs: which index, how far over, which column is carrying the weight, and the character count that would fit.
getInsertValues
Every SET column value on the entity — the field set insert/upsert
persist. Dirty tracking (getChangedFields) is an UPDATE
optimization: driving insert with it silently dropped the values of
clean entities (a clone()d or hydrated entity carries its data in
the value slots with an empty dirty set), storing NULL rows.
getPrimaryKeyColumns
Get all primary key columns from the primary key info
getPrimaryKeyConditions
getPrimaryKeyPropertyKeys
Get the property keys of all primary key columns
getTimezoneOffsetMinutes
Calculates the timezone offset in minutes for a given IANA timezone at a
specific point in time. Uses Intl.DateTimeFormat so DST transitions are
handled correctly. Shared by the dialect adapters' time-series bucketing.
timeZoneIANA timezone string (e.g., 'America/New_York')
epochSecUnix timestamp in seconds
Returns — Offset in minutes, matching `Date.getTimezoneOffset()` convention (positive = behind UTC, negative = ahead of UTC)
getTimezoneOffsetSegments
Splits [startEpochSec, endEpochSec) into segments of constant UTC
offset for the zone — one segment per side of each DST transition.
Bucketing with a single offset frozen at range start put every
post-transition row in the wrong local bucket for part of the day;
the adapters compile these segments into a per-row CASE instead.
Transition instants are located by bisection (to the minute), so a
multi-year range costs a handful of offset lookups per transition.
gt
gte
hasPrimaryKey
Check if the table has any primary key columns
inArray
isColumnKind
isColumnPrimaryKey
Check if a column is part of the primary key
isDurableAdapter
isDurableObjectStorage
isNotNull
isNull
isOrmAdapterProvider
isOrmFilter
Type guard to check if a value is an ORM filter
isOrmSettingsBetterSQLite
isOrmSettingsD1
isOrmSettingsDurableSQLite
isOrmSettingsPlanetScale
isParentColumnReference
like
lt
lte
not
notBetween
notEquals
notExists
notInArray
notLike
or
ormAddColumn
ormAddColumnIndex
Adds a single column index with auto-generated name if not provided
ormAddColumnUnique
Adds a single column unique constraint with auto-generated name if not provided
ormAddColumnUniqueIndex
Adds a single column unique index with auto-generated name if not provided This creates a unique index (different from unique constraint)
ormAddDateColumn
ormAddIndex
Adds an index to a table with optional auto-generated name
ctorThe entity class constructor
nameOptional custom name. If not provided, will be auto-generated as ix_<table>_<cols> or ux_<table>_<cols>
columnsThe columns to include in the index
optionsAdditional index options (e.g., unique)
ormAddJoinColumn
ormAddListener
ormAddPrimaryAutoColumn
ormAddPrimaryKey
ormAddRelation
ormAddTable
ormAddUniqueConstraint
ormCheckIndexKeyLength
Checks every index a table declares against InnoDB's key-length ceiling, BEFORE any SQL is generated.
This exists because the failure it catches is invisible everywhere else in
the pipeline. The entity decorators accept @OrmTableIndex(['title'])
without consulting @OrmColumn's length, the schema builder emits a valid
index('...').on(...), drizzle-kit writes a syntactically perfect
CREATE INDEX, and the whole thing looks correct on disk. The error surfaces
only when MySQL refuses the statement — and drizzle-kit migrate reports
that refusal by exiting 1 with nothing but a spinner on stdout, against
whichever database was unlucky enough to run it first.
Worse, the DDL that already succeeded stays applied: MySQL auto-commits each statement, so a migration that dies halfway leaves the database in a state no migration ledger records. We shipped exactly that and it cost a day of archaeology across three databases to reconstruct.
Pure arithmetic over metadata, so it runs offline at generate time with no database connection.
ormCreatePlanetScaleDatabase
Creates an OrmDatabase for a PlanetScale database outside of a
worker's dependency-injection container. Intended for tooling that
talks to the database directly with an explicit entity list — most
notably integration-test helpers (see
test/IntegrationTestClient.getOrmDatabase). Workers should always
resolve their databases through DI (@InjectDatabase) instead.
ormEnumStringValues
Extracts the string values from an enum column's values option.
Accepts an explicit value list or an enum object; for the object form
only string values are kept, so enums merged with a namespace of
helper functions contribute just their actual values.
ormGetEnvironmentCredentials
ormGetTable
ormHasTokenlessInjection
Whether ctor (or a base class — reflect-metadata inherits constructor
injection metadata through the prototype chain, so the subclass injects
too) has a token-less ORM injection.
ormIndexColumnKeyBytes
The byte width MySQL reserves for one column inside an index key.
Returns undefined for a TEXT column, which cannot be indexed at all without
an explicit prefix length — a different failure from "too wide", reported
separately so the message can say the useful thing.
ormIndexColumnName
The property name an index column refers to, whichever form it takes.
ormIndexColumnPrefixLength
The prefix length, or undefined when the whole column is indexed.
ormIsAdapterOptions
ormIsUniqueConstraintViolation
Whether a failed write was rejected by a unique index, as opposed to failing for any of the reasons a write fails when the database is unwell.
The distinction is what makes a unique index usable as a race arbiter. A caller that inserts and catches everything as "someone else won" carries on as though another writer succeeded - but in a connection reset, a timeout, or a throttle nobody did, the row is still unclaimed, and the next attempt takes the same branch and fails the same way. One transient fault becomes a fault per attempt for as long as the condition lasts, which is precisely when the database is least able to absorb it.
Matched on the driver's own vocabulary rather than a wrapped error type, because nothing between a caller and the driver classifies it: the repository and the adapters pass the raw failure straight through.
The text match is the load-bearing branch, not the fallback. PlanetScale answers over HTTP through Vitess, and what arrives is one string with the code inside it rather than a structured field:
so errno is prose here and a property check alone would never fire. The
property checks cover the drivers that do populate them - mysql2 sets
ER_DUP_ENTRY, SQLite sets SQLITE_CONSTRAINT_UNIQUE - and the cause chain
is walked because drivers wrap.
ormMarkTokenlessInjection
called by the token-less ORM inject decorators
ormPaginatedFind
Creates a paginated find query for the given entity.
Where conditions AND-merge across all sources, with server conditions
winning over client filters on key collision:
client pagination.filters < pagination.scopeWhere(...) < input.where.
Ordering uses the pagination orderBy when present, otherwise
input.order.
ormRequireTable
ormRunPendingMigrations
Migration runner for Durable SQLite databases.
Runs all pending migrations sequentially, with each migration getting its own blockConcurrencyWhile call for race condition protection and independent 30-second timeout budgets. Errors are fail-fast with automatic retry on next access.
Before judging drift, applied rows carrying an obsolete label — the
placeholder tags the tracking-table schema upgrade synthesizes, or a
content hash an older runner recorded — are reconciled back to their
journal tag by exact createdAt match and rewritten in place, so a
DO that lived through the legacy schema keeps booting in every
environment.
In Development, detects "journal drift" — applied migration tags that
no longer exist in source (which happens after schema:diff auto-folds
an unreleased migration). When drift is detected, wipes the DO's user
tables and the migrations tracking table, then reapplies from scratch.
This makes iteration on a single growing unreleased migration seamless
— local DOs don't accumulate stale schema.
In non-Development, the same drift situation is a hard error (this function only sees the situation after the caller's released-list check passes, so drift in prod is an integrity bug).
parentColumn
Creates a OrmParentColumnReference for use in a mapped join's
where.
requireColumnMode
mode is required on bigint, decimal, and datetime columns — the type
system enforces it for TypeScript consumers; this guards JavaScript
callers and stale metadata with the same loud failure at
schema-build time instead of silently picking a representation.
requireTruncatable
Throws if the table is not marked truncatable: true in its
@OrmTable() options. Called before any truncate() operation to
prevent accidental full-table wipes on tables that weren't designed
to be wiped.