@stacksjs/database 0.70.87 → 0.70.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/package.json +10 -10
  2. package/dist/auth-tables.d.ts +0 -60
  3. package/dist/class-seeder.d.ts +0 -65
  4. package/dist/custom/audits.d.ts +0 -16
  5. package/dist/custom/errors.d.ts +0 -1
  6. package/dist/custom/index.d.ts +0 -3
  7. package/dist/custom/jobs.d.ts +0 -3
  8. package/dist/database.d.ts +0 -89
  9. package/dist/defaults.d.ts +0 -48
  10. package/dist/driver-config.d.ts +0 -149
  11. package/dist/drivers/defaults/index.d.ts +0 -2
  12. package/dist/drivers/defaults/passwords.d.ts +0 -4
  13. package/dist/drivers/defaults/traits.d.ts +0 -33
  14. package/dist/drivers/dynamodb.d.ts +0 -200
  15. package/dist/drivers/helpers.d.ts +0 -35
  16. package/dist/drivers/index.d.ts +0 -16
  17. package/dist/drivers/mysql.d.ts +0 -7
  18. package/dist/drivers/postgres.d.ts +0 -7
  19. package/dist/drivers/sqlite.d.ts +0 -20
  20. package/dist/factory.d.ts +0 -41
  21. package/dist/fk-audit.d.ts +0 -101
  22. package/dist/index.d.ts +0 -149
  23. package/dist/index.js +0 -1263
  24. package/dist/migration-lock.d.ts +0 -23
  25. package/dist/migrations.d.ts +0 -76
  26. package/dist/notification-tables.d.ts +0 -20
  27. package/dist/query-logger.d.ts +0 -26
  28. package/dist/query-parser.d.ts +0 -4
  29. package/dist/rbac-tables.d.ts +0 -17
  30. package/dist/safe-migrations.d.ts +0 -72
  31. package/dist/seed-scaffold.d.ts +0 -34
  32. package/dist/seeder.d.ts +0 -116
  33. package/dist/sql-helpers.d.ts +0 -33
  34. package/dist/transaction-context.d.ts +0 -52
  35. package/dist/types.d.ts +0 -151
  36. package/dist/unique-audit.d.ts +0 -60
  37. package/dist/utils.d.ts +0 -189
  38. package/dist/uuid-columns.d.ts +0 -22
  39. package/dist/validators.d.ts +0 -26
@@ -1,200 +0,0 @@
1
- import type { Model } from '@stacksjs/types';
2
- /**
3
- * Marshall a JS object to DynamoDB format
4
- */
5
- declare function marshall(obj: Record<string, unknown>): DynamoItem;
6
- /**
7
- * Unmarshall a DynamoDB object to JS format
8
- */
9
- declare function unmarshall(obj: DynamoItem): Record<string, unknown>;
10
- /**
11
- * Generate key pattern for an entity
12
- */
13
- export declare function generateKeyPattern(entityName: string, idField?: string): string;
14
- /**
15
- * Parse a key pattern and extract values
16
- */
17
- export declare function parseKeyPattern(pattern: string, key: string): Record<string, string>;
18
- /**
19
- * Build a key from a pattern and values
20
- */
21
- export declare function buildKey(pattern: string, values: Record<string, string>): string;
22
- /**
23
- * Create a new DynamoDB client instance
24
- */
25
- export declare function createDynamo(): DynamoClient;
26
- /**
27
- * DynamoDB client singleton
28
- */
29
- export declare const dynamo: DynamoClient;
30
- /**
31
- * Minimal AWS-SDK `DynamoDBClient` shape — just the methods this
32
- * driver calls. Typed locally so callers wiring their own SDK
33
- * client into `setClient()` get a clear compile-time contract
34
- * instead of a runtime "function not found" surprise.
35
- */
36
- export declare interface DynamoSdkClient {
37
- query: (req: Record<string, unknown>) => Promise<{
38
- Items?: DynamoItem[]
39
- Count?: number
40
- ScannedCount?: number
41
- LastEvaluatedKey?: DynamoItem
42
- }>
43
- scan: (req: Record<string, unknown>) => Promise<{
44
- Items?: DynamoItem[]
45
- Count?: number
46
- ScannedCount?: number
47
- LastEvaluatedKey?: DynamoItem
48
- }>
49
- getItem: (req: Record<string, unknown>) => Promise<{ Item?: DynamoItem }>
50
- putItem: (req: Record<string, unknown>) => Promise<unknown>
51
- deleteItem: (req: Record<string, unknown>) => Promise<unknown>
52
- updateItem: (req: Record<string, unknown>) => Promise<unknown>
53
- batchWriteItem: (req: Record<string, unknown>) => Promise<unknown>
54
- transactWriteItems: (req: Record<string, unknown>) => Promise<unknown>
55
- }
56
- /**
57
- * DynamoDB connection configuration
58
- */
59
- export declare interface DynamoConnectionConfig {
60
- region: string
61
- table: string
62
- endpoint?: string
63
- credentials?: {
64
- accessKeyId: string
65
- secretAccessKey: string
66
- sessionToken?: string
67
- }
68
- pkAttribute?: string
69
- skAttribute?: string
70
- entityTypeAttribute?: string
71
- keyDelimiter?: string
72
- }
73
- /**
74
- * Entity mapping for single-table design
75
- */
76
- export declare interface SingleTableEntityMapping {
77
- entityType: string
78
- pkPattern: string
79
- skPattern?: string
80
- gsi1pk?: string
81
- gsi1sk?: string
82
- gsi2pk?: string
83
- gsi2sk?: string
84
- }
85
- /**
86
- * Sort key builder for fluent API
87
- */
88
- export declare interface SortKeyBuilder {
89
- equals(value: string): EntityQueryBuilder
90
- beginsWith(prefix: string): EntityQueryBuilder
91
- between(start: string, end: string): EntityQueryBuilder
92
- lt(value: string): EntityQueryBuilder
93
- lte(value: string): EntityQueryBuilder
94
- gt(value: string): EntityQueryBuilder
95
- gte(value: string): EntityQueryBuilder
96
- }
97
- /**
98
- * Batch write operation
99
- */
100
- export declare interface BatchWriteOperation {
101
- put?: { entity: string, item: Record<string, unknown> }
102
- delete?: { entity: string, pk: string, sk: string }
103
- }
104
- /**
105
- * Transact write operation
106
- */
107
- export declare interface TransactWriteOperation {
108
- put?: { entity: string, item: Record<string, unknown>, condition?: string }
109
- update?: { entity: string, pk: string, sk?: string, set?: Record<string, unknown>, add?: Record<string, number>, remove?: string[] }
110
- delete?: { entity: string, pk: string, sk: string, condition?: string }
111
- conditionCheck?: { entity: string, pk: string, sk: string, condition: string }
112
- }
113
- /**
114
- * Query result
115
- */
116
- export declare interface QueryResult<T = unknown> {
117
- items: T[]
118
- count: number
119
- scannedCount?: number
120
- lastKey?: Record<string, unknown>
121
- }
122
- /**
123
- * DynamoDB AttributeValue discriminated union (stacksjs/stacks#1894 T-8).
124
- *
125
- * Mirrors the wire format AWS SDK's `DynamoDBClient` produces and
126
- * consumes, declared locally so this package doesn't take a hard
127
- * dependency on `@aws-sdk/client-dynamodb` just for its types. Each
128
- * concrete variant carries its own typed payload; consumers narrow
129
- * via `'S' in attr` / etc.
130
- *
131
- * Why not just import from AWS SDK: the framework's DynamoDB driver
132
- * ships as an optional peer integration. Pulling AWS SDK as a type-
133
- * level dep would force every Stacks app to install it whether or
134
- * not they use the driver.
135
- */
136
- export type DynamoAttributeValue = | { S: string }
137
- | { N: string }
138
- | { B: Uint8Array | string }
139
- | { BOOL: boolean }
140
- | { NULL: true }
141
- | { L: DynamoAttributeValue[] }
142
- | { M: Record<string, DynamoAttributeValue> }
143
- | { SS: string[] }
144
- | { NS: string[] }
145
- | { BS: Array<Uint8Array | string> }
146
- /** Marshalled item — the on-the-wire representation. */
147
- export type DynamoItem = Record<string, DynamoAttributeValue>;
148
- /**
149
- * Entity-centric query builder for DynamoDB
150
- */
151
- export declare class EntityQueryBuilder<T = unknown> {
152
- constructor(client: DynamoSdkClient | undefined, tableName: string, config: { pkAttribute: string, skAttribute: string, entityTypeAttribute: string, keyDelimiter: string });
153
- entity(entityType: string): this;
154
- pk(value: string): this;
155
- get sk(): SortKeyBuilder;
156
- index(indexName: string): this;
157
- project(...attributes: string[]): this;
158
- filter(attribute: string, operator: string, value?: unknown): this;
159
- where(attribute: string, value: unknown): this;
160
- whereIn(attribute: string, values: unknown[]): this;
161
- limit(count: number): this;
162
- asc(): this;
163
- desc(): this;
164
- consistent(): this;
165
- startFrom(key: Record<string, unknown>): this;
166
- toRequest(): Record<string, unknown>;
167
- get(): Promise<T[]>;
168
- first(): Promise<T | undefined>;
169
- getAll(): Promise<T[]>;
170
- count(): Promise<number>;
171
- }
172
- /**
173
- * DynamoDB client with entity-centric API
174
- */
175
- declare class DynamoClient {
176
- connection(config: DynamoConnectionConfig): this;
177
- isConfigured(): boolean;
178
- setClient(client: DynamoSdkClient): this;
179
- getClient(): DynamoSdkClient | undefined;
180
- registerEntity(mapping: SingleTableEntityMapping): this;
181
- registerModel(model: Model): this;
182
- getEntityMapping(entityType: string): SingleTableEntityMapping | undefined;
183
- entity<T = any>(entityType: string): EntityQueryBuilder<T>;
184
- batchWrite(operations: BatchWriteOperation[]): Promise<void>;
185
- transactWrite(operations: TransactWriteOperation[]): Promise<void>;
186
- put(entity: string, item: Record<string, unknown>): Promise<void>;
187
- get<T = any>(pk: string, sk?: string): Promise<T | undefined>;
188
- delete(pk: string, sk?: string): Promise<void>;
189
- update(pk: string, sk: string | undefined, updates: Record<string, unknown>): Promise<void>;
190
- getTableName(): string;
191
- getConfig(): {
192
- tableName: string
193
- pkAttribute: string
194
- skAttribute: string
195
- entityTypeAttribute: string
196
- keyDelimiter: string
197
- };
198
- }
199
- // Export marshall/unmarshall utilities
200
- export { marshall, unmarshall };
@@ -1,35 +0,0 @@
1
- import type { Attribute, AttributesElements, Model } from '@stacksjs/types';
2
- import type { DateValidatorType, EnumValidatorType, NumberValidatorType, StringValidatorType, ValidationType } from '@stacksjs/ts-validation';
3
- export declare function deleteMigrationFiles(): Promise<void>;
4
- export declare function deleteFrameworkModels(): Promise<void>;
5
- export declare function getLastMigrationFields(modelName: string): Promise<AttributesElements>;
6
- export declare function modelTableName(model: Model | string): Promise<string>;
7
- export declare function hasTableBeenMigrated(tableName: string): Promise<boolean>;
8
- export declare function hasMigrationBeenCreated(tableName: string): Promise<boolean>;
9
- export declare function getExecutedMigrations(): Promise<{ name: string }[]>;
10
- export declare function prepareTextColumnType(validator: StringValidatorType, driver?: string): string;
11
- // Add new function for date/time column types
12
- export declare function prepareDateTimeColumnType(validator: DateValidatorType, driver?: string): string;
13
- export declare function compareRanges(range1: Range, range2: Range): boolean;
14
- export declare function checkPivotMigration(dynamicPart: string): Promise<boolean>;
15
- export declare function pluckChanges(array1: string[], array2: string[]): { added: string[], removed: string[] } | null;
16
- export declare function arrangeColumns(attributes: AttributesElements | undefined): Array<[string, Attribute]>;
17
- export declare function isArrayEqual(arr1: (number | undefined)[], arr2: (number | undefined)[]): boolean;
18
- export declare function findDifferingKeys(obj1: any, obj2: any): { key: string, max: number, min: number }[];
19
- export declare function fetchTables(): Promise<string[]>;
20
- export declare function getUpvoteTableName(model: Model, tableName: string): string | undefined;
21
- /**
22
- * Foreign-key column of the likes pivot. MUST mirror the runtime default in
23
- * orm/src/traits/likeable.ts (`${tableName.replace(/s$/, '')}_id`) — a pivot
24
- * generated with any other column name is a table `like()` cannot write to.
25
- */
26
- export declare function getLikeableForeignKey(model: Model, tableName: string): string;
27
- export declare function prepareNumberColumnType(validator: NumberValidatorType, driver?: string): string;
28
- // Add new function for enum column types
29
- export declare function prepareEnumColumnType(validator: EnumValidatorType, driver?: string): string;
30
- export declare function mapFieldTypeToColumnType(validator: ValidationType, driver?: string): string;
31
- export declare function checkIsRequired(rule: string): boolean;
32
- declare interface Range {
33
- min: number
34
- max: number
35
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Drivers — barrel export.
3
- *
4
- * Helpers shared across driver implementations live in `./helpers.ts` (NOT
5
- * inline here) so driver modules can import them without re-importing this
6
- * barrel and triggering a self-cycle. See `./helpers.ts` for the rationale.
7
- */
8
- export * from './helpers';
9
- export * from './mysql';
10
- export * from './postgres';
11
- export * from './sqlite';
12
- export { generateIndexCreationSQL } from './mysql';
13
- export { generateIndexCreationSQL as generatePostgresIndexCreationSQL } from './postgres';
14
- export { generateIndexCreationSQL as generateSqliteIndexCreationSQL } from './sqlite';
15
- export * from './defaults/index';
16
- export * from './dynamodb';
@@ -1,7 +0,0 @@
1
- import type { Ok } from '@stacksjs/error-handling';
2
- export declare function resetMysqlDatabase(): Promise<Ok<string, never>>;
3
- export declare function dropMysqlTables(): Promise<void>;
4
- export declare function generateMysqlMigration(modelPath: string): Promise<void>;
5
- export declare function generateMysqlTraitMigrations(): Promise<void>;
6
- export declare function createAlterTableMigration(modelPath: string): Promise<void>;
7
- export declare function generateIndexCreationSQL(tableName: string, index: { name: string, columns: string[], unique?: boolean, where?: string }): string;
@@ -1,7 +0,0 @@
1
- import type { Ok } from '@stacksjs/error-handling';
2
- export declare function dropPostgresTables(): Promise<void>;
3
- export declare function generatePostgresTraitMigrations(): Promise<void>;
4
- export declare function resetPostgresDatabase(): Promise<Ok<string, never>>;
5
- export declare function generatePostgresMigration(modelPath: string): Promise<void>;
6
- export declare function generateIndexCreationSQL(tableName: string, index: { name: string, columns: string[], unique?: boolean, where?: string }): string;
7
- export declare function fetchPostgresTables(): Promise<string[]>;
@@ -1,20 +0,0 @@
1
- import type { Ok } from '@stacksjs/error-handling';
2
- export declare function resetSqliteDatabase(): Promise<Ok<string, never>>;
3
- /**
4
- * Configure SQLite for the Stacks workload. Idempotent — the pragmas are
5
- * cheap to re-apply, but each one is a no-op once set so repeated calls
6
- * during dev hot-reload don't accumulate state.
7
- *
8
- * Connection bootstrap now applies SQLITE_BOOTSTRAP_PRAGMAS automatically
9
- * inside @stacksjs/query-builder's wrapped `createQueryBuilder`
10
- * (stacksjs/stacks#1951); this export remains for explicit re-application.
11
- * See the shared list in @stacksjs/query-builder for what each pragma does
12
- * and why it must be set per connection.
13
- */
14
- export declare function configureSqlitePragmas(): Promise<void>;
15
- export declare function dropSqliteTables(): Promise<void>;
16
- export declare function fetchSqliteFile(): string;
17
- export declare function fetchTestSqliteFile(): string;
18
- export declare function generateSqliteMigration(modelPath: string): Promise<void>;
19
- export declare function copyModelFiles(modelPath: string): Promise<void>;
20
- export declare function generateIndexCreationSQL(tableName: string, index: { name: string, columns: string[], unique?: boolean, where?: string }): string;
package/dist/factory.d.ts DELETED
@@ -1,41 +0,0 @@
1
- import type { Attribute, Model } from '@stacksjs/types';
2
- import type { SeedResult } from './seeder';
3
- /**
4
- * Build the internal `SeederModel`-shaped payload that `seedModelDirect`
5
- * expects from a public-API call. Pure function — exported separately
6
- * so tests can assert the override-precedence rules without touching
7
- * the database.
8
- *
9
- * Precedence (lowest → highest): per-attribute `factory` output →
10
- * global `options.with` → per-row `options.rows[i]`. All keys are
11
- * snake-cased before insert so callers can use the model's camelCase
12
- * attribute names without thinking about column naming.
13
- */
14
- export declare function buildSeederPayload(modelInput: unknown, options?: GenerateOptions): {
15
- name: string
16
- table: string
17
- count: number
18
- fixtures: Array<Record<string, unknown>>
19
- attributes: Record<string, Attribute>
20
- model: Model
21
- };
22
- /**
23
- * Generate factory rows for a model and insert them. Designed to be
24
- * called from a class seeder.
25
- *
26
- * Honours the model's per-attribute `factory: faker => …` declarations
27
- * — exactly the same code path as the legacy auto-walker — but without
28
- * the implicit "every model with `useSeeder` fires on every run"
29
- * coupling. See stacksjs/stacks#1919 for the rationale.
30
- */
31
- export declare function generate(modelInput: unknown, options?: GenerateOptions): Promise<SeedResult>;
32
- export declare const factory: {
33
- generate: typeof generate
34
- };
35
- export declare interface GenerateOptions {
36
- count?: number
37
- fresh?: boolean
38
- verbose?: boolean
39
- with?: Record<string, unknown>
40
- rows?: Array<Record<string, unknown>>
41
- }
@@ -1,101 +0,0 @@
1
- /**
2
- * Glob, but resilient to "directory doesn't exist yet" (the userland
3
- * `app/Models/` directory in particular often doesn't exist when the
4
- * audit runs in framework tests or scaffolded apps that haven't
5
- * created any models yet). Avoids the Bun Glob ENOENT.
6
- */
7
- export declare function safeGlob(pattern: string): string[];
8
- /**
9
- * Walk every model file (user + framework defaults) and return the
10
- * full list of declared `belongsTo` foreign keys.
11
- *
12
- * Convention: `Comment` with `belongsTo: ['Post']` implies the FK
13
- * `comments.post_id → posts.id`. Same shape the migration generator
14
- * uses, so we keep it consistent here. Other relationship types
15
- * (`hasOne`, `hasMany`, `belongsToMany` through tables) imply FKs in
16
- * the *other* direction or in pivot tables — we only check
17
- * `belongsTo` here for the simplest, highest-signal audit.
18
- */
19
- export declare function getDeclaredFKs(): Promise<DeclaredFK[]>;
20
- /**
21
- * Query the live database for every foreign key constraint, returning
22
- * a normalised shape. Dialect-aware: PRAGMA on SQLite,
23
- * information_schema on MySQL / PostgreSQL.
24
- */
25
- export declare function getLiveFKs(): Promise<LiveFK[]>;
26
- /**
27
- * Diff declared FKs against live FKs. Returns the declared FKs that
28
- * have no matching row in the live database — these are the silent
29
- * "FK should be enforcing referential integrity but isn't" cases that
30
- * motivated this audit.
31
- *
32
- * Match key is `fromTable.fromColumn → toTable.toColumn` (case-
33
- * insensitive). Extra live FKs (present in DB but not in any model)
34
- * are not reported — those usually come from manual migrations or
35
- * external tooling, both legitimate.
36
- */
37
- export declare function auditForeignKeys(): Promise<FkAuditResult>;
38
- /**
39
- * Scan the live database for rows whose foreign key references a
40
- * parent row that doesn't exist. SQLite's `PRAGMA foreign_key_check`
41
- * does this regardless of the `foreign_keys` pragma state and excludes
42
- * NULL-FK rows. The violating column is resolved by joining the
43
- * reported `fkid` against `PRAGMA foreign_key_list(table)`.
44
- */
45
- export declare function findFkOrphans(dialect?: 'sqlite' | 'mysql' | 'postgres' | 'other'): Promise<FkOrphanReport>;
46
- // stacksjs/stacks#1916 — Foreign-key audit. Compares each model's
47
- // declared `belongsTo` relationships against the FKs that actually
48
- // exist in the live database. Drives `buddy doctor`'s FK integrity
49
- // check, surfaces the "you flipped DB_CONNECTION but the FKs didn't
50
- // follow" failure mode that motivated #1915 and #1916.
51
- //
52
- // Two halves:
53
- //
54
- // 1. Declared FKs: walk model files, look at `belongsTo`, compute
55
- // the implied FK shape `{ fromTable, fromColumn, toTable,
56
- // toColumn }`. Convention is `<related>_id` → `<related>.id`,
57
- // same as the migration generator.
58
- //
59
- // 2. Live FKs: query the live database. SQLite via
60
- // `PRAGMA foreign_key_list("…")`, MySQL/Postgres via
61
- // `information_schema.key_column_usage`.
62
- export declare interface DeclaredFK {
63
- fromTable: string
64
- fromColumn: string
65
- toTable: string
66
- toColumn: string
67
- model: string
68
- }
69
- export declare interface LiveFK {
70
- fromTable: string
71
- fromColumn: string
72
- toTable: string
73
- toColumn: string
74
- }
75
- export declare interface FkAuditResult {
76
- declared: DeclaredFK[]
77
- live: LiveFK[]
78
- missing: DeclaredFK[]
79
- }
80
- // stacksjs/stacks#1951 — FK orphan detection. FK enforcement flipped
81
- // ON (utils.ts bootstrap pragmas) against databases that were written
82
- // while `foreign_keys = OFF`, so legacy rows can reference parents that
83
- // no longer exist. Those orphans silently turn previously-working
84
- // deletes/inserts into runtime FK failures. This READ-ONLY scan finds
85
- // them so `buddy doctor` can report before they bite.
86
- //
87
- // SQLite-specific: MySQL/Postgres enforce FKs natively, so the
88
- // FK-off-legacy-data failure mode can't arise there — we degrade to
89
- // `supported: false` rather than run an expensive per-FK anti-join.
90
- export declare interface FkOrphan {
91
- table: string
92
- column: string
93
- parent: string
94
- count: number
95
- sampleRowids: number[]
96
- }
97
- export declare interface FkOrphanReport {
98
- supported: boolean
99
- total: number
100
- orphans: FkOrphan[]
101
- }
package/dist/index.d.ts DELETED
@@ -1,149 +0,0 @@
1
- export type {
2
- DatabaseConnectionConfig,
3
- DatabaseOptions,
4
- } from './database';
5
- export type {
6
- DatabaseConnections,
7
- DynamoDbConfig,
8
- FullDatabaseConfig,
9
- MysqlConfig,
10
- PostgresConfig,
11
- SqliteConfig,
12
- } from './driver-config';
13
- export type { GenerateOptions } from './factory';
14
- export type { ScaffoldOptions, ScaffoldResult } from './seed-scaffold';
15
- export type { DeclaredFK, FkAuditResult, FkOrphan, FkOrphanReport, LiveFK } from './fk-audit';
16
- export type { DeclaredUnique, LiveUniqueIndex, UniqueAuditResult } from './unique-audit';
17
- export type {
18
- QueryBuilder,
19
- QueryBuilderConfig,
20
- Seeder as QueryBuilderSeeder,
21
- SupportedDialect,
22
- } from '@stacksjs/query-builder';
23
- export type {
24
- DynamoConnectionConfig,
25
- SingleTableEntityMapping,
26
- SortKeyBuilder,
27
- BatchWriteOperation,
28
- TransactWriteOperation,
29
- QueryResult,
30
- } from './drivers/dynamodb';
31
- /**
32
- * @stacksjs/database
33
- *
34
- * Database module powered by bun-query-builder.
35
- * Provides database initialization, driver configuration, migrations,
36
- * seeding, and a fluent query builder interface.
37
- *
38
- * @example
39
- * ```ts
40
- * import { Database, db, createSqliteDatabase } from '@stacksjs/database'
41
- *
42
- * // Use the default db instance (configured from environment)
43
- * const users = await db.selectFrom('users').where('active', '=', true).get()
44
- *
45
- * // Or create a custom database instance
46
- * const customDb = new Database({
47
- * driver: 'postgres',
48
- * connection: {
49
- * database: 'myapp',
50
- * host: 'localhost',
51
- * port: 5432,
52
- * username: 'postgres',
53
- * password: 'secret'
54
- * }
55
- * })
56
- *
57
- * // Helper functions for quick setup
58
- * const sqliteDb = createSqliteDatabase('database/app.sqlite')
59
- * ```
60
- */
61
- // Database initialization and management
62
- export {
63
- Database,
64
- createDatabase,
65
- createMysqlDatabase,
66
- createPostgresDatabase,
67
- createSqliteDatabase,
68
- } from './database';
69
- // Driver configuration
70
- export {
71
- detectDriver,
72
- driverDefaults,
73
- getConfigFromEnv,
74
- getConnectionString,
75
- mergeWithDefaults,
76
- validateDriverConfig,
77
- } from './driver-config';
78
- // Core database utilities and default instance
79
- export * from './utils';
80
- // Types (compatibility layer for Kysely types)
81
- export * from './types';
82
- // Migrations
83
- export * from './migrations';
84
- // Query logger DI hook (router calls setQueryTracker on init)
85
- export { setQueryTracker, logQuery } from './query-logger';
86
- // Class-based seeders (supplements the model-attribute auto-seeder)
87
- export { Seeder, runClassSeeders } from './class-seeder';
88
- // Zero-downtime migration helpers
89
- export { addColumnSafely, backfillInBatches, renameColumnSafely } from './safe-migrations';
90
- // Seeding
91
- export * from './seeder';
92
- // stacksjs/stacks#1919 — public factory API. The canonical replacement
93
- // for the legacy `useSeeder` trait + auto-walker. Class seeders call
94
- // `factory.generate(Model, opts)` explicitly so there's one
95
- // orchestration layer per table, no double-fire on tables that have
96
- // both a `useSeeder` trait and a class seeder file.
97
- export { factory, generate as factoryGenerate } from './factory';
98
- // `buddy seed:scaffold` codemod — generates class-seeder files for
99
- // every model with a `useSeeder` trait, easing the migration off the
100
- // auto-walker.
101
- export { scaffoldClassSeedersFromModels, renderSeederFile } from './seed-scaffold';
102
- // Driver utilities
103
- export * from './drivers/index';
104
- // Custom migrations (jobs, errors, etc.)
105
- export * from './custom/index';
106
- // Auth tables migration
107
- export * from './auth-tables';
108
- // uuid column guarantee for `useUuid` models (stacksjs/status#1 Phase 9)
109
- export * from './uuid-columns';
110
- // Notification tables migration (stacksjs/stacks#1937)
111
- export { migrateNotificationTables } from './notification-tables';
112
- // RBAC tables migration (stacksjs/stacks#1941 Phase A)
113
- export { migrateRbacTables } from './rbac-tables';
114
- // SQL dialect helpers & connection defaults
115
- export * from './sql-helpers';
116
- export * from './defaults';
117
- // Foreign-key audit (stacksjs/stacks#1916) — compare declared
118
- // `belongsTo` relationships against live FKs.
119
- export { auditForeignKeys, findFkOrphans, getDeclaredFKs, getLiveFKs } from './fk-audit';
120
- // Unique-index drift audit (stacksjs/stacks#1952) — compare declared
121
- // `unique: true` attributes / indexes against live UNIQUE indexes.
122
- export { auditUniqueIndexes, getDeclaredUniques, getLiveUniqueIndexes } from './unique-audit';
123
- // Transaction context: AsyncLocalStorage-based scope so side-effect
124
- // emitters (queue dispatch, mailer send) can buffer themselves
125
- // until the surrounding `db.transaction(...)` commits
126
- // (stacksjs/stacks#1882).
127
- export {
128
- __flushAfterCommitNow,
129
- __pendingAfterCommitCount,
130
- enqueueAfterCommit,
131
- isInTransaction,
132
- runInTransactionScope,
133
- } from './transaction-context';
134
- // Re-export bun-query-builder functions and types
135
- export {
136
- createQueryBuilder,
137
- setConfig,
138
- } from '@stacksjs/query-builder';
139
- // DynamoDB entity-centric API
140
- export {
141
- createDynamo,
142
- dynamo,
143
- EntityQueryBuilder,
144
- generateKeyPattern,
145
- parseKeyPattern,
146
- buildKey,
147
- marshall,
148
- unmarshall,
149
- } from './drivers/dynamodb';