@samveys/database

Koneksi, query builder dan schema builder, migrasi, seeder; PostgreSQL, MySQL/MariaDB, SQLite

Versi
1.0.35 Nov 2026
Pasang
pnpm add @samveys/database
Dokumentasi
README paket ini

Daftar ini dibaca dari versi 1.0.2; jalankan pnpm sync untuk memperbaruinya.

Import
import { createDatabaseManager, createDialect, createMigrator, createQueryBuilder, createSchemaBuilder, database, … } from '@samveys/database'

Fungsi (21)

createDatabaseManager Fungsi

Holds every named connection. A connection, and its client library, is loaded on the first query, then reused. `close()` closes the opened ones.

function createDatabaseManager(config: DatabaseConfig, options?: DatabaseManagerOptions): DatabaseManager;

Diekspor dari packages/database/src/manager.ts

createDialect Fungsi

Builds a frozen `Dialect` from the engine-specific parts. Dialects are pure: no I/O, no client library.

function createDialect(spec: DialectSpec): Dialect;

Diekspor dari packages/database/src/dialects/base.ts

createMigrator Fungsi

Runs migrations on one connection, recording them in `samveys_migrations`.

function createMigrator(options: MigratorOptions): Migrator;

Diekspor dari packages/database/src/migrations.ts

createQueryBuilder Fungsi

A new immutable query builder for `table`, running through `runner`.

function createQueryBuilder<R extends Row = Row>(runner: Runner, table: string): QueryBuilder<R>;

Diekspor dari packages/database/src/query/builder.ts

createSchemaBuilder Fungsi

Creates a schema builder. Calls only plan DDL; `toSQL()` reads the plan. `hasTable` and `columns` read the live catalog through `db`.

function createSchemaBuilder(dialect: Dialect, db: Queryable): SchemaPlan;

Diekspor dari packages/database/src/schema.ts

database Fungsi

The `@samveys/database` plugin: binds `'db'` (the DatabaseManager), a deploy check for every connection and the `migrate`, `migrate:rollback`, `migrate:status`, `db:seed` and `db:wipe` commands.

function database(config: DatabaseConfig, options?: DatabasePluginOptions): import("@samveys/core").Plugin<DatabasePluginInput>;

Diekspor dari packages/database/src/plugin.ts

databaseFromEnv Fungsi

One connection chosen by the environment, so switching engines is a deploy setting: - `DB_CONNECTION`: `sqlite`, `mysql` (MySQL or MariaDB), `postgres` (also `pgsql`, `postgresql`). When it is not set, the scheme of `DATABASE_URL` decides (`postgres://` is PostgreSQL), so a URL is never silently ignored; with neither, the engine is SQLite (the default, ADR 0011). - `DATABASE_URL` (`mysql://…`, `postgres://…`), or `DB_HOST`, `DB_PORT`, `DB_DATABASE`, `DB_USERNAME`, `DB_PASSWORD`; for SQLite, `DB_DATABASE` is the file (default `storage/app.db`). Unknown engine names fail with SVS_E070 listing the supported ones.

function databaseFromEnv(env?: Readonly<Record<string, string | undefined>>): ConnectionConfig;

Diekspor dari packages/database/src/drivers/index.ts

defineDatabaseConfig Fungsi

Identity helper that types named connections.

function defineDatabaseConfig<const Connections extends Readonly<Record<string, ConnectionConfig>>>(config: {

Diekspor dari packages/database/src/manager.ts

defineMigration Fungsi

Declares a migration. `transaction: false` is needed for PostgreSQL `CONCURRENTLY`.

function defineMigration(migration: Omit<Migration, 'kind'>): Migration;

Diekspor dari packages/database/src/migrations.ts

defineSeeder Fungsi

Declares a seeder for `svs db:seed`.

function defineSeeder(seeder: Omit<Seeder, 'kind'>): Seeder;

Diekspor dari packages/database/src/migrations.ts

fromDriverValue Fungsi

Shared value conversion; dialects override the engine-specific parts.

function fromDriverValue(value: unknown, type: ColumnType | undefined): DbValue;

Diekspor dari packages/database/src/dialects/base.ts

importLaravelMigration Fungsi

Converts the PHP source of one Laravel migration.

function importLaravelMigration(php: string): LaravelImportResult;

Diekspor dari packages/database/src/laravel.ts

instantFrom Fungsi

An instant from text with an offset, or from zone-less text that is UTC (MySQL).

function instantFrom(text: string): Temporal.Instant;

Diekspor dari packages/database/src/dialects/base.ts

laravelMigrationName Fungsi

`2024_01_01_000000_create_users_table.php` → `2024_01_01_000000_create_users_table.ts` (keeps Laravel's order).

function laravelMigrationName(file: string): string;

Diekspor dari packages/database/src/laravel.ts

literal Fungsi

A literal for DDL defaults, where engines do not accept bound parameters. Strings are quoted and escaped.

function literal(value: DbValue, booleanAsInteger: boolean): string;

Diekspor dari packages/database/src/dialects/base.ts

mysql Fungsi

MySQL, and MariaDB through the same wire protocol, via `mysql2` (install it in the app). One name for both (ADR 0012); conformance runs on MySQL 8.4 and MariaDB 11.4 so differences are caught.

function mysql(options: MysqlOptions): ConnectionConfig<MysqlOptions>;

Diekspor dari packages/database/src/drivers/index.ts

postgres Fungsi

PostgreSQL through `pg` (install it in the app).

function postgres(options: PostgresOptions): ConnectionConfig<PostgresOptions>;

Diekspor dari packages/database/src/drivers/index.ts

quoteWith Fungsi

Quotes `name`, `table.column`, `*` and `table.*` with `open`/`close` quote characters. Every part must be a plain name, so quoting is a formality and never the injection boundary.

function quoteWith(name: string, quote: string): string;

Diekspor dari packages/database/src/dialects/base.ts

sqlite Fungsi

SQLite through the built-in `node:sqlite`; `file` may be `:memory:`.

function sqlite(options: SqliteOptions): ConnectionConfig<SqliteOptions>;

Diekspor dari packages/database/src/drivers/index.ts

sqliteColumnType Fungsi

Maps a SQLite declared column type (`pragma table_info` / `stmt.columns()`) to a ColumnType, so values in a `date` or `timestamptz` column come back as Temporal values.

function sqliteColumnType(declared: string | null | undefined): ColumnType | undefined;

Diekspor dari packages/database/src/dialects/sqlite.ts

toInteger Fungsi

Converts an integer from a driver to `number` when it is safe, otherwise `bigint`.

function toInteger(value: string | number | bigint): number | bigint;

Diekspor dari packages/database/src/dialects/base.ts

Nilai (3)

mysqlDialect Nilai

MySQL (also used for MariaDB servers): `?` placeholders, no RETURNING (insertId), implicit commits on DDL.

const mysqlDialect: import("../contracts.ts").Dialect;

Diekspor dari packages/database/src/dialects/mysql.ts

postgresDialect Nilai

PostgreSQL: `$1` placeholders, RETURNING, transactional DDL, `lock_timeout` for migrations.

const postgresDialect: import("../contracts.ts").Dialect;

Diekspor dari packages/database/src/dialects/postgres.ts

sqliteDialect Nilai

SQLite: `?` placeholders, RETURNING (3.35+), transactional DDL.

const sqliteDialect: import("../contracts.ts").Dialect;

Diekspor dari packages/database/src/dialects/sqlite.ts

Interface (36)

ColumnBuilder Interface

Tidak ada komentar dokumentasi.

interface ColumnBuilder {
    nullable(): ColumnBuilder;
    unique(): ColumnBuilder;
    primary(): ColumnBuilder;
    default(value: DbValue): ColumnBuilder;
    references(table: string, column?: string, onDelete?: 'cascade' | 'restrict' | 'set null'): ColumnBuilder;
}

Diekspor dari packages/database/src/contracts.ts

ColumnDefinition Interface

Tidak ada komentar dokumentasi.

interface ColumnDefinition {
    readonly name: string;
    readonly type: ColumnType;
    readonly nullable: boolean;
    readonly unique: boolean;
    readonly primary: boolean;
    /** A literal default; SQL expressions are not allowed here. */
    readonly default?: DbValue;
    /** `string` length, `decimal` [precision, scale]. */
    readonly length?: number;
  …
Tampilkan seluruh deklarasi (17 baris)
interface ColumnDefinition {
    readonly name: string;
    readonly type: ColumnType;
    readonly nullable: boolean;
    readonly unique: boolean;
    readonly primary: boolean;
    /** A literal default; SQL expressions are not allowed here. */
    readonly default?: DbValue;
    /** `string` length, `decimal` [precision, scale]. */
    readonly length?: number;
    readonly precision?: readonly [number, number];
    readonly references?: {
        readonly table: string;
        readonly column: string;
        readonly onDelete?: 'cascade' | 'restrict' | 'set null';
    };
}

Diekspor dari packages/database/src/contracts.ts

CompiledQuery Interface

Tidak ada komentar dokumentasi.

interface CompiledQuery {
    readonly sql: string;
    readonly bindings: readonly DbValue[];
}

Diekspor dari packages/database/src/contracts.ts

ConnectionConfig Interface

Returned by `postgres()`, `mysql()`, `sqlite()`: a driver plus its options, resolved on first use.

interface ConnectionConfig<Options = unknown> {
    /** Known before connecting, so SQL can be built without loading the client library. */
    readonly dialect: Dialect;
    readonly driver: () => Promise<DatabaseDriver<Options>>;

Diekspor dari packages/database/src/contracts.ts

CursorPage Interface

Tidak ada komentar dokumentasi.

interface CursorPage<R extends Row> {
    readonly data: readonly R[];
    /** Opaque cursor for the next page, or `null` on the last page. Base64url of the ordering values. */
    readonly next: string | null;
}

Diekspor dari packages/database/src/contracts.ts

Database Interface

One named connection.

interface Database extends Queryable {
    readonly name: string;
    from<R extends Row = Row>(table: string): QueryBuilder<R>;
    rawQuery<R extends Row = Row>(sql: string, bindings?: readonly DbValue[], options?: QueryOptions): Promise<QueryResult<R>>;
    /** `await using trx = await db.transaction()` — rolls back on scope exit unless committed. */
    transaction(): Promise<Transaction>;
    /** Callback form: commits when `work` resolves, rolls back and rethrows the original error when it throws. */
    transaction<T>(work: (trx: Transaction) => Promise<T>): Promise<T>;

Diekspor dari packages/database/src/contracts.ts

DatabaseConfig Interface

Tidak ada komentar dokumentasi.

interface DatabaseConfig<Names extends string = string> {
    readonly default: Names;
    readonly connections: {
        readonly [K in Names]: ConnectionConfig;
    };
}

Diekspor dari packages/database/src/contracts.ts

DatabaseDriver Interface

Tidak ada komentar dokumentasi.

interface DatabaseDriver<Options = unknown> {
    readonly name: string;
    readonly dialect: Dialect;
    /** Connects lazily-loaded client libraries: `pg` and `mysql2` are imported here, never at module load. */
    connect(options: Options): Promise<DriverConnection>;
}

Diekspor dari packages/database/src/contracts.ts

DatabaseManager Interface

Holds every named connection; connections open lazily on first query.

interface DatabaseManager extends Database {
    /** Closes every opened connection. Called on app shutdown. */
    close(): Promise<void>;
    /** Names of configured connections. */
    readonly names: readonly string[];
}

Diekspor dari packages/database/src/contracts.ts

DatabaseManagerOptions Interface

Tidak ada komentar dokumentasi.

interface DatabaseManagerOptions {
    readonly logger?: Logger;
}

Diekspor dari packages/database/src/manager.ts

DatabasePluginOptions Interface

Options of the `database()` plugin beyond the connections.

interface DatabasePluginOptions {
    /** Directory of migration files, relative to the app root. Default `database/migrations`. */
    readonly migrations?: string;
    /** Directory of seeder files, relative to the app root. Default `database/seeders`. */
    readonly seeders?: string;
}

Diekspor dari packages/database/src/contracts.ts

Dialect Interface

Tidak ada komentar dokumentasi.

interface Dialect {
    readonly name: 'postgres' | 'mysql' | 'sqlite' | (string & {});
    /** Quotes one identifier (`"users"`, `` `users` ``). Rejects names containing NUL. */
    quoteIdentifier(name: string): string;
    /** Placeholder for the parameter at `index` (0-based): `$1` or `?`. */
    placeholder(index: number): string;
    /** True when INSERT/UPDATE/DELETE support `RETURNING`. */
    readonly supportsReturning: boolean;
    /** True when DDL runs inside a transaction (PostgreSQL, SQLite), so a failed migration leaves no trace. */
    readonly transactionalDdl: boolean;
  …
Tampilkan seluruh deklarasi (24 baris)
interface Dialect {
    readonly name: 'postgres' | 'mysql' | 'sqlite' | (string & {});
    /** Quotes one identifier (`"users"`, `` `users` ``). Rejects names containing NUL. */
    quoteIdentifier(name: string): string;
    /** Placeholder for the parameter at `index` (0-based): `$1` or `?`. */
    placeholder(index: number): string;
    /** True when INSERT/UPDATE/DELETE support `RETURNING`. */
    readonly supportsReturning: boolean;
    /** True when DDL runs inside a transaction (PostgreSQL, SQLite), so a failed migration leaves no trace. */
    readonly transactionalDdl: boolean;
    /** SQL type for a column definition. */
    columnType(column: ColumnDefinition): string;
    /** Converts a bound value to what the client library expects (e.g. Temporal → string). */
    toDriver(value: DbValue, type?: ColumnType): unknown;
    /** Converts a raw column value to a `DbValue`, using the column type when known. */
    fromDriver(value: unknown, type?: ColumnType): DbValue;
    /** Statement run before each migration (e.g. `SET lock_timeout = '5s'`), or undefined. */
    migrationPreamble(): string | undefined;
    /**
     * Optional (ADR 0014): appends LIMIT/OFFSET in the engine's own syntax (e.g. `OFFSET … ROWS FETCH NEXT … ROWS ONLY`).
     * `bind` adds a binding and returns its placeholder; call it in the order the placeholders appear.
     * Without it the builder writes `limit ? offset ?`.
     */
    paginate?(sql: string, limit: number | undefined, offset: number | undefined, bind: (value: DbValue) => string, hasOrderBy: boolean): string;

Diekspor dari packages/database/src/contracts.ts

DialectSpec Interface

Tidak ada komentar dokumentasi.

interface DialectSpec {
    readonly name: string;
    readonly quote: string;
    readonly placeholder: (index: number) => string;

Diekspor dari packages/database/src/dialects/base.ts

DriverConnection Interface

A pooled connection to one database, as returned by `DatabaseDriver.connect`.

interface DriverConnection extends Queryable {
    /** Starts a transaction on a dedicated pooled connection. */
    begin(): Promise<DriverTransaction>;
    /** Closes the pool; waits for checked-out connections up to `timeout` ms. */
    close(options?: {
        readonly timeout?: number;
    }): Promise<void>;
}

Diekspor dari packages/database/src/contracts.ts

DriverTransaction Interface

Tidak ada komentar dokumentasi.

interface DriverTransaction extends Queryable {
    commit(): Promise<void>;
    rollback(): Promise<void>;
    /** Nested transaction as a SAVEPOINT. */
    savepoint(): Promise<DriverTransaction>;
}

Diekspor dari packages/database/src/contracts.ts

IndexDefinition Interface

Tidak ada komentar dokumentasi.

interface IndexDefinition {
    readonly name: string;
    readonly table: string;
    readonly columns: readonly string[];
    readonly unique: boolean;
    /** PostgreSQL `CREATE INDEX CONCURRENTLY`. Ignored by engines without it. */
    readonly concurrently: boolean;
}

Diekspor dari packages/database/src/contracts.ts

IndexOptions Interface

Tidak ada komentar dokumentasi.

interface IndexOptions {
    readonly name?: string;
    readonly unique?: boolean;
    /** Required for PostgreSQL indexes on existing tables unless `safetyAssured`. */
    readonly concurrently?: boolean;
}

Diekspor dari packages/database/src/contracts.ts

LaravelImportResult Interface

Imports Laravel migrations. Reads the `Schema::create`, `Schema::table`, `Schema::dropIfExists` and `Schema::drop` calls of each `up()` / `down()` and writes Samveys migrations. It parses the Blueprint subset Laravel apps use most; anything else becomes a `// TODO(laravel)` line in the output and is listed in `unsupported`, so nothing is dropped silently. This is a text converter, not a PHP interpreter: logic around the calls (ifs, loops) is not run.

interface LaravelImportResult {
    /** Samveys migration source, `export default defineMigration({...})`. */
    readonly source: string;
    /** Statements that were not converted, with the line they came from. */
    readonly unsupported: readonly string[];
}

Diekspor dari packages/database/src/laravel.ts

Migration Interface

Tidak ada komentar dokumentasi.

interface Migration {
    readonly kind: 'migration';
    up(context: MigrationContext): void | Promise<void>;
    down(context: MigrationContext): void | Promise<void>;
    /** PostgreSQL CONCURRENTLY operations cannot run in a transaction; set false for them. Default true. */
    readonly transaction?: boolean;
}

Diekspor dari packages/database/src/contracts.ts

MigrationContext Interface

Tidak ada komentar dokumentasi.

interface MigrationContext {
    readonly schema: SchemaBuilder;
    readonly db: Queryable;
    /** Marks a dangerous operation as reviewed, with the reason. */
    safetyAssured(reason: string): void;
}

Diekspor dari packages/database/src/contracts.ts

MigrationRunOptions Interface

Tidak ada komentar dokumentasi.

interface MigrationRunOptions {
    /** Print SQL instead of running it (`svs migrate --dry-run`). */
    readonly dryRun?: boolean;
    readonly connection?: string;
}

Diekspor dari packages/database/src/contracts.ts

MigrationRunResult Interface

Tidak ada komentar dokumentasi.

interface MigrationRunResult {
    readonly ran: readonly string[];
    /** SQL per migration, in run order (always filled; executed unless dryRun). */
    readonly sql: readonly {
        readonly migration: string;
        readonly statements: readonly string[];
    }[];
}

Diekspor dari packages/database/src/contracts.ts

MigrationStatus Interface

Tidak ada komentar dokumentasi.

interface MigrationStatus {
    readonly name: string;
    readonly batch: number | undefined;
    readonly ranAt: Temporal.Instant | undefined;
}

Diekspor dari packages/database/src/contracts.ts

Migrator Interface

Tidak ada komentar dokumentasi.

interface Migrator {
    status(): Promise<readonly MigrationStatus[]>;
    /** Runs pending migrations as one batch. Unsafe operations without `safetyAssured` throw SVS_E072 before anything runs. */
    migrate(options?: MigrationRunOptions): Promise<MigrationRunResult>;
    /** Reverts the last batch (or `steps` batches). */
    rollback(options?: MigrationRunOptions & {
        readonly steps?: number;
    }): Promise<MigrationRunResult>;
    /** Drops every table the migrations created, then clears the migrations table. */
    reset(options?: MigrationRunOptions): Promise<MigrationRunResult>;
}

Diekspor dari packages/database/src/contracts.ts

MigratorOptions Interface

Tidak ada komentar dokumentasi.

interface MigratorOptions {
    readonly database: Database;
    /** Migrations by name (run in name order), or a directory of `*.ts`/`*.js` files exporting one by default. */
    readonly migrations: Readonly<Record<string, Lazy<Migration>>> | string;
}

Diekspor dari packages/database/src/migrations.ts

Page Interface

Tidak ada komentar dokumentasi.

interface Page<R extends Row> {
    readonly data: readonly R[];
    readonly page: number;
    readonly perPage: number;
    readonly total: number;
    readonly lastPage: number;
}

Diekspor dari packages/database/src/contracts.ts

Queryable Interface

Something that runs SQL: a connection, a transaction, or a savepoint.

interface Queryable {
    readonly dialect: Dialect;
    query<R extends Row = Row>(sql: string, bindings?: readonly DbValue[], options?: QueryOptions): Promise<QueryResult<R>>;
    /** Rows one at a time, without loading the whole result in memory. */
    stream<R extends Row = Row>(sql: string, bindings?: readonly DbValue[], options?: QueryOptions): AsyncIterable<R>;
}

Diekspor dari packages/database/src/contracts.ts

QueryBuilder Interface

Immutable: every method returns a new builder. Identifiers are always quoted; values are always bound.

interface QueryBuilder<R extends Row = Row> {
    select(...columns: readonly string[]): QueryBuilder<R>;
    where(column: string, value: DbValue): QueryBuilder<R>;
    where(column: string, operator: Operator, value: DbValue): QueryBuilder<R>;
    orWhere(column: string, value: DbValue): QueryBuilder<R>;
    orWhere(column: string, operator: Operator, value: DbValue): QueryBuilder<R>;
    whereIn(column: string, values: readonly DbValue[]): QueryBuilder<R>;
    whereNotIn(column: string, values: readonly DbValue[]): QueryBuilder<R>;
    whereNull(column: string): QueryBuilder<R>;
    whereNotNull(column: string): QueryBuilder<R>;
  …
Tampilkan seluruh deklarasi (13 baris)
interface QueryBuilder<R extends Row = Row> {
    select(...columns: readonly string[]): QueryBuilder<R>;
    where(column: string, value: DbValue): QueryBuilder<R>;
    where(column: string, operator: Operator, value: DbValue): QueryBuilder<R>;
    orWhere(column: string, value: DbValue): QueryBuilder<R>;
    orWhere(column: string, operator: Operator, value: DbValue): QueryBuilder<R>;
    whereIn(column: string, values: readonly DbValue[]): QueryBuilder<R>;
    whereNotIn(column: string, values: readonly DbValue[]): QueryBuilder<R>;
    whereNull(column: string): QueryBuilder<R>;
    whereNotNull(column: string): QueryBuilder<R>;
    whereBetween(column: string, range: readonly [DbValue, DbValue]): QueryBuilder<R>;
    /** `(…)` group of conditions joined with AND. */
    whereGroup(build: (group: QueryBuilder<R>) => QueryBuilder<R>): QueryBuilder<R>;

Diekspor dari packages/database/src/contracts.ts

QueryOptions Interface

Tidak ada komentar dokumentasi.

interface QueryOptions {
    /** Aborts the query; drivers cancel it on the server where the engine allows. */
    readonly signal?: AbortSignal;
}

Diekspor dari packages/database/src/contracts.ts

QueryResult Interface

Tidak ada komentar dokumentasi.

interface QueryResult<R extends Row = Row> {
    readonly rows: readonly R[];
    /** Rows changed by INSERT/UPDATE/DELETE. `0` for SELECT. */
    readonly rowCount: number;
    /** For INSERT on engines without RETURNING (MySQL, SQLite): the last generated id, else `undefined`. */
    readonly insertId: number | bigint | undefined;
}

Diekspor dari packages/database/src/contracts.ts

Runner Interface

Runs SQL for a builder; transactions pass their own (finished-transaction checks live there).

interface Runner {
    readonly dialect: Dialect;
    query: Queryable['query'];
    stream: Queryable['stream'];
}

Diekspor dari packages/database/src/query/builder.ts

SafetyViolation Interface

Tidak ada komentar dokumentasi.

interface SafetyViolation {
    readonly migration: string;
    readonly statement: string;
    readonly rule: string;
    readonly suggestion: string;
}

Diekspor dari packages/database/src/contracts.ts

SchemaBuilder Interface

Tidak ada komentar dokumentasi.

interface SchemaBuilder {
    createTable(name: string, build: (table: TableBuilder) => void): SchemaBuilder;

Diekspor dari packages/database/src/contracts.ts

Seeder Interface

Tidak ada komentar dokumentasi.

interface Seeder {
    readonly kind: 'seeder';
    run(db: Database): Promise<void>;
}

Diekspor dari packages/database/src/contracts.ts

TableBuilder Interface

Tidak ada komentar dokumentasi.

interface TableBuilder {
    increments(name?: string): ColumnBuilder;
    bigIncrements(name?: string): ColumnBuilder;
    integer(name: string): ColumnBuilder;
    bigInteger(name: string): ColumnBuilder;
    decimal(name: string, precision?: number, scale?: number): ColumnBuilder;
    float(name: string): ColumnBuilder;
    boolean(name: string): ColumnBuilder;
    string(name: string, length?: number): ColumnBuilder;
    text(name: string): ColumnBuilder;
  …
Tampilkan seluruh deklarasi (19 baris)
interface TableBuilder {
    increments(name?: string): ColumnBuilder;
    bigIncrements(name?: string): ColumnBuilder;
    integer(name: string): ColumnBuilder;
    bigInteger(name: string): ColumnBuilder;
    decimal(name: string, precision?: number, scale?: number): ColumnBuilder;
    float(name: string): ColumnBuilder;
    boolean(name: string): ColumnBuilder;
    string(name: string, length?: number): ColumnBuilder;
    text(name: string): ColumnBuilder;
    json(name: string): ColumnBuilder;
    uuid(name: string): ColumnBuilder;
    binary(name: string): ColumnBuilder;
    date(name: string): ColumnBuilder;
    datetime(name: string): ColumnBuilder;
    timestamptz(name: string): ColumnBuilder;
    /** `created_at` and `updated_at` as `timestamptz`. */
    timestamps(): void;
}

Diekspor dari packages/database/src/contracts.ts

Transaction Interface

A transaction as seen by application code. `await using` rolls back unless `commit()` ran (#6).

interface Transaction extends Queryable, AsyncDisposable {
    from<R extends Row = Row>(table: string): QueryBuilder<R>;
    rawQuery<R extends Row = Row>(sql: string, bindings?: readonly DbValue[], options?: QueryOptions): Promise<QueryResult<R>>;
    commit(): Promise<void>;
    rollback(): Promise<void>;
    /** Nested transaction through a SAVEPOINT. */
    transaction(): Promise<Transaction>;
    transaction<T>(work: (trx: Transaction) => Promise<T>): Promise<T>;

Diekspor dari packages/database/src/contracts.ts

Tipe (9)

ColumnType Tipe

Column types understood by the schema builder and the Temporal mapping.

type ColumnType = 'increments' | 'bigIncrements' | 'integer' | 'bigInteger' | 'decimal' | 'float' | 'boolean' | 'string' | 'text' | 'json' | 'uuid' | 'binary' | 'date' | 'datetime' | 'timestamptz';

Diekspor dari packages/database/src/contracts.ts

DatabaseEngine Tipe

Engines `databaseFromEnv()` understands, in `DB_CONNECTION`.

type DatabaseEngine = 'sqlite' | 'mysql' | 'postgres';

Diekspor dari packages/database/src/drivers/index.ts

DbValue Tipe

Values that can be bound to a query and that rows may contain.

type DbValue = string | number | bigint | boolean | null | Uint8Array | Temporal.PlainDate | Temporal.PlainDateTime | Temporal.Instant;

Diekspor dari packages/database/src/contracts.ts

Direction Tipe

Tidak ada komentar dokumentasi.

type Direction = 'asc' | 'desc';

Diekspor dari packages/database/src/contracts.ts

MysqlOptions Tipe

Tidak ada komentar dokumentasi.

export { MysqlOptions } from './drivers/index.ts'

Diekspor dari packages/database/src/drivers/index.ts

Operator Tipe

Tidak ada komentar dokumentasi.

type Operator = '=' | '!=' | '<>' | '<' | '<=' | '>' | '>=' | 'like' | 'not like' | 'ilike';

Diekspor dari packages/database/src/contracts.ts

PostgresOptions Tipe

Tidak ada komentar dokumentasi.

export { PostgresOptions } from './drivers/index.ts'

Diekspor dari packages/database/src/drivers/index.ts

Row Tipe

One result row. Prototype-less; column order follows the query.

type Row = Readonly<Record<string, DbValue>>;

Diekspor dari packages/database/src/contracts.ts

SqliteOptions Tipe

Tidak ada komentar dokumentasi.

export { SqliteOptions } from './drivers/index.ts'

Diekspor dari packages/database/src/drivers/index.ts