alepha 0.14.4 → 0.15.0
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.
- package/README.md +1 -4
- package/dist/api/audits/index.d.ts +619 -731
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/files/index.d.ts +185 -298
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +0 -1
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.d.ts +245 -356
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/notifications/index.d.ts +238 -350
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/parameters/index.d.ts +499 -611
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/users/index.browser.js +1 -2
- package/dist/api/users/index.browser.js.map +1 -1
- package/dist/api/users/index.d.ts +1697 -1804
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +178 -151
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.d.ts +132 -132
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/batch/index.d.ts +122 -122
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js +1 -2
- package/dist/batch/index.js.map +1 -1
- package/dist/bucket/index.d.ts +163 -163
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/cache/core/index.d.ts +46 -46
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cli/index.d.ts +302 -299
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +966 -564
- package/dist/cli/index.js.map +1 -1
- package/dist/command/index.d.ts +303 -299
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +11 -7
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js +419 -99
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +718 -625
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +420 -99
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +419 -99
- package/dist/core/index.native.js.map +1 -1
- package/dist/datetime/index.d.ts +44 -44
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/datetime/index.js +4 -4
- package/dist/datetime/index.js.map +1 -1
- package/dist/email/index.d.ts +97 -50
- package/dist/email/index.d.ts.map +1 -1
- package/dist/email/index.js +129 -33
- package/dist/email/index.js.map +1 -1
- package/dist/fake/index.d.ts +7981 -14
- package/dist/fake/index.d.ts.map +1 -1
- package/dist/file/index.d.ts +523 -390
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js +253 -1
- package/dist/file/index.js.map +1 -1
- package/dist/lock/core/index.d.ts +208 -208
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/redis/index.d.ts.map +1 -1
- package/dist/logger/index.d.ts +25 -26
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +197 -197
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/orm/chunk-DtkW-qnP.js +38 -0
- package/dist/orm/index.browser.js.map +1 -1
- package/dist/orm/index.bun.js +2814 -0
- package/dist/orm/index.bun.js.map +1 -0
- package/dist/orm/index.d.ts +1205 -1057
- package/dist/orm/index.d.ts.map +1 -1
- package/dist/orm/index.js +2056 -1753
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +248 -248
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/redis/index.bun.js +285 -0
- package/dist/redis/index.bun.js.map +1 -0
- package/dist/redis/index.d.ts +118 -136
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +18 -38
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.d.ts +69 -69
- package/dist/retry/index.d.ts.map +1 -1
- package/dist/router/index.d.ts +6 -6
- package/dist/router/index.d.ts.map +1 -1
- package/dist/scheduler/index.d.ts +25 -25
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/security/index.browser.js +5 -1
- package/dist/security/index.browser.js.map +1 -1
- package/dist/security/index.d.ts +417 -254
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +386 -86
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +277 -277
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +20 -20
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cache/index.d.ts +60 -57
- package/dist/server/cache/index.d.ts.map +1 -1
- package/dist/server/cache/index.js +1 -1
- package/dist/server/cache/index.js.map +1 -1
- package/dist/server/compress/index.d.ts +3 -3
- package/dist/server/compress/index.d.ts.map +1 -1
- package/dist/server/cookies/index.d.ts +6 -6
- package/dist/server/cookies/index.d.ts.map +1 -1
- package/dist/server/cookies/index.js +3 -3
- package/dist/server/cookies/index.js.map +1 -1
- package/dist/server/core/index.d.ts +242 -150
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js +288 -122
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +11 -12
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/health/index.d.ts +0 -1
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/helmet/index.d.ts +2 -2
- package/dist/server/helmet/index.d.ts.map +1 -1
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +84 -85
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +1 -2
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.d.ts.map +1 -1
- package/dist/server/multipart/index.d.ts +6 -6
- package/dist/server/multipart/index.d.ts.map +1 -1
- package/dist/server/proxy/index.d.ts +102 -103
- package/dist/server/proxy/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.d.ts +16 -16
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/static/index.d.ts +44 -44
- package/dist/server/static/index.d.ts.map +1 -1
- package/dist/server/swagger/index.d.ts +48 -49
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js +1 -2
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/sms/index.d.ts +13 -11
- package/dist/sms/index.d.ts.map +1 -1
- package/dist/sms/index.js +7 -7
- package/dist/sms/index.js.map +1 -1
- package/dist/thread/index.d.ts +71 -72
- package/dist/thread/index.d.ts.map +1 -1
- package/dist/topic/core/index.d.ts +318 -318
- package/dist/topic/core/index.d.ts.map +1 -1
- package/dist/topic/redis/index.d.ts +6 -6
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/dist/vite/index.d.ts +5720 -159
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +41 -18
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.browser.js +6 -6
- package/dist/websocket/index.browser.js.map +1 -1
- package/dist/websocket/index.d.ts +247 -247
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +6 -6
- package/dist/websocket/index.js.map +1 -1
- package/package.json +9 -14
- package/src/api/files/controllers/AdminFileStatsController.ts +0 -1
- package/src/api/users/atoms/realmAuthSettingsAtom.ts +5 -0
- package/src/api/users/controllers/{UserRealmController.ts → RealmController.ts} +11 -11
- package/src/api/users/entities/users.ts +1 -1
- package/src/api/users/index.ts +8 -8
- package/src/api/users/primitives/{$userRealm.ts → $realm.ts} +17 -19
- package/src/api/users/providers/{UserRealmProvider.ts → RealmProvider.ts} +26 -30
- package/src/api/users/schemas/{userRealmConfigSchema.ts → realmConfigSchema.ts} +2 -2
- package/src/api/users/services/CredentialService.ts +7 -7
- package/src/api/users/services/IdentityService.ts +4 -4
- package/src/api/users/services/RegistrationService.spec.ts +25 -27
- package/src/api/users/services/RegistrationService.ts +38 -27
- package/src/api/users/services/SessionCrudService.ts +3 -3
- package/src/api/users/services/SessionService.spec.ts +3 -3
- package/src/api/users/services/SessionService.ts +28 -9
- package/src/api/users/services/UserService.ts +7 -7
- package/src/batch/providers/BatchProvider.ts +1 -2
- package/src/cli/apps/AlephaPackageBuilderCli.ts +38 -19
- package/src/cli/assets/apiHelloControllerTs.ts +18 -0
- package/src/cli/assets/apiIndexTs.ts +16 -0
- package/src/cli/assets/claudeMd.ts +303 -0
- package/src/cli/assets/mainBrowserTs.ts +2 -2
- package/src/cli/assets/mainServerTs.ts +24 -0
- package/src/cli/assets/webAppRouterTs.ts +15 -0
- package/src/cli/assets/webHelloComponentTsx.ts +16 -0
- package/src/cli/assets/webIndexTs.ts +16 -0
- package/src/cli/commands/build.ts +41 -21
- package/src/cli/commands/db.ts +21 -18
- package/src/cli/commands/deploy.ts +17 -5
- package/src/cli/commands/dev.ts +13 -17
- package/src/cli/commands/format.ts +8 -2
- package/src/cli/commands/init.ts +74 -29
- package/src/cli/commands/lint.ts +8 -2
- package/src/cli/commands/test.ts +8 -2
- package/src/cli/commands/typecheck.ts +5 -1
- package/src/cli/commands/verify.ts +4 -2
- package/src/cli/services/AlephaCliUtils.ts +39 -600
- package/src/cli/services/PackageManagerUtils.ts +301 -0
- package/src/cli/services/ProjectScaffolder.ts +306 -0
- package/src/command/helpers/Runner.ts +15 -3
- package/src/core/__tests__/Alepha-graph.spec.ts +4 -0
- package/src/core/index.shared.ts +1 -0
- package/src/core/index.ts +2 -0
- package/src/core/primitives/$hook.ts +6 -2
- package/src/core/primitives/$module.spec.ts +4 -0
- package/src/core/providers/AlsProvider.ts +1 -1
- package/src/core/providers/CodecManager.spec.ts +12 -6
- package/src/core/providers/CodecManager.ts +26 -6
- package/src/core/providers/EventManager.ts +169 -13
- package/src/core/providers/KeylessJsonSchemaCodec.spec.ts +621 -0
- package/src/core/providers/KeylessJsonSchemaCodec.ts +407 -0
- package/src/core/providers/StateManager.spec.ts +27 -16
- package/src/email/providers/LocalEmailProvider.spec.ts +111 -87
- package/src/email/providers/LocalEmailProvider.ts +52 -15
- package/src/email/providers/NodemailerEmailProvider.ts +167 -56
- package/src/file/errors/FileError.ts +7 -0
- package/src/file/index.ts +9 -1
- package/src/file/providers/MemoryFileSystemProvider.ts +393 -0
- package/src/orm/index.browser.ts +1 -19
- package/src/orm/index.bun.ts +77 -0
- package/src/orm/index.shared-server.ts +22 -0
- package/src/orm/index.shared.ts +15 -0
- package/src/orm/index.ts +19 -39
- package/src/orm/providers/drivers/BunPostgresProvider.ts +3 -5
- package/src/orm/providers/drivers/BunSqliteProvider.ts +1 -1
- package/src/orm/providers/drivers/CloudflareD1Provider.ts +4 -0
- package/src/orm/providers/drivers/DatabaseProvider.ts +4 -0
- package/src/orm/providers/drivers/PglitePostgresProvider.ts +4 -0
- package/src/orm/services/Repository.ts +8 -0
- package/src/redis/index.bun.ts +35 -0
- package/src/redis/providers/BunRedisProvider.ts +12 -43
- package/src/redis/providers/BunRedisSubscriberProvider.ts +2 -3
- package/src/redis/providers/NodeRedisProvider.ts +16 -34
- package/src/{server/security → security}/__tests__/BasicAuth.spec.ts +11 -11
- package/src/{server/security → security}/__tests__/ServerSecurityProvider-realm.spec.ts +21 -16
- package/src/{server/security/providers → security/__tests__}/ServerSecurityProvider.spec.ts +5 -5
- package/src/security/index.browser.ts +5 -0
- package/src/security/index.ts +90 -7
- package/src/security/primitives/{$realm.spec.ts → $issuer.spec.ts} +11 -11
- package/src/security/primitives/{$realm.ts → $issuer.ts} +20 -17
- package/src/security/primitives/$role.ts +5 -5
- package/src/security/primitives/$serviceAccount.spec.ts +5 -5
- package/src/security/primitives/$serviceAccount.ts +3 -3
- package/src/{server/security → security}/providers/ServerSecurityProvider.ts +5 -7
- package/src/server/auth/primitives/$auth.ts +10 -10
- package/src/server/auth/primitives/$authCredentials.ts +3 -3
- package/src/server/auth/primitives/$authGithub.ts +3 -3
- package/src/server/auth/primitives/$authGoogle.ts +3 -3
- package/src/server/auth/providers/ServerAuthProvider.ts +13 -13
- package/src/server/cache/providers/ServerCacheProvider.ts +1 -1
- package/src/server/cookies/providers/ServerCookiesProvider.ts +3 -3
- package/src/server/core/providers/NodeHttpServerProvider.ts +25 -6
- package/src/server/core/providers/ServerBodyParserProvider.ts +19 -23
- package/src/server/core/providers/ServerLoggerProvider.ts +23 -19
- package/src/server/core/providers/ServerProvider.ts +144 -21
- package/src/server/core/providers/ServerRouterProvider.ts +259 -115
- package/src/server/core/providers/ServerTimingProvider.ts +2 -2
- package/src/server/links/index.ts +1 -1
- package/src/server/links/providers/LinkProvider.ts +1 -1
- package/src/server/swagger/index.ts +1 -1
- package/src/sms/providers/LocalSmsProvider.spec.ts +153 -111
- package/src/sms/providers/LocalSmsProvider.ts +8 -7
- package/src/vite/helpers/boot.ts +28 -17
- package/src/vite/tasks/buildServer.ts +12 -1
- package/src/vite/tasks/devServer.ts +3 -1
- package/src/vite/tasks/generateCloudflare.ts +7 -0
- package/dist/server/security/index.browser.js +0 -13
- package/dist/server/security/index.browser.js.map +0 -1
- package/dist/server/security/index.d.ts +0 -173
- package/dist/server/security/index.d.ts.map +0 -1
- package/dist/server/security/index.js +0 -311
- package/dist/server/security/index.js.map +0 -1
- package/src/cli/assets/appRouterTs.ts +0 -9
- package/src/cli/assets/mainTs.ts +0 -13
- package/src/server/security/index.browser.ts +0 -10
- package/src/server/security/index.ts +0 -94
- /package/src/{server/security → security}/primitives/$basicAuth.ts +0 -0
- /package/src/{server/security → security}/providers/ServerBasicAuthProvider.ts +0 -0
package/dist/orm/index.d.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { n as __reExport, t as __exportAll } from "./chunk-DtkW-qnP.js";
|
|
2
|
+
import * as alepha34 from "alepha";
|
|
2
3
|
import { Alepha, AlephaError, KIND, Page, Page as Page$1, PageQuery, PageQuery as PageQuery$1, Primitive, Service, Static, StaticEncode, TBigInt, TInteger, TNull, TNumber, TNumberOptions, TObject, TObjectOptions, TOptional, TPage, TSchema, TString, TStringOptions, TUnion, TUnsafe, pageQuerySchema, pageSchema } from "alepha";
|
|
3
4
|
import { DateTime, DateTimeProvider } from "alepha/datetime";
|
|
4
|
-
import * as drizzle_orm0 from "drizzle-orm";
|
|
5
|
-
import { BuildColumns, BuildExtraConfigColumns, SQL, SQLWrapper, sql } from "drizzle-orm";
|
|
6
5
|
import * as drizzle_orm_pg_core0 from "drizzle-orm/pg-core";
|
|
7
6
|
import { LockConfig, LockStrength, PgColumn, PgColumnBuilderBase, PgDatabase, PgInsertValue, PgSchema, PgSelectBase, PgSequenceOptions, PgTableExtraConfigValue, PgTableWithColumns, PgTransaction, UpdateDeleteAction } from "drizzle-orm/pg-core";
|
|
8
|
-
import * as
|
|
7
|
+
import * as drizzle_orm0 from "drizzle-orm";
|
|
8
|
+
import { BuildColumns, BuildExtraConfigColumns, SQL, SQLWrapper, sql } from "drizzle-orm";
|
|
9
|
+
import * as alepha_logger3 from "alepha/logger";
|
|
10
|
+
import * as alepha_lock0 from "alepha/lock";
|
|
9
11
|
import * as pg$1 from "drizzle-orm/sqlite-core";
|
|
10
12
|
import { SQLiteColumnBuilderBase } from "drizzle-orm/sqlite-core";
|
|
11
|
-
import * as alepha_lock0 from "alepha/lock";
|
|
12
13
|
import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
13
14
|
import postgres from "postgres";
|
|
14
15
|
import * as alepha_retry0 from "alepha/retry";
|
|
16
|
+
import { Database } from "bun:sqlite";
|
|
17
|
+
import { BunSQLDatabase } from "drizzle-orm/bun-sql";
|
|
18
|
+
import { BunSQLiteDatabase } from "drizzle-orm/bun-sqlite";
|
|
15
19
|
import { DrizzleD1Database } from "drizzle-orm/d1";
|
|
16
20
|
import { DatabaseSync } from "node:sqlite";
|
|
21
|
+
import { UpdateDeleteAction as UpdateDeleteAction$1 } from "drizzle-orm/pg-core/foreign-keys";
|
|
17
22
|
import { PgTransactionConfig } from "drizzle-orm/pg-core/session";
|
|
18
23
|
import * as DrizzleKit from "drizzle-kit/api";
|
|
19
|
-
import { UpdateDeleteAction as UpdateDeleteAction$1 } from "drizzle-orm/pg-core/foreign-keys";
|
|
20
24
|
import * as typebox1 from "typebox";
|
|
21
25
|
export * from "drizzle-orm/pg-core";
|
|
22
26
|
|
|
@@ -74,114 +78,114 @@ declare const $entity: {
|
|
|
74
78
|
};
|
|
75
79
|
interface EntityPrimitiveOptions<T extends TObject, Keys = keyof Static<T>> {
|
|
76
80
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
* The database table name that will be created for this entity.
|
|
82
|
+
* If not provided, name will be inferred from the $repository variable name.
|
|
83
|
+
*/
|
|
80
84
|
name: string;
|
|
81
85
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
* TypeBox schema defining the table structure and column types.
|
|
87
|
+
*/
|
|
84
88
|
schema: T;
|
|
85
89
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
* Database indexes to create for query optimization.
|
|
91
|
+
*/
|
|
88
92
|
indexes?: (Keys | {
|
|
89
93
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
* Single column to index.
|
|
95
|
+
*/
|
|
92
96
|
column: Keys;
|
|
93
97
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
* Whether this should be a unique index (enforces uniqueness constraint).
|
|
99
|
+
*/
|
|
96
100
|
unique?: boolean;
|
|
97
101
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
* Custom name for the index. If not provided, generates name automatically.
|
|
103
|
+
*/
|
|
100
104
|
name?: string;
|
|
101
105
|
} | {
|
|
102
106
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
* Multiple columns for composite index (order matters for query optimization).
|
|
108
|
+
*/
|
|
105
109
|
columns: Keys[];
|
|
106
110
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
* Whether this should be a unique index (enforces uniqueness constraint).
|
|
112
|
+
*/
|
|
109
113
|
unique?: boolean;
|
|
110
114
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
* Custom name for the index. If not provided, generates name automatically.
|
|
116
|
+
*/
|
|
113
117
|
name?: string;
|
|
114
118
|
})[];
|
|
115
119
|
/**
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
* Foreign key constraints to maintain referential integrity.
|
|
121
|
+
*/
|
|
118
122
|
foreignKeys?: Array<{
|
|
119
123
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
* Optional name for the foreign key constraint.
|
|
125
|
+
*/
|
|
122
126
|
name?: string;
|
|
123
127
|
/**
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
* Local columns that reference the foreign table.
|
|
129
|
+
*/
|
|
126
130
|
columns: Array<keyof Static<T>>;
|
|
127
131
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
* Referenced columns in the foreign table.
|
|
133
|
+
* Must be EntityColumn references from other entities.
|
|
134
|
+
*/
|
|
131
135
|
foreignColumns: Array<() => EntityColumn<any>>;
|
|
132
136
|
}>;
|
|
133
137
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
138
|
+
* Additional table constraints for data validation.
|
|
139
|
+
*
|
|
140
|
+
* Constraints enforce business rules at the database level, providing
|
|
141
|
+
* an additional layer of data integrity beyond application validation.
|
|
142
|
+
*
|
|
143
|
+
* **Constraint Types**:
|
|
144
|
+
* - **Unique constraints**: Prevent duplicate values across columns
|
|
145
|
+
* - **Check constraints**: Enforce custom validation rules with SQL expressions
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* constraints: [
|
|
150
|
+
* {
|
|
151
|
+
* name: "unique_user_email",
|
|
152
|
+
* columns: ["email"],
|
|
153
|
+
* unique: true
|
|
154
|
+
* },
|
|
155
|
+
* {
|
|
156
|
+
* name: "valid_age_range",
|
|
157
|
+
* columns: ["age"],
|
|
158
|
+
* check: sql`age >= 0 AND age <= 150`
|
|
159
|
+
* },
|
|
160
|
+
* {
|
|
161
|
+
* name: "unique_user_username_per_tenant",
|
|
162
|
+
* columns: ["tenantId", "username"],
|
|
163
|
+
* unique: true
|
|
164
|
+
* }
|
|
165
|
+
* ]
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
164
168
|
constraints?: Array<{
|
|
165
169
|
/**
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
* Columns involved in this constraint.
|
|
171
|
+
*/
|
|
168
172
|
columns: Array<keyof Static<T>>;
|
|
169
173
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
174
|
+
* Optional name for the constraint.
|
|
175
|
+
*/
|
|
172
176
|
name?: string;
|
|
173
177
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
178
|
+
* Whether this is a unique constraint.
|
|
179
|
+
*/
|
|
176
180
|
unique?: boolean | {};
|
|
177
181
|
/**
|
|
178
|
-
|
|
179
|
-
|
|
182
|
+
* SQL expression for check constraint validation.
|
|
183
|
+
*/
|
|
180
184
|
check?: SQL;
|
|
181
185
|
}>;
|
|
182
186
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
* Advanced Drizzle ORM configuration for complex table setups.
|
|
188
|
+
*/
|
|
185
189
|
config?: (self: BuildExtraConfigColumns<string, FromSchema<T>, "pg">) => PgTableExtraConfigValue[];
|
|
186
190
|
}
|
|
187
191
|
declare class EntityPrimitive<T extends TObject = TObject> {
|
|
@@ -238,8 +242,8 @@ type PgSymbols = {
|
|
|
238
242
|
[PG_REF]: PgRefOptions;
|
|
239
243
|
[PG_ENUM]: PgEnumOptions;
|
|
240
244
|
/**
|
|
241
|
-
|
|
242
|
-
|
|
245
|
+
* @deprecated Use `PG_IDENTITY` instead.
|
|
246
|
+
*/
|
|
243
247
|
[PG_SERIAL]: {};
|
|
244
248
|
};
|
|
245
249
|
type PgSymbolKeys = keyof PgSymbols;
|
|
@@ -275,13 +279,6 @@ declare class DbConflictError extends DbError {
|
|
|
275
279
|
readonly status = 409;
|
|
276
280
|
}
|
|
277
281
|
//#endregion
|
|
278
|
-
//#region ../../src/orm/errors/DbEntityNotFoundError.d.ts
|
|
279
|
-
declare class DbEntityNotFoundError extends DbError {
|
|
280
|
-
readonly name = "DbEntityNotFoundError";
|
|
281
|
-
readonly status = 404;
|
|
282
|
-
constructor(entityName: string);
|
|
283
|
-
}
|
|
284
|
-
//#endregion
|
|
285
282
|
//#region ../../src/orm/errors/DbMigrationError.d.ts
|
|
286
283
|
declare class DbMigrationError extends DbError {
|
|
287
284
|
readonly name = "DbMigrationError";
|
|
@@ -299,419 +296,426 @@ declare class DbVersionMismatchError extends DbError {
|
|
|
299
296
|
constructor(table: string, id: any);
|
|
300
297
|
}
|
|
301
298
|
//#endregion
|
|
299
|
+
//#region ../../src/orm/errors/DbEntityNotFoundError.d.ts
|
|
300
|
+
declare class DbEntityNotFoundError extends DbError {
|
|
301
|
+
readonly name = "DbEntityNotFoundError";
|
|
302
|
+
readonly status = 404;
|
|
303
|
+
constructor(entityName: string);
|
|
304
|
+
}
|
|
305
|
+
//#endregion
|
|
302
306
|
//#region ../../src/orm/interfaces/FilterOperators.d.ts
|
|
303
307
|
interface FilterOperators<TValue> {
|
|
304
308
|
/**
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
309
|
+
* Test that two values are equal.
|
|
310
|
+
*
|
|
311
|
+
* Remember that the SQL standard dictates that
|
|
312
|
+
* two NULL values are not equal, so if you want to test
|
|
313
|
+
* whether a value is null, you may want to use
|
|
314
|
+
* `isNull` instead.
|
|
315
|
+
*
|
|
316
|
+
* ## Examples
|
|
317
|
+
*
|
|
318
|
+
* ```ts
|
|
319
|
+
* // Select cars made by Ford
|
|
320
|
+
* db.select().from(cars)
|
|
321
|
+
* .where(eq(cars.make, 'Ford'))
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @see isNull for a way to test equality to NULL.
|
|
325
|
+
*/
|
|
322
326
|
eq?: TValue;
|
|
323
327
|
/**
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
328
|
+
* Test that two values are not equal.
|
|
329
|
+
*
|
|
330
|
+
* Remember that the SQL standard dictates that
|
|
331
|
+
* two NULL values are not equal, so if you want to test
|
|
332
|
+
* whether a value is not null, you may want to use
|
|
333
|
+
* `isNotNull` instead.
|
|
334
|
+
*
|
|
335
|
+
* ## Examples
|
|
336
|
+
*
|
|
337
|
+
* ```ts
|
|
338
|
+
* // Select cars not made by Ford
|
|
339
|
+
* db.select().from(cars)
|
|
340
|
+
* .where(ne(cars.make, 'Ford'))
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
343
|
+
* @see isNotNull for a way to test whether a value is not null.
|
|
344
|
+
*/
|
|
341
345
|
ne?: TValue;
|
|
342
346
|
/**
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
347
|
+
* Test that the first expression passed is greater than
|
|
348
|
+
* the second expression.
|
|
349
|
+
*
|
|
350
|
+
* ## Examples
|
|
351
|
+
*
|
|
352
|
+
* ```ts
|
|
353
|
+
* // Select cars made after 2000.
|
|
354
|
+
* db.select().from(cars)
|
|
355
|
+
* .where(gt(cars.year, 2000))
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* @see gte for greater-than-or-equal
|
|
359
|
+
*/
|
|
356
360
|
gt?: TValue;
|
|
357
361
|
/**
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
362
|
+
* Test that the first expression passed is greater than
|
|
363
|
+
* or equal to the second expression. Use `gt` to
|
|
364
|
+
* test whether an expression is strictly greater
|
|
365
|
+
* than another.
|
|
366
|
+
*
|
|
367
|
+
* ## Examples
|
|
368
|
+
*
|
|
369
|
+
* ```ts
|
|
370
|
+
* // Select cars made on or after 2000.
|
|
371
|
+
* db.select().from(cars)
|
|
372
|
+
* .where(gte(cars.year, 2000))
|
|
373
|
+
* ```
|
|
374
|
+
*
|
|
375
|
+
* @see gt for a strictly greater-than condition
|
|
376
|
+
*/
|
|
373
377
|
gte?: TValue;
|
|
374
378
|
/**
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
379
|
+
* Test that the first expression passed is less than
|
|
380
|
+
* the second expression.
|
|
381
|
+
*
|
|
382
|
+
* ## Examples
|
|
383
|
+
*
|
|
384
|
+
* ```ts
|
|
385
|
+
* // Select cars made before 2000.
|
|
386
|
+
* db.select().from(cars)
|
|
387
|
+
* .where(lt(cars.year, 2000))
|
|
388
|
+
* ```
|
|
389
|
+
*
|
|
390
|
+
* @see lte for greater-than-or-equal
|
|
391
|
+
*/
|
|
388
392
|
lt?: TValue;
|
|
389
393
|
/**
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
394
|
+
* Test that the first expression passed is less than
|
|
395
|
+
* or equal to the second expression.
|
|
396
|
+
*
|
|
397
|
+
* ## Examples
|
|
398
|
+
*
|
|
399
|
+
* ```ts
|
|
400
|
+
* // Select cars made before 2000.
|
|
401
|
+
* db.select().from(cars)
|
|
402
|
+
* .where(lte(cars.year, 2000))
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
405
|
+
* @see lt for a strictly less-than condition
|
|
406
|
+
*/
|
|
403
407
|
lte?: TValue;
|
|
404
408
|
/**
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
409
|
+
* Test whether the first parameter, a column or expression,
|
|
410
|
+
* has a value from a list passed as the second argument.
|
|
411
|
+
*
|
|
412
|
+
* ## Throws
|
|
413
|
+
*
|
|
414
|
+
* The argument passed in the second array can't be empty:
|
|
415
|
+
* if an empty is provided, this method will throw.
|
|
416
|
+
*
|
|
417
|
+
* ## Examples
|
|
418
|
+
*
|
|
419
|
+
* ```ts
|
|
420
|
+
* // Select cars made by Ford or GM.
|
|
421
|
+
* db.select().from(cars)
|
|
422
|
+
* .where(inArray(cars.make, ['Ford', 'GM']))
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* @see notInArray for the inverse of this test
|
|
426
|
+
*/
|
|
423
427
|
inArray?: TValue[];
|
|
424
428
|
/**
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
429
|
+
* Test whether the first parameter, a column or expression,
|
|
430
|
+
* has a value that is not present in a list passed as the
|
|
431
|
+
* second argument.
|
|
432
|
+
*
|
|
433
|
+
* ## Throws
|
|
434
|
+
*
|
|
435
|
+
* The argument passed in the second array can't be empty:
|
|
436
|
+
* if an empty is provided, this method will throw.
|
|
437
|
+
*
|
|
438
|
+
* ## Examples
|
|
439
|
+
*
|
|
440
|
+
* ```ts
|
|
441
|
+
* // Select cars made by any company except Ford or GM.
|
|
442
|
+
* db.select().from(cars)
|
|
443
|
+
* .where(notInArray(cars.make, ['Ford', 'GM']))
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
446
|
+
* @see inArray for the inverse of this test
|
|
447
|
+
*/
|
|
444
448
|
notInArray?: TValue[];
|
|
445
449
|
/**
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
450
|
+
* Test whether an expression is not NULL. By the SQL standard,
|
|
451
|
+
* NULL is neither equal nor not equal to itself, so
|
|
452
|
+
* it's recommended to use `isNull` and `notIsNull` for
|
|
453
|
+
* comparisons to NULL.
|
|
454
|
+
*
|
|
455
|
+
* ## Examples
|
|
456
|
+
*
|
|
457
|
+
* ```ts
|
|
458
|
+
* // Select cars that have been discontinued.
|
|
459
|
+
* db.select().from(cars)
|
|
460
|
+
* .where(isNotNull(cars.discontinuedAt))
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
463
|
+
* @see isNull for the inverse of this test
|
|
464
|
+
*/
|
|
461
465
|
isNotNull?: true;
|
|
462
466
|
/**
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
467
|
+
* Test whether an expression is NULL. By the SQL standard,
|
|
468
|
+
* NULL is neither equal nor not equal to itself, so
|
|
469
|
+
* it's recommended to use `isNull` and `notIsNull` for
|
|
470
|
+
* comparisons to NULL.
|
|
471
|
+
*
|
|
472
|
+
* ## Examples
|
|
473
|
+
*
|
|
474
|
+
* ```ts
|
|
475
|
+
* // Select cars that have no discontinuedAt date.
|
|
476
|
+
* db.select().from(cars)
|
|
477
|
+
* .where(isNull(cars.discontinuedAt))
|
|
478
|
+
* ```
|
|
479
|
+
*
|
|
480
|
+
* @see isNotNull for the inverse of this test
|
|
481
|
+
*/
|
|
478
482
|
isNull?: true;
|
|
479
483
|
/**
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
484
|
+
* Test whether an expression is between two values. This
|
|
485
|
+
* is an easier way to express range tests, which would be
|
|
486
|
+
* expressed mathematically as `x <= a <= y` but in SQL
|
|
487
|
+
* would have to be like `a >= x AND a <= y`.
|
|
488
|
+
*
|
|
489
|
+
* Between is inclusive of the endpoints: if `column`
|
|
490
|
+
* is equal to `min` or `max`, it will be TRUE.
|
|
491
|
+
*
|
|
492
|
+
* ## Examples
|
|
493
|
+
*
|
|
494
|
+
* ```ts
|
|
495
|
+
* // Select cars made between 1990 and 2000
|
|
496
|
+
* db.select().from(cars)
|
|
497
|
+
* .where(between(cars.year, 1990, 2000))
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* @see notBetween for the inverse of this test
|
|
501
|
+
*/
|
|
498
502
|
between?: [number, number];
|
|
499
503
|
/**
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
504
|
+
* Test whether an expression is not between two values.
|
|
505
|
+
*
|
|
506
|
+
* This, like `between`, includes its endpoints, so if
|
|
507
|
+
* the `column` is equal to `min` or `max`, in this case
|
|
508
|
+
* it will evaluate to FALSE.
|
|
509
|
+
*
|
|
510
|
+
* ## Examples
|
|
511
|
+
*
|
|
512
|
+
* ```ts
|
|
513
|
+
* // Exclude cars made in the 1970s
|
|
514
|
+
* db.select().from(cars)
|
|
515
|
+
* .where(notBetween(cars.year, 1970, 1979))
|
|
516
|
+
* ```
|
|
517
|
+
*
|
|
518
|
+
* @see between for the inverse of this test
|
|
519
|
+
*/
|
|
516
520
|
notBetween?: [number, number];
|
|
517
521
|
/**
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
522
|
+
* Compare a column to a pattern, which can include `%` and `_`
|
|
523
|
+
* characters to match multiple variations. Including `%`
|
|
524
|
+
* in the pattern matches zero or more characters, and including
|
|
525
|
+
* `_` will match a single character.
|
|
526
|
+
*
|
|
527
|
+
* ## Examples
|
|
528
|
+
*
|
|
529
|
+
* ```ts
|
|
530
|
+
* // Select all cars with 'Turbo' in their names.
|
|
531
|
+
* db.select().from(cars)
|
|
532
|
+
* .where(like(cars.name, '%Turbo%'))
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @see ilike for a case-insensitive version of this condition
|
|
536
|
+
*/
|
|
533
537
|
like?: string;
|
|
534
538
|
/**
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
539
|
+
* The inverse of like - this tests that a given column
|
|
540
|
+
* does not match a pattern, which can include `%` and `_`
|
|
541
|
+
* characters to match multiple variations. Including `%`
|
|
542
|
+
* in the pattern matches zero or more characters, and including
|
|
543
|
+
* `_` will match a single character.
|
|
544
|
+
*
|
|
545
|
+
* ## Examples
|
|
546
|
+
*
|
|
547
|
+
* ```ts
|
|
548
|
+
* // Select all cars that don't have "ROver" in their name.
|
|
549
|
+
* db.select().from(cars)
|
|
550
|
+
* .where(notLike(cars.name, '%Rover%'))
|
|
551
|
+
* ```
|
|
552
|
+
*
|
|
553
|
+
* @see like for the inverse condition
|
|
554
|
+
* @see notIlike for a case-insensitive version of this condition
|
|
555
|
+
*/
|
|
552
556
|
notLike?: string;
|
|
553
557
|
/**
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
558
|
+
* Case-insensitively compare a column to a pattern,
|
|
559
|
+
* which can include `%` and `_`
|
|
560
|
+
* characters to match multiple variations. Including `%`
|
|
561
|
+
* in the pattern matches zero or more characters, and including
|
|
562
|
+
* `_` will match a single character.
|
|
563
|
+
*
|
|
564
|
+
* Unlike like, this performs a case-insensitive comparison.
|
|
565
|
+
*
|
|
566
|
+
* ## Examples
|
|
567
|
+
*
|
|
568
|
+
* ```ts
|
|
569
|
+
* // Select all cars with 'Turbo' in their names.
|
|
570
|
+
* db.select().from(cars)
|
|
571
|
+
* .where(ilike(cars.name, '%Turbo%'))
|
|
572
|
+
* ```
|
|
573
|
+
*
|
|
574
|
+
* @see like for a case-sensitive version of this condition
|
|
575
|
+
*/
|
|
572
576
|
ilike?: string;
|
|
573
577
|
/**
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
578
|
+
* The inverse of ilike - this case-insensitively tests that a given column
|
|
579
|
+
* does not match a pattern, which can include `%` and `_`
|
|
580
|
+
* characters to match multiple variations. Including `%`
|
|
581
|
+
* in the pattern matches zero or more characters, and including
|
|
582
|
+
* `_` will match a single character.
|
|
583
|
+
*
|
|
584
|
+
* ## Examples
|
|
585
|
+
*
|
|
586
|
+
* ```ts
|
|
587
|
+
* // Select all cars that don't have "Rover" in their name.
|
|
588
|
+
* db.select().from(cars)
|
|
589
|
+
* .where(notLike(cars.name, '%Rover%'))
|
|
590
|
+
* ```
|
|
591
|
+
*
|
|
592
|
+
* @see ilike for the inverse condition
|
|
593
|
+
* @see notLike for a case-sensitive version of this condition
|
|
594
|
+
*/
|
|
591
595
|
notIlike?: string;
|
|
592
596
|
/**
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
597
|
+
* Syntactic sugar for case-insensitive substring matching.
|
|
598
|
+
* Automatically wraps the value with `%` wildcards on both sides.
|
|
599
|
+
*
|
|
600
|
+
* Equivalent to: `ilike: '%value%'`
|
|
601
|
+
*
|
|
602
|
+
* ## Examples
|
|
603
|
+
*
|
|
604
|
+
* ```ts
|
|
605
|
+
* // Select all cars with "Turbo" anywhere in their name.
|
|
606
|
+
* db.select().from(cars)
|
|
607
|
+
* .where({ name: { contains: 'Turbo' } })
|
|
608
|
+
* // Same as: .where(ilike(cars.name, '%Turbo%'))
|
|
609
|
+
* ```
|
|
610
|
+
*
|
|
611
|
+
* @see ilike for manual pattern matching
|
|
612
|
+
* @see startsWith for prefix matching
|
|
613
|
+
* @see endsWith for suffix matching
|
|
614
|
+
*/
|
|
611
615
|
contains?: string;
|
|
612
616
|
/**
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
617
|
+
* Syntactic sugar for case-insensitive prefix matching.
|
|
618
|
+
* Automatically appends a `%` wildcard to the end of the value.
|
|
619
|
+
*
|
|
620
|
+
* Equivalent to: `ilike: 'value%'`
|
|
621
|
+
*
|
|
622
|
+
* ## Examples
|
|
623
|
+
*
|
|
624
|
+
* ```ts
|
|
625
|
+
* // Select all cars whose names start with "Ford".
|
|
626
|
+
* db.select().from(cars)
|
|
627
|
+
* .where({ name: { startsWith: 'Ford' } })
|
|
628
|
+
* // Same as: .where(ilike(cars.name, 'Ford%'))
|
|
629
|
+
* ```
|
|
630
|
+
*
|
|
631
|
+
* @see ilike for manual pattern matching
|
|
632
|
+
* @see contains for substring matching
|
|
633
|
+
* @see endsWith for suffix matching
|
|
634
|
+
*/
|
|
631
635
|
startsWith?: string;
|
|
632
636
|
/**
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
637
|
+
* Syntactic sugar for case-insensitive suffix matching.
|
|
638
|
+
* Automatically prepends a `%` wildcard to the beginning of the value.
|
|
639
|
+
*
|
|
640
|
+
* Equivalent to: `ilike: '%value'`
|
|
641
|
+
*
|
|
642
|
+
* ## Examples
|
|
643
|
+
*
|
|
644
|
+
* ```ts
|
|
645
|
+
* // Select all cars whose names end with "Turbo".
|
|
646
|
+
* db.select().from(cars)
|
|
647
|
+
* .where({ name: { endsWith: 'Turbo' } })
|
|
648
|
+
* // Same as: .where(ilike(cars.name, '%Turbo'))
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* @see ilike for manual pattern matching
|
|
652
|
+
* @see contains for substring matching
|
|
653
|
+
* @see startsWith for prefix matching
|
|
654
|
+
*/
|
|
651
655
|
endsWith?: string;
|
|
652
656
|
/**
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
657
|
+
* Test that a column or expression contains all elements of
|
|
658
|
+
* the list passed as the second argument.
|
|
659
|
+
*
|
|
660
|
+
* ## Throws
|
|
661
|
+
*
|
|
662
|
+
* The argument passed in the second array can't be empty:
|
|
663
|
+
* if an empty is provided, this method will throw.
|
|
664
|
+
*
|
|
665
|
+
* ## Examples
|
|
666
|
+
*
|
|
667
|
+
* ```ts
|
|
668
|
+
* // Select posts where its tags contain "Typescript" and "ORM".
|
|
669
|
+
* db.select().from(posts)
|
|
670
|
+
* .where(arrayContains(posts.tags, ['Typescript', 'ORM']))
|
|
671
|
+
* ```
|
|
672
|
+
*
|
|
673
|
+
* @see arrayContained to find if an array contains all elements of a column or expression
|
|
674
|
+
* @see arrayOverlaps to find if a column or expression contains any elements of an array
|
|
675
|
+
*/
|
|
672
676
|
arrayContains?: TValue;
|
|
673
677
|
/**
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
678
|
+
* Test that the list passed as the second argument contains
|
|
679
|
+
* all elements of a column or expression.
|
|
680
|
+
*
|
|
681
|
+
* ## Throws
|
|
682
|
+
*
|
|
683
|
+
* The argument passed in the second array can't be empty:
|
|
684
|
+
* if an empty is provided, this method will throw.
|
|
685
|
+
*
|
|
686
|
+
* ## Examples
|
|
687
|
+
*
|
|
688
|
+
* ```ts
|
|
689
|
+
* // Select posts where its tags contain "Typescript", "ORM" or both,
|
|
690
|
+
* // but filtering posts that have additional tags.
|
|
691
|
+
* db.select().from(posts)
|
|
692
|
+
* .where(arrayContained(posts.tags, ['Typescript', 'ORM']))
|
|
693
|
+
* ```
|
|
694
|
+
*
|
|
695
|
+
* @see arrayContains to find if a column or expression contains all elements of an array
|
|
696
|
+
* @see arrayOverlaps to find if a column or expression contains any elements of an array
|
|
697
|
+
*/
|
|
694
698
|
arrayContained?: TValue;
|
|
695
699
|
/**
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
700
|
+
* Test that a column or expression contains any elements of
|
|
701
|
+
* the list passed as the second argument.
|
|
702
|
+
*
|
|
703
|
+
* ## Throws
|
|
704
|
+
*
|
|
705
|
+
* The argument passed in the second array can't be empty:
|
|
706
|
+
* if an empty is provided, this method will throw.
|
|
707
|
+
*
|
|
708
|
+
* ## Examples
|
|
709
|
+
*
|
|
710
|
+
* ```ts
|
|
711
|
+
* // Select posts where its tags contain "Typescript", "ORM" or both.
|
|
712
|
+
* db.select().from(posts)
|
|
713
|
+
* .where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']))
|
|
714
|
+
* ```
|
|
715
|
+
*
|
|
716
|
+
* @see arrayContains to find if a column or expression contains all elements of an array
|
|
717
|
+
* @see arrayContained to find if an array contains all elements of a column or expression
|
|
718
|
+
*/
|
|
715
719
|
arrayOverlaps?: TValue;
|
|
716
720
|
}
|
|
717
721
|
//#endregion
|
|
@@ -770,71 +774,71 @@ type PgQueryWhereOrSQL<T extends TObject, Relations extends PgRelationMap<TObjec
|
|
|
770
774
|
type PgQueryWhereOperators<T extends TObject> = { [Key in keyof Static<T>]?: FilterOperators<Static<T>[Key]> | Static<T>[Key] };
|
|
771
775
|
type PgQueryWhereConditions<T extends TObject, Relations extends PgRelationMap<TObject> | undefined = undefined> = {
|
|
772
776
|
/**
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
777
|
+
* Combine a list of conditions with the `and` operator. Conditions
|
|
778
|
+
* that are equal `undefined` are automatically ignored.
|
|
779
|
+
*
|
|
780
|
+
* ## Examples
|
|
781
|
+
*
|
|
782
|
+
* ```ts
|
|
783
|
+
* db.select().from(cars)
|
|
784
|
+
* .where(
|
|
785
|
+
* and(
|
|
786
|
+
* eq(cars.make, 'Volvo'),
|
|
787
|
+
* eq(cars.year, 1950),
|
|
788
|
+
* )
|
|
789
|
+
* )
|
|
790
|
+
* ```
|
|
791
|
+
*/
|
|
788
792
|
and?: Array<PgQueryWhereOrSQL<T, Relations>>;
|
|
789
793
|
/**
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
794
|
+
* Combine a list of conditions with the `or` operator. Conditions
|
|
795
|
+
* that are equal `undefined` are automatically ignored.
|
|
796
|
+
*
|
|
797
|
+
* ## Examples
|
|
798
|
+
*
|
|
799
|
+
* ```ts
|
|
800
|
+
* db.select().from(cars)
|
|
801
|
+
* .where(
|
|
802
|
+
* or(
|
|
803
|
+
* eq(cars.make, 'GM'),
|
|
804
|
+
* eq(cars.make, 'Ford'),
|
|
805
|
+
* )
|
|
806
|
+
* )
|
|
807
|
+
* ```
|
|
808
|
+
*/
|
|
805
809
|
or?: Array<PgQueryWhereOrSQL<T, Relations>>;
|
|
806
810
|
/**
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
811
|
+
* Negate the meaning of an expression using the `not` keyword.
|
|
812
|
+
*
|
|
813
|
+
* ## Examples
|
|
814
|
+
*
|
|
815
|
+
* ```ts
|
|
816
|
+
* // Select cars _not_ made by GM or Ford.
|
|
817
|
+
* db.select().from(cars)
|
|
818
|
+
* .where(not(inArray(cars.make, ['GM', 'Ford'])))
|
|
819
|
+
* ```
|
|
820
|
+
*/
|
|
817
821
|
not?: PgQueryWhereOrSQL<T, Relations>;
|
|
818
822
|
/**
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
823
|
+
* Test whether a subquery evaluates to have any rows.
|
|
824
|
+
*
|
|
825
|
+
* ## Examples
|
|
826
|
+
*
|
|
827
|
+
* ```ts
|
|
828
|
+
* // Users whose `homeCity` column has a match in a cities
|
|
829
|
+
* // table.
|
|
830
|
+
* db
|
|
831
|
+
* .select()
|
|
832
|
+
* .from(users)
|
|
833
|
+
* .where(
|
|
834
|
+
* exists(db.select()
|
|
835
|
+
* .from(cities)
|
|
836
|
+
* .where(eq(users.homeCity, cities.id))),
|
|
837
|
+
* );
|
|
838
|
+
* ```
|
|
839
|
+
*
|
|
840
|
+
* @see notExists for the inverse of this test
|
|
841
|
+
*/
|
|
838
842
|
exists?: SQLWrapper;
|
|
839
843
|
};
|
|
840
844
|
type PgQueryWhereRelations<Relations extends PgRelationMap<TObject> | undefined = undefined> = Relations extends PgRelationMap<TObject> ? { [K in keyof Relations]?: PgQueryWhere<Relations[K]["join"]["schema"], Relations[K]["with"]> } : {};
|
|
@@ -939,6 +943,116 @@ interface PgAttrField {
|
|
|
939
943
|
one?: boolean;
|
|
940
944
|
}
|
|
941
945
|
//#endregion
|
|
946
|
+
//#region ../../src/orm/providers/DatabaseTypeProvider.d.ts
|
|
947
|
+
declare class DatabaseTypeProvider {
|
|
948
|
+
readonly attr: <T extends TSchema, Attr extends PgSymbolKeys>(type: T, attr: Attr, value?: PgSymbols[Attr]) => PgAttr<T, Attr>;
|
|
949
|
+
/**
|
|
950
|
+
* Creates a primary key with an identity column.
|
|
951
|
+
*/
|
|
952
|
+
readonly identityPrimaryKey: (identity?: PgIdentityOptions, options?: TNumberOptions) => PgAttr<PgAttr<PgAttr<TInteger, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
|
|
953
|
+
/**
|
|
954
|
+
* Creates a primary key with a big identity column. (default)
|
|
955
|
+
*/
|
|
956
|
+
readonly bigIdentityPrimaryKey: (identity?: PgIdentityOptions, options?: TNumberOptions) => PgAttr<PgAttr<PgAttr<TNumber, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
|
|
957
|
+
/**
|
|
958
|
+
* Creates a primary key with a UUID column.
|
|
959
|
+
*/
|
|
960
|
+
readonly uuidPrimaryKey: () => PgAttr<PgAttr<TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
961
|
+
/**
|
|
962
|
+
* Creates a primary key for a given type. Supports:
|
|
963
|
+
* - `t.integer()` -> PG INT (default)
|
|
964
|
+
* - `t.bigint()` -> PG BIGINT
|
|
965
|
+
* - `t.uuid()` -> PG UUID
|
|
966
|
+
*/
|
|
967
|
+
primaryKey(): PgAttr<PgAttr<TInteger, PgPrimaryKey>, PgDefault>;
|
|
968
|
+
primaryKey(type: TString, options?: TStringOptions): PgAttr<PgAttr<TString, PgPrimaryKey>, PgDefault>;
|
|
969
|
+
primaryKey(type: TInteger, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TInteger, PgPrimaryKey>, PgDefault>;
|
|
970
|
+
primaryKey(type: TNumber, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TNumber, PgPrimaryKey>, PgDefault>;
|
|
971
|
+
primaryKey(type: TBigInt, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TBigInt, PgPrimaryKey>, PgDefault>;
|
|
972
|
+
/**
|
|
973
|
+
* Wrap a schema with "default" attribute.
|
|
974
|
+
* This is used to set a default value for a column in the database.
|
|
975
|
+
*/
|
|
976
|
+
readonly default: <T extends TSchema>(type: T, value?: Static<T>) => PgAttr<T, PgDefault>;
|
|
977
|
+
/**
|
|
978
|
+
* Creates a column 'version'.
|
|
979
|
+
*
|
|
980
|
+
* This is used to track the version of a row in the database.
|
|
981
|
+
*
|
|
982
|
+
* You can use it for optimistic concurrency control (OCC) with {@link RepositoryPrimitive#save}.
|
|
983
|
+
*
|
|
984
|
+
* @see {@link RepositoryPrimitive#save}
|
|
985
|
+
* @see {@link PgVersionMismatchError}
|
|
986
|
+
*/
|
|
987
|
+
readonly version: (options?: TNumberOptions) => PgAttr<PgAttr<TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
|
|
988
|
+
/**
|
|
989
|
+
* Creates a column Created At. So just a datetime column with a default value of the current timestamp.
|
|
990
|
+
*/
|
|
991
|
+
readonly createdAt: (options?: TStringOptions) => PgAttr<PgAttr<TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
992
|
+
/**
|
|
993
|
+
* Creates a column Updated At. Like createdAt, but it is updated on every update of the row.
|
|
994
|
+
*/
|
|
995
|
+
readonly updatedAt: (options?: TStringOptions) => PgAttr<PgAttr<TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
996
|
+
/**
|
|
997
|
+
* Creates a column Deleted At for soft delete functionality.
|
|
998
|
+
* This is used to mark rows as deleted without actually removing them from the database.
|
|
999
|
+
* The column is nullable - NULL means not deleted, timestamp means deleted.
|
|
1000
|
+
*/
|
|
1001
|
+
readonly deletedAt: (options?: TStringOptions) => PgAttr<alepha34.TOptional<TString>, typeof PG_DELETED_AT>;
|
|
1002
|
+
/**
|
|
1003
|
+
* Creates a Postgres ENUM type.
|
|
1004
|
+
*
|
|
1005
|
+
* > By default, `t.enum()` is mapped to a TEXT column in Postgres.
|
|
1006
|
+
* > Using this method, you can create a real ENUM type in the database.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```ts
|
|
1010
|
+
* const statusEnum = pg.enum(["pending", "active", "archived"], { name: "status_enum" });
|
|
1011
|
+
* ```
|
|
1012
|
+
*/
|
|
1013
|
+
readonly enum: <T extends string[]>(values: [...T], pgEnumOptions?: PgEnumOptions, typeOptions?: TStringOptions) => PgAttr<TUnsafe<T[number]>, typeof PG_ENUM>;
|
|
1014
|
+
/**
|
|
1015
|
+
* Creates a reference to another table or schema. Basically a foreign key.
|
|
1016
|
+
*/
|
|
1017
|
+
readonly ref: <T extends TSchema>(type: T, ref: () => any, actions?: {
|
|
1018
|
+
onUpdate?: UpdateDeleteAction$1;
|
|
1019
|
+
onDelete?: UpdateDeleteAction$1;
|
|
1020
|
+
}) => PgAttr<T, PgRef>;
|
|
1021
|
+
/**
|
|
1022
|
+
* Creates a page schema for a given object schema.
|
|
1023
|
+
* It's used by {@link Repository#paginate} method.
|
|
1024
|
+
*/
|
|
1025
|
+
readonly page: <T extends TObject>(resource: T, options?: TObjectOptions) => TPage<T>;
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Wrapper of TypeProvider (`t`) for database types.
|
|
1029
|
+
*
|
|
1030
|
+
* Use `db` for improve TypeBox schema definitions with database-specific attributes.
|
|
1031
|
+
*
|
|
1032
|
+
* @example
|
|
1033
|
+
* ```ts
|
|
1034
|
+
* import { t } from "alepha";
|
|
1035
|
+
* import { db } from "alepha/orm";
|
|
1036
|
+
*
|
|
1037
|
+
* const userSchema = t.object({
|
|
1038
|
+
* id: db.primaryKey(t.uuid()),
|
|
1039
|
+
* email: t.email(),
|
|
1040
|
+
* createdAt: db.createdAt(),
|
|
1041
|
+
* });
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1044
|
+
declare const db: DatabaseTypeProvider;
|
|
1045
|
+
/**
|
|
1046
|
+
* @deprecated Use `db` instead.
|
|
1047
|
+
*/
|
|
1048
|
+
declare const pg: DatabaseTypeProvider;
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region ../../src/orm/schemas/legacyIdSchema.d.ts
|
|
1051
|
+
/**
|
|
1052
|
+
* @deprecated Use `pg.primaryKey()` instead.
|
|
1053
|
+
*/
|
|
1054
|
+
declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<alepha34.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
|
|
1055
|
+
//#endregion
|
|
942
1056
|
//#region ../../src/orm/primitives/$sequence.d.ts
|
|
943
1057
|
/**
|
|
944
1058
|
* Creates a PostgreSQL sequence primitive for generating unique numeric values.
|
|
@@ -949,8 +1063,8 @@ declare const $sequence: {
|
|
|
949
1063
|
};
|
|
950
1064
|
interface SequencePrimitiveOptions extends PgSequenceOptions {
|
|
951
1065
|
/**
|
|
952
|
-
|
|
953
|
-
|
|
1066
|
+
* The name of the sequence. If not provided, the property key will be used.
|
|
1067
|
+
*/
|
|
954
1068
|
name?: string;
|
|
955
1069
|
provider?: DatabaseProvider;
|
|
956
1070
|
}
|
|
@@ -990,79 +1104,79 @@ interface TableConfigBuilders<TConfig> {
|
|
|
990
1104
|
*/
|
|
991
1105
|
declare abstract class ModelBuilder {
|
|
992
1106
|
/**
|
|
993
|
-
|
|
994
|
-
|
|
1107
|
+
* Build a table from an entity primitive.
|
|
1108
|
+
*/
|
|
995
1109
|
abstract buildTable(entity: EntityPrimitive, options: {
|
|
996
1110
|
tables: Map<string, unknown>;
|
|
997
1111
|
enums: Map<string, unknown>;
|
|
998
1112
|
schema: string;
|
|
999
1113
|
}): void;
|
|
1000
1114
|
/**
|
|
1001
|
-
|
|
1002
|
-
|
|
1115
|
+
* Build a sequence from a sequence primitive.
|
|
1116
|
+
*/
|
|
1003
1117
|
abstract buildSequence(sequence: SequencePrimitive, options: {
|
|
1004
1118
|
sequences: Map<string, unknown>;
|
|
1005
1119
|
schema: string;
|
|
1006
1120
|
}): void;
|
|
1007
1121
|
/**
|
|
1008
|
-
|
|
1009
|
-
|
|
1122
|
+
* Convert camelCase to snake_case for column names.
|
|
1123
|
+
*/
|
|
1010
1124
|
protected toColumnName(str: string): string;
|
|
1011
1125
|
/**
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1126
|
+
* Build the table configuration function for any database.
|
|
1127
|
+
* This includes indexes, foreign keys, constraints, and custom config.
|
|
1128
|
+
*
|
|
1129
|
+
* @param entity - The entity primitive
|
|
1130
|
+
* @param builders - Database-specific builder functions
|
|
1131
|
+
* @param tableResolver - Function to resolve entity references to table columns
|
|
1132
|
+
* @param customConfigHandler - Optional handler for custom config
|
|
1133
|
+
*/
|
|
1020
1134
|
protected buildTableConfig<TConfig, TSelf>(entity: EntityPrimitive, builders: TableConfigBuilders<TConfig>, tableResolver?: (entityName: string) => any, customConfigHandler?: (config: any, self: TSelf) => TConfig[]): ((self: TSelf) => TConfig[]) | undefined;
|
|
1021
1135
|
}
|
|
1022
1136
|
//#endregion
|
|
1023
1137
|
//#region ../../src/orm/providers/DrizzleKitProvider.d.ts
|
|
1024
1138
|
declare class DrizzleKitProvider {
|
|
1025
|
-
protected readonly log:
|
|
1139
|
+
protected readonly log: alepha_logger3.Logger;
|
|
1026
1140
|
protected readonly alepha: Alepha;
|
|
1027
1141
|
/**
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1142
|
+
* Synchronize database with current schema definitions.
|
|
1143
|
+
*
|
|
1144
|
+
* In development mode, it will generate and execute migrations based on the current state.
|
|
1145
|
+
* In testing mode, it will generate migrations from scratch without applying them.
|
|
1146
|
+
*
|
|
1147
|
+
* Does nothing in production mode, you must handle migrations manually.
|
|
1148
|
+
*/
|
|
1035
1149
|
synchronize(provider: DatabaseProvider): Promise<void>;
|
|
1036
1150
|
/**
|
|
1037
|
-
|
|
1038
|
-
|
|
1151
|
+
* Mostly used for testing purposes. You can generate SQL migration statements without executing them.
|
|
1152
|
+
*/
|
|
1039
1153
|
generateMigration(provider: DatabaseProvider, prevSnapshot?: any): Promise<{
|
|
1040
1154
|
statements: string[];
|
|
1041
1155
|
models: Record<string, unknown>;
|
|
1042
1156
|
snapshot?: any;
|
|
1043
1157
|
}>;
|
|
1044
1158
|
/**
|
|
1045
|
-
|
|
1046
|
-
|
|
1159
|
+
* Load all tables, enums, sequences, etc. from the provider's repositories.
|
|
1160
|
+
*/
|
|
1047
1161
|
getModels(provider: DatabaseProvider): Record<string, unknown>;
|
|
1048
1162
|
/**
|
|
1049
|
-
|
|
1050
|
-
|
|
1163
|
+
* Load the migration snapshot from the database.
|
|
1164
|
+
*/
|
|
1051
1165
|
protected loadDevMigrations(provider: DatabaseProvider): Promise<DevMigrations | undefined>;
|
|
1052
1166
|
protected saveDevMigrations(provider: DatabaseProvider, curr: Record<string, any>, devMigrations?: DevMigrations): Promise<void>;
|
|
1053
1167
|
protected executeStatements(statements: string[], provider: DatabaseProvider, catchErrors?: boolean): Promise<void>;
|
|
1054
1168
|
protected createSchemaIfNotExists(provider: DatabaseProvider, schemaName: string): Promise<void>;
|
|
1055
1169
|
/**
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1170
|
+
* Try to load the official Drizzle Kit API.
|
|
1171
|
+
* If not available, fallback to the local kit import.
|
|
1172
|
+
*/
|
|
1059
1173
|
importDrizzleKit(): typeof DrizzleKit;
|
|
1060
1174
|
}
|
|
1061
|
-
declare const devMigrationsSchema:
|
|
1062
|
-
id:
|
|
1063
|
-
name:
|
|
1064
|
-
snapshot:
|
|
1065
|
-
created_at:
|
|
1175
|
+
declare const devMigrationsSchema: alepha34.TObject<{
|
|
1176
|
+
id: alepha34.TNumber;
|
|
1177
|
+
name: alepha34.TString;
|
|
1178
|
+
snapshot: alepha34.TString;
|
|
1179
|
+
created_at: alepha34.TString;
|
|
1066
1180
|
}>;
|
|
1067
1181
|
type DevMigrations = Static<typeof devMigrationsSchema>;
|
|
1068
1182
|
//#endregion
|
|
@@ -1070,7 +1184,7 @@ type DevMigrations = Static<typeof devMigrationsSchema>;
|
|
|
1070
1184
|
type SQLLike = SQLWrapper | string;
|
|
1071
1185
|
declare abstract class DatabaseProvider {
|
|
1072
1186
|
protected readonly alepha: Alepha;
|
|
1073
|
-
protected readonly log:
|
|
1187
|
+
protected readonly log: alepha_logger3.Logger;
|
|
1074
1188
|
protected abstract readonly builder: ModelBuilder;
|
|
1075
1189
|
protected abstract readonly kit: DrizzleKitProvider;
|
|
1076
1190
|
abstract readonly db: PgDatabase<any>;
|
|
@@ -1080,6 +1194,7 @@ declare abstract class DatabaseProvider {
|
|
|
1080
1194
|
readonly tables: Map<string, unknown>;
|
|
1081
1195
|
readonly sequences: Map<string, unknown>;
|
|
1082
1196
|
get name(): string;
|
|
1197
|
+
get driver(): string;
|
|
1083
1198
|
get schema(): string;
|
|
1084
1199
|
table<T extends TObject>(entity: EntityPrimitive<T>): PgTableWithColumns<SchemaToTableConfig<T>>;
|
|
1085
1200
|
registerEntity(entity: EntityPrimitive): void;
|
|
@@ -1087,39 +1202,39 @@ declare abstract class DatabaseProvider {
|
|
|
1087
1202
|
abstract execute(statement: SQLLike): Promise<Record<string, unknown>[]>;
|
|
1088
1203
|
run<T extends TObject>(statement: SQLLike, schema: T): Promise<Array<Static<T>>>;
|
|
1089
1204
|
/**
|
|
1090
|
-
|
|
1091
|
-
|
|
1205
|
+
* Get migrations folder path - can be overridden
|
|
1206
|
+
*/
|
|
1092
1207
|
protected getMigrationsFolder(): string;
|
|
1093
1208
|
/**
|
|
1094
|
-
|
|
1095
|
-
|
|
1209
|
+
* Base migration orchestration - handles environment logic
|
|
1210
|
+
*/
|
|
1096
1211
|
migrate(): Promise<void>;
|
|
1097
1212
|
/**
|
|
1098
|
-
|
|
1099
|
-
|
|
1213
|
+
* Production: run migrations from folder
|
|
1214
|
+
*/
|
|
1100
1215
|
protected runProductionMigration(migrationsFolder: string): Promise<void>;
|
|
1101
1216
|
/**
|
|
1102
|
-
|
|
1103
|
-
|
|
1217
|
+
* Test: always synchronize
|
|
1218
|
+
*/
|
|
1104
1219
|
protected runTestMigration(): Promise<void>;
|
|
1105
1220
|
/**
|
|
1106
|
-
|
|
1107
|
-
|
|
1221
|
+
* Development: default to synchronize (can be overridden)
|
|
1222
|
+
*/
|
|
1108
1223
|
protected runDevelopmentMigration(migrationsFolder: string): Promise<void>;
|
|
1109
1224
|
/**
|
|
1110
|
-
|
|
1111
|
-
|
|
1225
|
+
* Common synchronization with error handling
|
|
1226
|
+
*/
|
|
1112
1227
|
protected synchronizeSchema(): Promise<void>;
|
|
1113
1228
|
/**
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1229
|
+
* Provider-specific migration execution
|
|
1230
|
+
* MUST be implemented by each provider
|
|
1231
|
+
*/
|
|
1117
1232
|
protected abstract executeMigrations(migrationsFolder: string): Promise<void>;
|
|
1118
1233
|
/**
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1234
|
+
* For testing purposes, generate a unique schema name.
|
|
1235
|
+
* The schema name will be generated based on the current date and time.
|
|
1236
|
+
* It will be in the format of `test_YYYYMMDD_HHMMSS_randomSuffix`.
|
|
1237
|
+
*/
|
|
1123
1238
|
protected generateTestSchemaName(): string;
|
|
1124
1239
|
}
|
|
1125
1240
|
//#endregion
|
|
@@ -1127,8 +1242,8 @@ declare abstract class DatabaseProvider {
|
|
|
1127
1242
|
declare class QueryManager {
|
|
1128
1243
|
protected readonly alepha: Alepha;
|
|
1129
1244
|
/**
|
|
1130
|
-
|
|
1131
|
-
|
|
1245
|
+
* Convert a query object to a SQL query.
|
|
1246
|
+
*/
|
|
1132
1247
|
toSQL(query: PgQueryWhereOrSQL<TObject>, options: {
|
|
1133
1248
|
schema: TObject;
|
|
1134
1249
|
col: (key: string) => PgColumn;
|
|
@@ -1136,22 +1251,22 @@ declare class QueryManager {
|
|
|
1136
1251
|
dialect: "postgresql" | "sqlite";
|
|
1137
1252
|
}): SQL | undefined;
|
|
1138
1253
|
/**
|
|
1139
|
-
|
|
1140
|
-
|
|
1254
|
+
* Check if an object has any filter operator properties.
|
|
1255
|
+
*/
|
|
1141
1256
|
protected hasFilterOperatorProperties(obj: any): boolean;
|
|
1142
1257
|
/**
|
|
1143
|
-
|
|
1144
|
-
|
|
1258
|
+
* Map a filter operator to a SQL query.
|
|
1259
|
+
*/
|
|
1145
1260
|
mapOperatorToSql(operator: FilterOperators<any> | any, column: PgColumn, columnSchema?: TObject, columnName?: string, dialect?: "postgresql" | "sqlite"): SQL | undefined;
|
|
1146
1261
|
/**
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1262
|
+
* Parse pagination sort string to orderBy format.
|
|
1263
|
+
* Format: "firstName,-lastName" -> [{ column: "firstName", direction: "asc" }, { column: "lastName", direction: "desc" }]
|
|
1264
|
+
* - Columns separated by comma
|
|
1265
|
+
* - Prefix with '-' for DESC direction
|
|
1266
|
+
*
|
|
1267
|
+
* @param sort Pagination sort string
|
|
1268
|
+
* @returns OrderBy array or single object
|
|
1269
|
+
*/
|
|
1155
1270
|
parsePaginationSort(sort: string): Array<{
|
|
1156
1271
|
column: string;
|
|
1157
1272
|
direction: "asc" | "desc";
|
|
@@ -1160,34 +1275,34 @@ declare class QueryManager {
|
|
|
1160
1275
|
direction: "asc" | "desc";
|
|
1161
1276
|
};
|
|
1162
1277
|
/**
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1278
|
+
* Normalize orderBy parameter to array format.
|
|
1279
|
+
* Supports 3 modes:
|
|
1280
|
+
* 1. String: "name" -> [{ column: "name", direction: "asc" }]
|
|
1281
|
+
* 2. Object: { column: "name", direction: "desc" } -> [{ column: "name", direction: "desc" }]
|
|
1282
|
+
* 3. Array: [{ column: "name" }, { column: "age", direction: "desc" }] -> normalized array
|
|
1283
|
+
*
|
|
1284
|
+
* @param orderBy The orderBy parameter
|
|
1285
|
+
* @returns Normalized array of order by clauses
|
|
1286
|
+
*/
|
|
1172
1287
|
normalizeOrderBy(orderBy: any): Array<{
|
|
1173
1288
|
column: string;
|
|
1174
1289
|
direction: "asc" | "desc";
|
|
1175
1290
|
}>;
|
|
1176
1291
|
/**
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1292
|
+
* Create a pagination object.
|
|
1293
|
+
*
|
|
1294
|
+
* @deprecated Use `createPagination` from alepha instead.
|
|
1295
|
+
* This method now delegates to the framework-level helper.
|
|
1296
|
+
*
|
|
1297
|
+
* @param entities The entities to paginate.
|
|
1298
|
+
* @param limit The limit of the pagination.
|
|
1299
|
+
* @param offset The offset of the pagination.
|
|
1300
|
+
* @param sort Optional sort metadata to include in response.
|
|
1301
|
+
*/
|
|
1187
1302
|
createPagination<T>(entities: T[], limit?: number, offset?: number, sort?: Array<{
|
|
1188
1303
|
column: string;
|
|
1189
1304
|
direction: "asc" | "desc";
|
|
1190
|
-
}>):
|
|
1305
|
+
}>): alepha34.Page<T>;
|
|
1191
1306
|
}
|
|
1192
1307
|
interface PgJoin {
|
|
1193
1308
|
table: string;
|
|
@@ -1200,20 +1315,20 @@ interface PgJoin {
|
|
|
1200
1315
|
//#region ../../src/orm/services/PgRelationManager.d.ts
|
|
1201
1316
|
declare class PgRelationManager {
|
|
1202
1317
|
/**
|
|
1203
|
-
|
|
1204
|
-
|
|
1318
|
+
* Recursively build joins for the query builder based on the relations map
|
|
1319
|
+
*/
|
|
1205
1320
|
buildJoins(provider: DatabaseProvider, builder: PgSelectBase<any, any, any>, joins: Array<PgJoin>, withRelations: PgRelationMap<TObject>, table: PgTableWithColumns<any>, parentKey?: string): void;
|
|
1206
1321
|
/**
|
|
1207
|
-
|
|
1208
|
-
|
|
1322
|
+
* Map a row with its joined relations based on the joins definition
|
|
1323
|
+
*/
|
|
1209
1324
|
mapRowWithJoins(record: Record<string, unknown>, row: Record<string, unknown>, schema: TObject, joins: PgJoin[], parentKey?: string): Record<string, unknown>;
|
|
1210
1325
|
/**
|
|
1211
|
-
|
|
1212
|
-
|
|
1326
|
+
* Check if all values in an object are null (indicates a left join with no match)
|
|
1327
|
+
*/
|
|
1213
1328
|
private isAllNull;
|
|
1214
1329
|
/**
|
|
1215
|
-
|
|
1216
|
-
|
|
1330
|
+
* Build a schema that includes all join properties recursively
|
|
1331
|
+
*/
|
|
1217
1332
|
buildSchemaWithJoins(baseSchema: TObject, joins: PgJoin[], parentPath?: string): TObject;
|
|
1218
1333
|
}
|
|
1219
1334
|
//#endregion
|
|
@@ -1221,216 +1336,217 @@ declare class PgRelationManager {
|
|
|
1221
1336
|
declare abstract class Repository<T extends TObject> {
|
|
1222
1337
|
readonly entity: EntityPrimitive<T>;
|
|
1223
1338
|
readonly provider: DatabaseProvider;
|
|
1339
|
+
protected readonly log: alepha_logger3.Logger;
|
|
1224
1340
|
protected readonly relationManager: PgRelationManager;
|
|
1225
1341
|
protected readonly queryManager: QueryManager;
|
|
1226
1342
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
1227
1343
|
protected readonly alepha: Alepha;
|
|
1228
1344
|
constructor(entity: EntityPrimitive<T>, provider?: typeof DatabaseProvider);
|
|
1229
1345
|
/**
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1346
|
+
* Represents the primary key of the table.
|
|
1347
|
+
* - Key is the name of the primary key column.
|
|
1348
|
+
* - Type is the type (TypeBox) of the primary key column.
|
|
1349
|
+
*
|
|
1350
|
+
* ID is mandatory. If the table does not have a primary key, it will throw an error.
|
|
1351
|
+
*/
|
|
1236
1352
|
get id(): {
|
|
1237
1353
|
type: TSchema;
|
|
1238
1354
|
key: keyof T["properties"];
|
|
1239
1355
|
col: PgColumn;
|
|
1240
1356
|
};
|
|
1241
1357
|
/**
|
|
1242
|
-
|
|
1243
|
-
|
|
1358
|
+
* Get Drizzle table object.
|
|
1359
|
+
*/
|
|
1244
1360
|
get table(): PgTableWithColumns<SchemaToTableConfig<T>>;
|
|
1245
1361
|
/**
|
|
1246
|
-
|
|
1247
|
-
|
|
1362
|
+
* Get SQL table name. (from Drizzle table object)
|
|
1363
|
+
*/
|
|
1248
1364
|
get tableName(): string;
|
|
1249
1365
|
/**
|
|
1250
|
-
|
|
1251
|
-
|
|
1366
|
+
* Getter for the database connection from the database provider.
|
|
1367
|
+
*/
|
|
1252
1368
|
protected get db(): PgDatabase<any>;
|
|
1253
1369
|
/**
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1370
|
+
* Execute a SQL query.
|
|
1371
|
+
*
|
|
1372
|
+
* This method allows executing raw SQL queries against the database.
|
|
1373
|
+
* This is by far the easiest way to run custom queries that are not covered by the repository's built-in methods!
|
|
1374
|
+
*
|
|
1375
|
+
* You must use the `sql` tagged template function from Drizzle ORM to create the query. https://orm.drizzle.team/docs/sql
|
|
1376
|
+
*
|
|
1377
|
+
* @example
|
|
1378
|
+
* ```ts
|
|
1379
|
+
* class App {
|
|
1380
|
+
* repository = $repository({ ... });
|
|
1381
|
+
* async getAdults() {
|
|
1382
|
+
* const users = repository.table; // Drizzle table object
|
|
1383
|
+
* await repository.query(sql`SELECT * FROM ${users} WHERE ${users.age} > ${18}`);
|
|
1384
|
+
* // or better
|
|
1385
|
+
* await repository.query((users) => sql`SELECT * FROM ${users} WHERE ${users.age} > ${18}`);
|
|
1386
|
+
* }
|
|
1387
|
+
* }
|
|
1388
|
+
* ```
|
|
1389
|
+
*/
|
|
1274
1390
|
query<R extends TObject = T>(query: SQLLike | ((table: PgTableWithColumns<SchemaToTableConfig<T>>, db: PgDatabase<any>) => SQLLike), schema?: R): Promise<Static<R>[]>;
|
|
1275
1391
|
/**
|
|
1276
|
-
|
|
1277
|
-
|
|
1392
|
+
* Map raw database fields to entity fields. (handles column name differences)
|
|
1393
|
+
*/
|
|
1278
1394
|
protected mapRawFieldsToEntity(row: Record<string, unknown>): any;
|
|
1279
1395
|
/**
|
|
1280
|
-
|
|
1281
|
-
|
|
1396
|
+
* Get a Drizzle column from the table by his name.
|
|
1397
|
+
*/
|
|
1282
1398
|
protected col(name: keyof StaticEncode<T>): PgColumn;
|
|
1283
1399
|
/**
|
|
1284
|
-
|
|
1285
|
-
|
|
1400
|
+
* Run a transaction.
|
|
1401
|
+
*/
|
|
1286
1402
|
transaction<T>(transaction: (tx: PgTransaction<any, Record<string, any>, any>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
1287
1403
|
/**
|
|
1288
|
-
|
|
1289
|
-
|
|
1404
|
+
* Start a SELECT query on the table.
|
|
1405
|
+
*/
|
|
1290
1406
|
protected rawSelect(opts?: StatementOptions): drizzle_orm_pg_core0.PgSelectBase<string, Record<string, PgColumn<drizzle_orm0.ColumnBaseConfig<drizzle_orm0.ColumnDataType, string>, {}, {}>>, "single", Record<string, "not-null">, false, never, {
|
|
1291
1407
|
[x: string]: unknown;
|
|
1292
1408
|
}[], {
|
|
1293
1409
|
[x: string]: PgColumn<drizzle_orm0.ColumnBaseConfig<drizzle_orm0.ColumnDataType, string>, {}, {}>;
|
|
1294
1410
|
}>;
|
|
1295
1411
|
/**
|
|
1296
|
-
|
|
1297
|
-
|
|
1412
|
+
* Start a SELECT DISTINCT query on the table.
|
|
1413
|
+
*/
|
|
1298
1414
|
protected rawSelectDistinct(opts?: StatementOptions, columns?: (keyof Static<T>)[]): drizzle_orm_pg_core0.PgSelectBase<string, Record<string, any>, "partial", Record<string, "not-null">, false, never, {
|
|
1299
1415
|
[x: string]: any;
|
|
1300
1416
|
}[], {
|
|
1301
1417
|
[x: string]: any;
|
|
1302
1418
|
}>;
|
|
1303
1419
|
/**
|
|
1304
|
-
|
|
1305
|
-
|
|
1420
|
+
* Start an INSERT query on the table.
|
|
1421
|
+
*/
|
|
1306
1422
|
protected rawInsert(opts?: StatementOptions): drizzle_orm_pg_core0.PgInsertBuilder<PgTableWithColumns<SchemaToTableConfig<T>>, any, false>;
|
|
1307
1423
|
/**
|
|
1308
|
-
|
|
1309
|
-
|
|
1424
|
+
* Start an UPDATE query on the table.
|
|
1425
|
+
*/
|
|
1310
1426
|
protected rawUpdate(opts?: StatementOptions): drizzle_orm_pg_core0.PgUpdateBuilder<PgTableWithColumns<SchemaToTableConfig<T>>, any>;
|
|
1311
1427
|
/**
|
|
1312
|
-
|
|
1313
|
-
|
|
1428
|
+
* Start a DELETE query on the table.
|
|
1429
|
+
*/
|
|
1314
1430
|
protected rawDelete(opts?: StatementOptions): drizzle_orm_pg_core0.PgDeleteBase<PgTableWithColumns<SchemaToTableConfig<T>>, any, undefined, undefined, false, never>;
|
|
1315
1431
|
/**
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1432
|
+
* Create a Drizzle `select` query based on a JSON query object.
|
|
1433
|
+
*
|
|
1434
|
+
* > This method is the base for `find`, `findOne`, `findById`, and `paginate`.
|
|
1435
|
+
*/
|
|
1320
1436
|
findMany<R extends PgRelationMap<T>>(query?: PgQueryRelations<T, R>, opts?: StatementOptions): Promise<PgStatic<T, R>[]>;
|
|
1321
1437
|
/**
|
|
1322
|
-
|
|
1323
|
-
|
|
1438
|
+
* Find a single entity.
|
|
1439
|
+
*/
|
|
1324
1440
|
findOne<R extends PgRelationMap<T>>(query: Pick<PgQueryRelations<T, R>, "with" | "where">, opts?: StatementOptions): Promise<PgStatic<T, R>>;
|
|
1325
1441
|
/**
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1442
|
+
* Find entities with pagination.
|
|
1443
|
+
*
|
|
1444
|
+
* It uses the same parameters as `find()`, but adds pagination metadata to the response.
|
|
1445
|
+
*
|
|
1446
|
+
* > Pagination CAN also do a count query to get the total number of elements.
|
|
1447
|
+
*/
|
|
1332
1448
|
paginate<R extends PgRelationMap<T>>(pagination?: PageQuery$1, query?: PgQueryRelations<T, R>, opts?: StatementOptions & {
|
|
1333
1449
|
count?: boolean;
|
|
1334
1450
|
}): Promise<Page$1<PgStatic<T, R>>>;
|
|
1335
1451
|
/**
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1452
|
+
* Find an entity by ID.
|
|
1453
|
+
*
|
|
1454
|
+
* This is a convenience method for `findOne` with a where clause on the primary key.
|
|
1455
|
+
* If you need more complex queries, use `findOne` instead.
|
|
1456
|
+
*/
|
|
1341
1457
|
findById(id: string | number, opts?: StatementOptions): Promise<Static<T>>;
|
|
1342
1458
|
/**
|
|
1343
|
-
|
|
1344
|
-
|
|
1459
|
+
* Helper to create a type-safe query object.
|
|
1460
|
+
*/
|
|
1345
1461
|
createQuery(): PgQuery<T>;
|
|
1346
1462
|
/**
|
|
1347
|
-
|
|
1348
|
-
|
|
1463
|
+
* Helper to create a type-safe where clause.
|
|
1464
|
+
*/
|
|
1349
1465
|
createQueryWhere(): PgQueryWhere<T>;
|
|
1350
1466
|
/**
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1467
|
+
* Create an entity.
|
|
1468
|
+
*
|
|
1469
|
+
* @param data The entity to create.
|
|
1470
|
+
* @param opts The options for creating the entity.
|
|
1471
|
+
* @returns The ID of the created entity.
|
|
1472
|
+
*/
|
|
1357
1473
|
create(data: Static<TObjectInsert<T>>, opts?: StatementOptions): Promise<Static<T>>;
|
|
1358
1474
|
/**
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1475
|
+
* Create many entities.
|
|
1476
|
+
*
|
|
1477
|
+
* Inserts are batched in chunks of 1000 to avoid hitting database limits.
|
|
1478
|
+
*
|
|
1479
|
+
* @param values The entities to create.
|
|
1480
|
+
* @param opts The statement options.
|
|
1481
|
+
* @returns The created entities.
|
|
1482
|
+
*/
|
|
1367
1483
|
createMany(values: Array<Static<TObjectInsert<T>>>, opts?: StatementOptions & {
|
|
1368
1484
|
batchSize?: number;
|
|
1369
1485
|
}): Promise<Static<T>[]>;
|
|
1370
1486
|
/**
|
|
1371
|
-
|
|
1372
|
-
|
|
1487
|
+
* Find an entity and update it.
|
|
1488
|
+
*/
|
|
1373
1489
|
updateOne(where: PgQueryWhereOrSQL<T>, data: Partial<Static<TObjectUpdate<T>>>, opts?: StatementOptions): Promise<Static<T>>;
|
|
1374
1490
|
/**
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1491
|
+
* Save a given entity.
|
|
1492
|
+
*
|
|
1493
|
+
* @example
|
|
1494
|
+
* ```ts
|
|
1495
|
+
* const entity = await repository.findById(1);
|
|
1496
|
+
* entity.name = "New Name"; // update a field
|
|
1497
|
+
* delete entity.description; // delete a field
|
|
1498
|
+
* await repository.save(entity);
|
|
1499
|
+
* ```
|
|
1500
|
+
*
|
|
1501
|
+
* Difference with `updateById/updateOne`:
|
|
1502
|
+
*
|
|
1503
|
+
* - requires the entity to be fetched first (whole object is expected)
|
|
1504
|
+
* - check pg.version() if present -> optimistic locking
|
|
1505
|
+
* - validate entity against schema
|
|
1506
|
+
* - undefined values will be set to null, not ignored!
|
|
1507
|
+
*
|
|
1508
|
+
* @see {@link DbVersionMismatchError}
|
|
1509
|
+
*/
|
|
1394
1510
|
save(entity: Static<T>, opts?: StatementOptions): Promise<void>;
|
|
1395
1511
|
/**
|
|
1396
|
-
|
|
1397
|
-
|
|
1512
|
+
* Find an entity by ID and update it.
|
|
1513
|
+
*/
|
|
1398
1514
|
updateById(id: string | number, data: Partial<Static<TObjectUpdate<T>>>, opts?: StatementOptions): Promise<Static<T>>;
|
|
1399
1515
|
/**
|
|
1400
|
-
|
|
1401
|
-
|
|
1516
|
+
* Find many entities and update all of them.
|
|
1517
|
+
*/
|
|
1402
1518
|
updateMany(where: PgQueryWhereOrSQL<T>, data: Partial<Static<TObjectUpdate<T>>>, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1403
1519
|
/**
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1520
|
+
* Find many and delete all of them.
|
|
1521
|
+
* @returns Array of deleted entity IDs
|
|
1522
|
+
*/
|
|
1407
1523
|
deleteMany(where?: PgQueryWhereOrSQL<T>, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1408
1524
|
/**
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1525
|
+
* Delete all entities.
|
|
1526
|
+
* @returns Array of deleted entity IDs
|
|
1527
|
+
*/
|
|
1412
1528
|
clear(opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1413
1529
|
/**
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1530
|
+
* Delete the given entity.
|
|
1531
|
+
*
|
|
1532
|
+
* You must fetch the entity first in order to delete it.
|
|
1533
|
+
* @returns Array containing the deleted entity ID
|
|
1534
|
+
*/
|
|
1419
1535
|
destroy(entity: Static<T>, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1420
1536
|
/**
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1537
|
+
* Find an entity and delete it.
|
|
1538
|
+
* @returns Array of deleted entity IDs (should contain at most one ID)
|
|
1539
|
+
*/
|
|
1424
1540
|
deleteOne(where?: PgQueryWhereOrSQL<T>, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1425
1541
|
/**
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1542
|
+
* Find an entity by ID and delete it.
|
|
1543
|
+
* @returns Array containing the deleted entity ID
|
|
1544
|
+
* @throws DbEntityNotFoundError if the entity is not found
|
|
1545
|
+
*/
|
|
1430
1546
|
deleteById(id: string | number, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1431
1547
|
/**
|
|
1432
|
-
|
|
1433
|
-
|
|
1548
|
+
* Count entities.
|
|
1549
|
+
*/
|
|
1434
1550
|
count(where?: PgQueryWhereOrSQL<T>, opts?: StatementOptions): Promise<number>;
|
|
1435
1551
|
protected conflictMessagePattern: string;
|
|
1436
1552
|
protected handleError(error: unknown, message: string): DbError;
|
|
@@ -1439,31 +1555,31 @@ declare abstract class Repository<T extends TObject> {
|
|
|
1439
1555
|
}): PgQueryWhereOrSQL<T>;
|
|
1440
1556
|
protected deletedAt(): PgAttrField | undefined;
|
|
1441
1557
|
/**
|
|
1442
|
-
|
|
1443
|
-
|
|
1558
|
+
* Convert something to valid Pg Insert Value.
|
|
1559
|
+
*/
|
|
1444
1560
|
protected cast(data: any, insert: boolean): PgInsertValue<PgTableWithColumns<SchemaToTableConfig<T>>>;
|
|
1445
1561
|
/**
|
|
1446
|
-
|
|
1447
|
-
|
|
1562
|
+
* Transform a row from the database into a clean entity.
|
|
1563
|
+
*/
|
|
1448
1564
|
protected clean<T extends TObject>(row: Record<string, unknown>, schema: T): Static<T>;
|
|
1449
1565
|
/**
|
|
1450
|
-
|
|
1451
|
-
|
|
1566
|
+
* Clean a row with joins recursively
|
|
1567
|
+
*/
|
|
1452
1568
|
protected cleanWithJoins<T extends TObject>(row: Record<string, unknown>, schema: T, joins: PgJoin[], parentPath?: string): Static<T>;
|
|
1453
1569
|
/**
|
|
1454
|
-
|
|
1455
|
-
|
|
1570
|
+
* Convert a where clause to SQL.
|
|
1571
|
+
*/
|
|
1456
1572
|
protected toSQL(where: PgQueryWhereOrSQL<T>, joins?: PgJoin[]): SQL | undefined;
|
|
1457
1573
|
/**
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1574
|
+
* Get the where clause for an ID.
|
|
1575
|
+
*
|
|
1576
|
+
* @param id The ID to get the where clause for.
|
|
1577
|
+
* @returns The where clause for the ID.
|
|
1578
|
+
*/
|
|
1463
1579
|
protected getWhereId(id: string | number): PgQueryWhere<T>;
|
|
1464
1580
|
/**
|
|
1465
|
-
|
|
1466
|
-
|
|
1581
|
+
* Find a primary key in the schema.
|
|
1582
|
+
*/
|
|
1467
1583
|
protected getPrimaryKey(schema: TObject): {
|
|
1468
1584
|
key: string;
|
|
1469
1585
|
col: PgColumn<drizzle_orm0.ColumnBaseConfig<drizzle_orm0.ColumnDataType, string>, {}, {}>;
|
|
@@ -1475,23 +1591,23 @@ declare abstract class Repository<T extends TObject> {
|
|
|
1475
1591
|
*/
|
|
1476
1592
|
interface StatementOptions {
|
|
1477
1593
|
/**
|
|
1478
|
-
|
|
1479
|
-
|
|
1594
|
+
* Transaction to use.
|
|
1595
|
+
*/
|
|
1480
1596
|
tx?: PgTransaction<any, Record<string, any>>;
|
|
1481
1597
|
/**
|
|
1482
|
-
|
|
1483
|
-
|
|
1598
|
+
* Lock strength.
|
|
1599
|
+
*/
|
|
1484
1600
|
for?: LockStrength | {
|
|
1485
1601
|
config: LockConfig;
|
|
1486
1602
|
strength: LockStrength;
|
|
1487
1603
|
};
|
|
1488
1604
|
/**
|
|
1489
|
-
|
|
1490
|
-
|
|
1605
|
+
* If true, ignore soft delete.
|
|
1606
|
+
*/
|
|
1491
1607
|
force?: boolean;
|
|
1492
1608
|
/**
|
|
1493
|
-
|
|
1494
|
-
|
|
1609
|
+
* Force the current time.
|
|
1610
|
+
*/
|
|
1495
1611
|
now?: DateTime | string;
|
|
1496
1612
|
}
|
|
1497
1613
|
//#endregion
|
|
@@ -1520,212 +1636,108 @@ declare const $repository: <T extends TObject>(entity: EntityPrimitive<T>) => Re
|
|
|
1520
1636
|
declare const $transaction: <T extends any[], R>(opts: TransactionPrimitiveOptions<T, R>) => alepha_retry0.RetryPrimitiveFn<(...args: T) => Promise<R>>;
|
|
1521
1637
|
interface TransactionPrimitiveOptions<T extends any[], R> {
|
|
1522
1638
|
/**
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1639
|
+
* Transaction handler function that contains all database operations to be executed atomically.
|
|
1640
|
+
*
|
|
1641
|
+
* This function:
|
|
1642
|
+
* - Receives a transaction object as the first parameter
|
|
1643
|
+
* - Should pass the transaction to all repository operations via `{ tx }` option
|
|
1644
|
+
* - All operations within are automatically rolled back if any error occurs
|
|
1645
|
+
* - Has access to the full Alepha dependency injection container
|
|
1646
|
+
* - Will be automatically retried if a `PgVersionMismatchError` occurs
|
|
1647
|
+
*
|
|
1648
|
+
* **Transaction Guidelines**:
|
|
1649
|
+
* - Keep transactions as short as possible to minimize lock contention
|
|
1650
|
+
* - Always pass the `tx` parameter to repository operations
|
|
1651
|
+
* - Handle expected business errors gracefully
|
|
1652
|
+
* - Log important operations for debugging and audit trails
|
|
1653
|
+
* - Consider the impact of long-running transactions on performance
|
|
1654
|
+
*
|
|
1655
|
+
* **Error Handling**:
|
|
1656
|
+
* - Throwing any error will automatically roll back the transaction
|
|
1657
|
+
* - `PgVersionMismatchError` triggers automatic retry logic
|
|
1658
|
+
* - Other database errors will be propagated after rollback
|
|
1659
|
+
* - Use try-catch within the handler for business-specific error handling
|
|
1660
|
+
*
|
|
1661
|
+
* @param tx - The PostgreSQL transaction object to use for all database operations
|
|
1662
|
+
* @param ...args - Additional arguments passed to the transaction function
|
|
1663
|
+
* @returns Promise resolving to the transaction result
|
|
1664
|
+
*
|
|
1665
|
+
* @example
|
|
1666
|
+
* ```ts
|
|
1667
|
+
* handler: async (tx, orderId: string, newStatus: string) => {
|
|
1668
|
+
* // Get the current order (with transaction)
|
|
1669
|
+
* const order = await this.orders.findById(orderId, { tx });
|
|
1670
|
+
*
|
|
1671
|
+
* // Validate business rules
|
|
1672
|
+
* if (!this.isValidStatusTransition(order.status, newStatus)) {
|
|
1673
|
+
* throw new Error(`Invalid status transition: ${order.status} -> ${newStatus}`);
|
|
1674
|
+
* }
|
|
1675
|
+
*
|
|
1676
|
+
* // Update order status (with transaction)
|
|
1677
|
+
* const updatedOrder = await this.orders.updateById(
|
|
1678
|
+
* orderId,
|
|
1679
|
+
* { status: newStatus },
|
|
1680
|
+
* { tx }
|
|
1681
|
+
* );
|
|
1682
|
+
*
|
|
1683
|
+
* // Create audit log (with transaction)
|
|
1684
|
+
* await this.auditLogs.create({
|
|
1685
|
+
* id: generateUUID(),
|
|
1686
|
+
* entityId: orderId,
|
|
1687
|
+
* action: 'status_change',
|
|
1688
|
+
* oldValue: order.status,
|
|
1689
|
+
* newValue: newStatus,
|
|
1690
|
+
* timestamp: new Date().toISOString()
|
|
1691
|
+
* }, { tx });
|
|
1692
|
+
*
|
|
1693
|
+
* return updatedOrder;
|
|
1694
|
+
* }
|
|
1695
|
+
* ```
|
|
1696
|
+
*/
|
|
1581
1697
|
handler: (tx: PgTransaction<any, any, any>, ...args: T) => Promise<R>;
|
|
1582
1698
|
/**
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1699
|
+
* PostgreSQL transaction configuration options.
|
|
1700
|
+
*
|
|
1701
|
+
* This allows you to customize transaction behavior including:
|
|
1702
|
+
* - **Isolation Level**: Controls visibility of concurrent transaction changes
|
|
1703
|
+
* - **Access Mode**: Whether the transaction is read-only or read-write
|
|
1704
|
+
* - **Deferrable**: For serializable transactions, allows deferring to avoid conflicts
|
|
1705
|
+
*
|
|
1706
|
+
* **Isolation Levels**:
|
|
1707
|
+
* - **read_uncommitted**: Lowest isolation, allows dirty reads (rarely used)
|
|
1708
|
+
* - **read_committed**: Default level, prevents dirty reads
|
|
1709
|
+
* - **repeatable_read**: Prevents dirty and non-repeatable reads
|
|
1710
|
+
* - **serializable**: Highest isolation, full ACID compliance
|
|
1711
|
+
*
|
|
1712
|
+
* **Access Modes**:
|
|
1713
|
+
* - **read_write**: Default, allows both read and write operations
|
|
1714
|
+
* - **read_only**: Only allows read operations, can provide performance benefits
|
|
1715
|
+
*
|
|
1716
|
+
* **When to Use Different Isolation Levels**:
|
|
1717
|
+
* - **read_committed**: Most common operations, good balance of consistency and performance
|
|
1718
|
+
* - **repeatable_read**: When you need consistent reads throughout the transaction
|
|
1719
|
+
* - **serializable**: Critical financial operations, when absolute consistency is required
|
|
1720
|
+
*
|
|
1721
|
+
* @example
|
|
1722
|
+
* ```ts
|
|
1723
|
+
* config: {
|
|
1724
|
+
* isolationLevel: 'serializable', // Highest consistency for financial operations
|
|
1725
|
+
* accessMode: 'read_write'
|
|
1726
|
+
* }
|
|
1727
|
+
* ```
|
|
1728
|
+
*
|
|
1729
|
+
* @example
|
|
1730
|
+
* ```ts
|
|
1731
|
+
* config: {
|
|
1732
|
+
* isolationLevel: 'read_committed', // Default level for most operations
|
|
1733
|
+
* accessMode: 'read_only' // Performance optimization for read-only operations
|
|
1734
|
+
* }
|
|
1735
|
+
* ```
|
|
1736
|
+
*/
|
|
1621
1737
|
config?: PgTransactionConfig;
|
|
1622
1738
|
}
|
|
1623
1739
|
type TransactionContext = PgTransaction<any, any, any>;
|
|
1624
1740
|
//#endregion
|
|
1625
|
-
//#region ../../src/orm/providers/DatabaseTypeProvider.d.ts
|
|
1626
|
-
declare class DatabaseTypeProvider {
|
|
1627
|
-
readonly attr: <T extends TSchema, Attr extends PgSymbolKeys>(type: T, attr: Attr, value?: PgSymbols[Attr]) => PgAttr<T, Attr>;
|
|
1628
|
-
/**
|
|
1629
|
-
* Creates a primary key with an identity column.
|
|
1630
|
-
*/
|
|
1631
|
-
readonly identityPrimaryKey: (identity?: PgIdentityOptions, options?: TNumberOptions) => PgAttr<PgAttr<PgAttr<TInteger, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
|
|
1632
|
-
/**
|
|
1633
|
-
* Creates a primary key with a big identity column. (default)
|
|
1634
|
-
*/
|
|
1635
|
-
readonly bigIdentityPrimaryKey: (identity?: PgIdentityOptions, options?: TNumberOptions) => PgAttr<PgAttr<PgAttr<TNumber, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
|
|
1636
|
-
/**
|
|
1637
|
-
* Creates a primary key with a UUID column.
|
|
1638
|
-
*/
|
|
1639
|
-
readonly uuidPrimaryKey: () => PgAttr<PgAttr<TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
1640
|
-
/**
|
|
1641
|
-
* Creates a primary key for a given type. Supports:
|
|
1642
|
-
* - `t.integer()` -> PG INT (default)
|
|
1643
|
-
* - `t.bigint()` -> PG BIGINT
|
|
1644
|
-
* - `t.uuid()` -> PG UUID
|
|
1645
|
-
*/
|
|
1646
|
-
primaryKey(): PgAttr<PgAttr<TInteger, PgPrimaryKey>, PgDefault>;
|
|
1647
|
-
primaryKey(type: TString, options?: TStringOptions): PgAttr<PgAttr<TString, PgPrimaryKey>, PgDefault>;
|
|
1648
|
-
primaryKey(type: TInteger, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TInteger, PgPrimaryKey>, PgDefault>;
|
|
1649
|
-
primaryKey(type: TNumber, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TNumber, PgPrimaryKey>, PgDefault>;
|
|
1650
|
-
primaryKey(type: TBigInt, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TBigInt, PgPrimaryKey>, PgDefault>;
|
|
1651
|
-
/**
|
|
1652
|
-
* Wrap a schema with "default" attribute.
|
|
1653
|
-
* This is used to set a default value for a column in the database.
|
|
1654
|
-
*/
|
|
1655
|
-
readonly default: <T extends TSchema>(type: T, value?: Static<T>) => PgAttr<T, PgDefault>;
|
|
1656
|
-
/**
|
|
1657
|
-
* Creates a column 'version'.
|
|
1658
|
-
*
|
|
1659
|
-
* This is used to track the version of a row in the database.
|
|
1660
|
-
*
|
|
1661
|
-
* You can use it for optimistic concurrency control (OCC) with {@link RepositoryPrimitive#save}.
|
|
1662
|
-
*
|
|
1663
|
-
* @see {@link RepositoryPrimitive#save}
|
|
1664
|
-
* @see {@link PgVersionMismatchError}
|
|
1665
|
-
*/
|
|
1666
|
-
readonly version: (options?: TNumberOptions) => PgAttr<PgAttr<TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
|
|
1667
|
-
/**
|
|
1668
|
-
* Creates a column Created At. So just a datetime column with a default value of the current timestamp.
|
|
1669
|
-
*/
|
|
1670
|
-
readonly createdAt: (options?: TStringOptions) => PgAttr<PgAttr<TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
1671
|
-
/**
|
|
1672
|
-
* Creates a column Updated At. Like createdAt, but it is updated on every update of the row.
|
|
1673
|
-
*/
|
|
1674
|
-
readonly updatedAt: (options?: TStringOptions) => PgAttr<PgAttr<TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
1675
|
-
/**
|
|
1676
|
-
* Creates a column Deleted At for soft delete functionality.
|
|
1677
|
-
* This is used to mark rows as deleted without actually removing them from the database.
|
|
1678
|
-
* The column is nullable - NULL means not deleted, timestamp means deleted.
|
|
1679
|
-
*/
|
|
1680
|
-
readonly deletedAt: (options?: TStringOptions) => PgAttr<alepha2.TOptional<TString>, typeof PG_DELETED_AT>;
|
|
1681
|
-
/**
|
|
1682
|
-
* Creates a Postgres ENUM type.
|
|
1683
|
-
*
|
|
1684
|
-
* > By default, `t.enum()` is mapped to a TEXT column in Postgres.
|
|
1685
|
-
* > Using this method, you can create a real ENUM type in the database.
|
|
1686
|
-
*
|
|
1687
|
-
* @example
|
|
1688
|
-
* ```ts
|
|
1689
|
-
* const statusEnum = pg.enum(["pending", "active", "archived"], { name: "status_enum" });
|
|
1690
|
-
* ```
|
|
1691
|
-
*/
|
|
1692
|
-
readonly enum: <T extends string[]>(values: [...T], pgEnumOptions?: PgEnumOptions, typeOptions?: TStringOptions) => PgAttr<TUnsafe<T[number]>, typeof PG_ENUM>;
|
|
1693
|
-
/**
|
|
1694
|
-
* Creates a reference to another table or schema. Basically a foreign key.
|
|
1695
|
-
*/
|
|
1696
|
-
readonly ref: <T extends TSchema>(type: T, ref: () => any, actions?: {
|
|
1697
|
-
onUpdate?: UpdateDeleteAction$1;
|
|
1698
|
-
onDelete?: UpdateDeleteAction$1;
|
|
1699
|
-
}) => PgAttr<T, PgRef>;
|
|
1700
|
-
/**
|
|
1701
|
-
* Creates a page schema for a given object schema.
|
|
1702
|
-
* It's used by {@link Repository#paginate} method.
|
|
1703
|
-
*/
|
|
1704
|
-
readonly page: <T extends TObject>(resource: T, options?: TObjectOptions) => TPage<T>;
|
|
1705
|
-
}
|
|
1706
|
-
/**
|
|
1707
|
-
* Wrapper of TypeProvider (`t`) for database types.
|
|
1708
|
-
*
|
|
1709
|
-
* Use `db` for improve TypeBox schema definitions with database-specific attributes.
|
|
1710
|
-
*
|
|
1711
|
-
* @example
|
|
1712
|
-
* ```ts
|
|
1713
|
-
* import { t } from "alepha";
|
|
1714
|
-
* import { db } from "alepha/orm";
|
|
1715
|
-
*
|
|
1716
|
-
* const userSchema = t.object({
|
|
1717
|
-
* id: db.primaryKey(t.uuid()),
|
|
1718
|
-
* email: t.email(),
|
|
1719
|
-
* createdAt: db.createdAt(),
|
|
1720
|
-
* });
|
|
1721
|
-
* ```
|
|
1722
|
-
*/
|
|
1723
|
-
declare const db: DatabaseTypeProvider;
|
|
1724
|
-
/**
|
|
1725
|
-
* @deprecated Use `db` instead.
|
|
1726
|
-
*/
|
|
1727
|
-
declare const pg: DatabaseTypeProvider;
|
|
1728
|
-
//#endregion
|
|
1729
1741
|
//#region ../../src/orm/services/SqliteModelBuilder.d.ts
|
|
1730
1742
|
declare class SqliteModelBuilder extends ModelBuilder {
|
|
1731
1743
|
buildTable(entity: EntityPrimitive<any>, options: {
|
|
@@ -1738,8 +1750,8 @@ declare class SqliteModelBuilder extends ModelBuilder {
|
|
|
1738
1750
|
schema: string;
|
|
1739
1751
|
}): void;
|
|
1740
1752
|
/**
|
|
1741
|
-
|
|
1742
|
-
|
|
1753
|
+
* Get SQLite-specific config builder for the table.
|
|
1754
|
+
*/
|
|
1743
1755
|
protected getTableConfig(entity: EntityPrimitive, tables: Map<string, unknown>): ((self: BuildColumns<string, any, "sqlite">) => any) | undefined;
|
|
1744
1756
|
schemaToSqliteColumns: <T extends TObject>(tableName: string, schema: T, enums: Map<string, unknown>, tables: Map<string, unknown>) => SchemaToSqliteBuilder<T>;
|
|
1745
1757
|
mapFieldToSqliteColumn: (tableName: string, fieldName: string, value: TSchema, enums: Map<string, any>) => pg$1.SQLiteIntegerBuilderInitial<string> | pg$1.SQLiteNumericBuilderInitial<string> | pg$1.SQLiteTextBuilderInitial<string, [string, ...string[]], number | undefined> | drizzle_orm0.$Type<pg$1.SQLiteCustomColumnBuilder<{
|
|
@@ -1926,7 +1938,7 @@ interface D1ExecResult {
|
|
|
1926
1938
|
*/
|
|
1927
1939
|
declare class CloudflareD1Provider extends DatabaseProvider {
|
|
1928
1940
|
protected readonly kit: DrizzleKitProvider;
|
|
1929
|
-
protected readonly log:
|
|
1941
|
+
protected readonly log: alepha_logger3.Logger;
|
|
1930
1942
|
protected readonly builder: SqliteModelBuilder;
|
|
1931
1943
|
protected readonly env: {
|
|
1932
1944
|
DATABASE_URL: string;
|
|
@@ -1934,24 +1946,47 @@ declare class CloudflareD1Provider extends DatabaseProvider {
|
|
|
1934
1946
|
protected d1?: D1Database;
|
|
1935
1947
|
protected drizzleDb?: DrizzleD1Database;
|
|
1936
1948
|
get name(): string;
|
|
1949
|
+
get driver(): string;
|
|
1937
1950
|
readonly dialect = "sqlite";
|
|
1938
1951
|
get url(): string;
|
|
1939
1952
|
get db(): PgDatabase<any>;
|
|
1940
1953
|
execute(query: SQLLike): Promise<Array<Record<string, unknown>>>;
|
|
1941
|
-
protected readonly onStart:
|
|
1954
|
+
protected readonly onStart: alepha34.HookPrimitive<"start">;
|
|
1942
1955
|
protected executeMigrations(migrationsFolder: string): Promise<void>;
|
|
1943
1956
|
/**
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1957
|
+
* Override development migration to skip sync (not supported on D1).
|
|
1958
|
+
* D1 requires proper migrations to be applied.
|
|
1959
|
+
*/
|
|
1947
1960
|
protected runDevelopmentMigration(migrationsFolder: string): Promise<void>;
|
|
1948
1961
|
/**
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1962
|
+
* Override test migration to run migrations instead of sync.
|
|
1963
|
+
* D1 doesn't support schema synchronization.
|
|
1964
|
+
*/
|
|
1952
1965
|
protected runTestMigration(): Promise<void>;
|
|
1953
1966
|
}
|
|
1954
1967
|
//#endregion
|
|
1968
|
+
//#region ../../src/orm/providers/RepositoryProvider.d.ts
|
|
1969
|
+
declare class RepositoryProvider {
|
|
1970
|
+
protected readonly alepha: Alepha;
|
|
1971
|
+
protected readonly registry: Map<EntityPrimitive<any>, Service<Repository<any>>>;
|
|
1972
|
+
getRepositories(provider?: DatabaseProvider): Repository<TObject<alepha34.TProperties>>[];
|
|
1973
|
+
getRepository<T extends TObject>(entity: EntityPrimitive<T>): Repository<T>;
|
|
1974
|
+
createClassRepository<T extends TObject>(entity: EntityPrimitive<T>): Service<Repository<T>>;
|
|
1975
|
+
}
|
|
1976
|
+
//#endregion
|
|
1977
|
+
//#region ../../src/orm/types/schema.d.ts
|
|
1978
|
+
/**
|
|
1979
|
+
* Postgres schema type.
|
|
1980
|
+
*/
|
|
1981
|
+
declare const schema: <TDocument extends TSchema>(name: string, document: TDocument) => drizzle_orm0.$Type<drizzle_orm_pg_core0.PgCustomColumnBuilder<{
|
|
1982
|
+
name: string;
|
|
1983
|
+
dataType: "custom";
|
|
1984
|
+
columnType: "PgCustomColumn";
|
|
1985
|
+
data: typebox1.StaticType<[], "Decode", {}, {}, TDocument>;
|
|
1986
|
+
driverParam: string;
|
|
1987
|
+
enumValues: undefined;
|
|
1988
|
+
}>, typebox1.StaticType<[], "Decode", {}, {}, TDocument>>;
|
|
1989
|
+
//#endregion
|
|
1955
1990
|
//#region ../../src/orm/services/PostgresModelBuilder.d.ts
|
|
1956
1991
|
declare class PostgresModelBuilder extends ModelBuilder {
|
|
1957
1992
|
protected schemas: Map<string, drizzle_orm_pg_core0.PgSchema<string>>;
|
|
@@ -1966,17 +2001,17 @@ declare class PostgresModelBuilder extends ModelBuilder {
|
|
|
1966
2001
|
schema: string;
|
|
1967
2002
|
}): void;
|
|
1968
2003
|
/**
|
|
1969
|
-
|
|
1970
|
-
|
|
2004
|
+
* Get PostgreSQL-specific config builder for the table.
|
|
2005
|
+
*/
|
|
1971
2006
|
protected getTableConfig(entity: EntityPrimitive, tables: Map<string, unknown>): ((self: BuildExtraConfigColumns<string, any, "pg">) => PgTableExtraConfigValue[]) | undefined;
|
|
1972
2007
|
schemaToPgColumns: <T extends TObject>(tableName: string, schema: T, nsp: PgSchema, enums: Map<string, unknown>, tables: Map<string, unknown>) => FromSchema<T>;
|
|
1973
2008
|
mapFieldToColumn: (tableName: string, fieldName: string, value: TSchema, nsp: PgSchema, enums: Map<string, any>) => any;
|
|
1974
2009
|
/**
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2010
|
+
* Map a string to a PG column.
|
|
2011
|
+
*
|
|
2012
|
+
* @param key The key of the field.
|
|
2013
|
+
* @param value The value of the field.
|
|
2014
|
+
*/
|
|
1980
2015
|
mapStringToColumn: (key: string, value: TSchema) => drizzle_orm_pg_core0.PgUUIDBuilderInitial<string> | drizzle_orm_pg_core0.PgCustomColumnBuilder<{
|
|
1981
2016
|
name: string;
|
|
1982
2017
|
dataType: "custom";
|
|
@@ -1987,29 +2022,161 @@ declare class PostgresModelBuilder extends ModelBuilder {
|
|
|
1987
2022
|
}> | drizzle_orm_pg_core0.PgTimestampStringBuilderInitial<string> | drizzle_orm_pg_core0.PgDateStringBuilderInitial<string> | drizzle_orm_pg_core0.PgTextBuilderInitial<string, [string, ...string[]]>;
|
|
1988
2023
|
}
|
|
1989
2024
|
//#endregion
|
|
2025
|
+
//#region ../../src/orm/providers/drivers/BunPostgresProvider.d.ts
|
|
2026
|
+
declare module "alepha" {
|
|
2027
|
+
interface Env extends Partial<Static<typeof envSchema$1>> {}
|
|
2028
|
+
}
|
|
2029
|
+
declare const envSchema$1: alepha34.TObject<{
|
|
2030
|
+
/**
|
|
2031
|
+
* Main configuration for database connection.
|
|
2032
|
+
* Accept a string in the format of a Postgres connection URL.
|
|
2033
|
+
* Example: postgres://user:password@localhost:5432/database
|
|
2034
|
+
* or
|
|
2035
|
+
* Example: postgres://user:password@localhost:5432/database?sslmode=require
|
|
2036
|
+
*/
|
|
2037
|
+
DATABASE_URL: alepha34.TOptional<alepha34.TString>;
|
|
2038
|
+
/**
|
|
2039
|
+
* In addition to the DATABASE_URL, you can specify the postgres schema name.
|
|
2040
|
+
*/
|
|
2041
|
+
POSTGRES_SCHEMA: alepha34.TOptional<alepha34.TString>;
|
|
2042
|
+
}>;
|
|
2043
|
+
/**
|
|
2044
|
+
* Bun PostgreSQL provider using Drizzle ORM with Bun's native SQL client.
|
|
2045
|
+
*
|
|
2046
|
+
* This provider uses Bun's built-in SQL class for PostgreSQL connections,
|
|
2047
|
+
* which provides excellent performance on the Bun runtime.
|
|
2048
|
+
*
|
|
2049
|
+
* @example
|
|
2050
|
+
* ```ts
|
|
2051
|
+
* // Set DATABASE_URL environment variable
|
|
2052
|
+
* // DATABASE_URL=postgres://user:password@localhost:5432/database
|
|
2053
|
+
*
|
|
2054
|
+
* // Or configure programmatically
|
|
2055
|
+
* alepha.with({
|
|
2056
|
+
* provide: DatabaseProvider,
|
|
2057
|
+
* use: BunPostgresProvider,
|
|
2058
|
+
* });
|
|
2059
|
+
* ```
|
|
2060
|
+
*/
|
|
2061
|
+
declare class BunPostgresProvider extends DatabaseProvider {
|
|
2062
|
+
protected readonly log: alepha_logger3.Logger;
|
|
2063
|
+
protected readonly env: {
|
|
2064
|
+
DATABASE_URL?: string | undefined;
|
|
2065
|
+
POSTGRES_SCHEMA?: string | undefined;
|
|
2066
|
+
};
|
|
2067
|
+
protected readonly kit: DrizzleKitProvider;
|
|
2068
|
+
protected readonly builder: PostgresModelBuilder;
|
|
2069
|
+
protected client?: Bun.SQL;
|
|
2070
|
+
protected bunDb?: BunSQLDatabase;
|
|
2071
|
+
readonly dialect = "postgresql";
|
|
2072
|
+
get name(): string;
|
|
2073
|
+
/**
|
|
2074
|
+
* In testing mode, the schema name will be generated and deleted after the test.
|
|
2075
|
+
*/
|
|
2076
|
+
protected schemaForTesting: string | undefined;
|
|
2077
|
+
get url(): string;
|
|
2078
|
+
/**
|
|
2079
|
+
* Execute a SQL statement.
|
|
2080
|
+
*/
|
|
2081
|
+
execute(statement: SQLLike): Promise<Array<Record<string, unknown>>>;
|
|
2082
|
+
/**
|
|
2083
|
+
* Get Postgres schema used by this provider.
|
|
2084
|
+
*/
|
|
2085
|
+
get schema(): string;
|
|
2086
|
+
/**
|
|
2087
|
+
* Get the Drizzle Postgres database instance.
|
|
2088
|
+
*/
|
|
2089
|
+
get db(): PgDatabase<any>;
|
|
2090
|
+
protected executeMigrations(migrationsFolder: string): Promise<void>;
|
|
2091
|
+
protected readonly onStart: alepha34.HookPrimitive<"start">;
|
|
2092
|
+
protected readonly onStop: alepha34.HookPrimitive<"stop">;
|
|
2093
|
+
connect(): Promise<void>;
|
|
2094
|
+
close(): Promise<void>;
|
|
2095
|
+
protected migrateLock: alepha_lock0.LockPrimitive<() => Promise<void>>;
|
|
2096
|
+
}
|
|
2097
|
+
//#endregion
|
|
2098
|
+
//#region ../../src/orm/providers/drivers/BunSqliteProvider.d.ts
|
|
2099
|
+
/**
|
|
2100
|
+
* Configuration options for the Bun SQLite database provider.
|
|
2101
|
+
*/
|
|
2102
|
+
declare const bunSqliteOptions: alepha34.Atom<alepha34.TObject<{
|
|
2103
|
+
path: alepha34.TOptional<alepha34.TString>;
|
|
2104
|
+
}>, "alepha.postgres.bun-sqlite.options">;
|
|
2105
|
+
type BunSqliteProviderOptions = Static<typeof bunSqliteOptions.schema>;
|
|
2106
|
+
declare module "alepha" {
|
|
2107
|
+
interface State {
|
|
2108
|
+
[bunSqliteOptions.key]: BunSqliteProviderOptions;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* Bun SQLite provider using Drizzle ORM with Bun's native SQLite client.
|
|
2113
|
+
*
|
|
2114
|
+
* This provider uses Bun's built-in `bun:sqlite` for SQLite connections,
|
|
2115
|
+
* which provides excellent performance on the Bun runtime.
|
|
2116
|
+
*
|
|
2117
|
+
* @example
|
|
2118
|
+
* ```ts
|
|
2119
|
+
* // Set DATABASE_URL environment variable
|
|
2120
|
+
* // DATABASE_URL=sqlite://./my-database.db
|
|
2121
|
+
*
|
|
2122
|
+
* // Or configure programmatically
|
|
2123
|
+
* alepha.with({
|
|
2124
|
+
* provide: DatabaseProvider,
|
|
2125
|
+
* use: BunSqliteProvider,
|
|
2126
|
+
* });
|
|
2127
|
+
*
|
|
2128
|
+
* // Or use options atom
|
|
2129
|
+
* alepha.store.mut(bunSqliteOptions, (old) => ({
|
|
2130
|
+
* ...old,
|
|
2131
|
+
* path: ":memory:",
|
|
2132
|
+
* }));
|
|
2133
|
+
* ```
|
|
2134
|
+
*/
|
|
2135
|
+
declare class BunSqliteProvider extends DatabaseProvider {
|
|
2136
|
+
protected readonly kit: DrizzleKitProvider;
|
|
2137
|
+
protected readonly log: alepha_logger3.Logger;
|
|
2138
|
+
protected readonly env: {
|
|
2139
|
+
DATABASE_URL?: string | undefined;
|
|
2140
|
+
};
|
|
2141
|
+
protected readonly builder: SqliteModelBuilder;
|
|
2142
|
+
protected readonly options: Readonly<{
|
|
2143
|
+
path?: string | undefined;
|
|
2144
|
+
}>;
|
|
2145
|
+
protected sqlite?: Database;
|
|
2146
|
+
protected bunDb?: BunSQLiteDatabase;
|
|
2147
|
+
get name(): string;
|
|
2148
|
+
readonly dialect = "sqlite";
|
|
2149
|
+
get url(): string;
|
|
2150
|
+
get db(): PgDatabase<any>;
|
|
2151
|
+
execute(query: SQLLike): Promise<Array<Record<string, unknown>>>;
|
|
2152
|
+
protected readonly onStart: alepha34.HookPrimitive<"start">;
|
|
2153
|
+
protected readonly onStop: alepha34.HookPrimitive<"stop">;
|
|
2154
|
+
protected executeMigrations(migrationsFolder: string): Promise<void>;
|
|
2155
|
+
}
|
|
2156
|
+
//#endregion
|
|
1990
2157
|
//#region ../../src/orm/providers/drivers/NodePostgresProvider.d.ts
|
|
1991
2158
|
declare module "alepha" {
|
|
1992
2159
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
1993
2160
|
}
|
|
1994
|
-
declare const envSchema:
|
|
1995
|
-
/**
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
DATABASE_URL:
|
|
2003
|
-
/**
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
POSTGRES_SCHEMA:
|
|
2161
|
+
declare const envSchema: alepha34.TObject<{
|
|
2162
|
+
/**
|
|
2163
|
+
* Main configuration for database connection.
|
|
2164
|
+
* Accept a string in the format of a Postgres connection URL.
|
|
2165
|
+
* Example: postgres://user:password@localhost:5432/database
|
|
2166
|
+
* or
|
|
2167
|
+
* Example: postgres://user:password@localhost:5432/database?sslmode=require
|
|
2168
|
+
*/
|
|
2169
|
+
DATABASE_URL: alepha34.TOptional<alepha34.TString>;
|
|
2170
|
+
/**
|
|
2171
|
+
* In addition to the DATABASE_URL, you can specify the postgres schema name.
|
|
2172
|
+
*
|
|
2173
|
+
* It will monkey patch drizzle tables.
|
|
2174
|
+
*/
|
|
2175
|
+
POSTGRES_SCHEMA: alepha34.TOptional<alepha34.TString>;
|
|
2009
2176
|
}>;
|
|
2010
2177
|
declare class NodePostgresProvider extends DatabaseProvider {
|
|
2011
2178
|
static readonly SSL_MODES: readonly ["require", "allow", "prefer", "verify-full"];
|
|
2012
|
-
protected readonly log:
|
|
2179
|
+
protected readonly log: alepha_logger3.Logger;
|
|
2013
2180
|
protected readonly env: {
|
|
2014
2181
|
DATABASE_URL?: string | undefined;
|
|
2015
2182
|
POSTGRES_SCHEMA?: string | undefined;
|
|
@@ -2021,31 +2188,31 @@ declare class NodePostgresProvider extends DatabaseProvider {
|
|
|
2021
2188
|
readonly dialect = "postgresql";
|
|
2022
2189
|
get name(): string;
|
|
2023
2190
|
/**
|
|
2024
|
-
|
|
2025
|
-
|
|
2191
|
+
* In testing mode, the schema name will be generated and deleted after the test.
|
|
2192
|
+
*/
|
|
2026
2193
|
protected schemaForTesting: string | undefined;
|
|
2027
2194
|
get url(): string;
|
|
2028
2195
|
/**
|
|
2029
|
-
|
|
2030
|
-
|
|
2196
|
+
* Execute a SQL statement.
|
|
2197
|
+
*/
|
|
2031
2198
|
execute(statement: SQLLike): Promise<Array<Record<string, unknown>>>;
|
|
2032
2199
|
/**
|
|
2033
|
-
|
|
2034
|
-
|
|
2200
|
+
* Get Postgres schema used by this provider.
|
|
2201
|
+
*/
|
|
2035
2202
|
get schema(): string;
|
|
2036
2203
|
/**
|
|
2037
|
-
|
|
2038
|
-
|
|
2204
|
+
* Get the Drizzle Postgres database instance.
|
|
2205
|
+
*/
|
|
2039
2206
|
get db(): PostgresJsDatabase;
|
|
2040
2207
|
protected executeMigrations(migrationsFolder: string): Promise<void>;
|
|
2041
|
-
protected readonly onStart:
|
|
2042
|
-
protected readonly onStop:
|
|
2208
|
+
protected readonly onStart: alepha34.HookPrimitive<"start">;
|
|
2209
|
+
protected readonly onStop: alepha34.HookPrimitive<"stop">;
|
|
2043
2210
|
connect(): Promise<void>;
|
|
2044
2211
|
close(): Promise<void>;
|
|
2045
2212
|
protected migrateLock: alepha_lock0.LockPrimitive<() => Promise<void>>;
|
|
2046
2213
|
/**
|
|
2047
|
-
|
|
2048
|
-
|
|
2214
|
+
* Map the DATABASE_URL to postgres client options.
|
|
2215
|
+
*/
|
|
2049
2216
|
protected getClientOptions(): postgres.Options<any>;
|
|
2050
2217
|
protected ssl(url: URL): "require" | "allow" | "prefer" | "verify-full" | undefined;
|
|
2051
2218
|
}
|
|
@@ -2054,8 +2221,8 @@ declare class NodePostgresProvider extends DatabaseProvider {
|
|
|
2054
2221
|
/**
|
|
2055
2222
|
* Configuration options for the Node.js SQLite database provider.
|
|
2056
2223
|
*/
|
|
2057
|
-
declare const nodeSqliteOptions:
|
|
2058
|
-
path:
|
|
2224
|
+
declare const nodeSqliteOptions: alepha34.Atom<alepha34.TObject<{
|
|
2225
|
+
path: alepha34.TOptional<alepha34.TString>;
|
|
2059
2226
|
}>, "alepha.postgres.node-sqlite.options">;
|
|
2060
2227
|
type NodeSqliteProviderOptions = Static<typeof nodeSqliteOptions.schema>;
|
|
2061
2228
|
declare module "alepha" {
|
|
@@ -2071,7 +2238,7 @@ declare module "alepha" {
|
|
|
2071
2238
|
*/
|
|
2072
2239
|
declare class NodeSqliteProvider extends DatabaseProvider {
|
|
2073
2240
|
protected readonly kit: DrizzleKitProvider;
|
|
2074
|
-
protected readonly log:
|
|
2241
|
+
protected readonly log: alepha_logger3.Logger;
|
|
2075
2242
|
protected readonly env: {
|
|
2076
2243
|
DATABASE_URL?: string | undefined;
|
|
2077
2244
|
};
|
|
@@ -2085,67 +2252,40 @@ declare class NodeSqliteProvider extends DatabaseProvider {
|
|
|
2085
2252
|
get url(): string;
|
|
2086
2253
|
execute(query: SQLLike): Promise<Array<Record<string, unknown>>>;
|
|
2087
2254
|
readonly db: PgDatabase<any>;
|
|
2088
|
-
protected readonly onStart:
|
|
2255
|
+
protected readonly onStart: alepha34.HookPrimitive<"start">;
|
|
2089
2256
|
protected executeMigrations(migrationsFolder: string): Promise<void>;
|
|
2090
2257
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
declare class RepositoryProvider {
|
|
2094
|
-
protected readonly alepha: Alepha;
|
|
2095
|
-
protected readonly registry: Map<EntityPrimitive<any>, Service<Repository<any>>>;
|
|
2096
|
-
getRepositories(provider?: DatabaseProvider): Repository<TObject<alepha2.TProperties>>[];
|
|
2097
|
-
getRepository<T extends TObject>(entity: EntityPrimitive<T>): Repository<T>;
|
|
2098
|
-
createClassRepository<T extends TObject>(entity: EntityPrimitive<T>): Service<Repository<T>>;
|
|
2258
|
+
declare namespace index_d_exports {
|
|
2259
|
+
export { $entity, $repository, $sequence, $transaction, AlephaPostgres, BunPostgresProvider, BunSqliteProvider, BunSqliteProviderOptions, CloudflareD1Provider, D1Database, D1ExecResult, D1PreparedStatement, D1Result, DatabaseProvider, DatabaseTypeProvider, DbConflictError, DbEntityNotFoundError, DbError, DbMigrationError, DbVersionMismatchError, DrizzleKitProvider, EntityColumn, EntityColumns, EntityPrimitive, EntityPrimitiveOptions, FilterOperators, FromSchema, NodePostgresProvider, NodeSqliteProvider, NodeSqliteProviderOptions, OrderBy, OrderByClause, OrderDirection, PG_CREATED_AT, PG_DEFAULT, PG_DELETED_AT, PG_ENUM, PG_IDENTITY, PG_PRIMARY_KEY, PG_REF, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, Page, PageQuery, PgAttr, PgAttrField, PgDefault, PgEnumOptions, PgIdentityOptions, PgPrimaryKey, PgQuery, PgQueryRelations, PgQueryWhere, PgQueryWhereOrSQL, PgRef, PgRefOptions, PgRelation, PgRelationMap, PgStatic, PgSymbolKeys, PgSymbols, Repository, RepositoryProvider, SQLLike, SchemaToTableConfig, SequencePrimitive, SequencePrimitiveOptions, StatementOptions, TObjectInsert, TObjectUpdate, TransactionContext, TransactionPrimitiveOptions, buildQueryString, bunSqliteOptions, db, drizzle_orm0 as drizzle, getAttrFields, insertSchema, legacyIdSchema, nodeSqliteOptions, pageQuerySchema, pageSchema, parseQueryString, pg, pgAttr, schema, sql, updateSchema };
|
|
2099
2260
|
}
|
|
2100
|
-
//#endregion
|
|
2101
|
-
//#region ../../src/orm/schemas/legacyIdSchema.d.ts
|
|
2102
|
-
/**
|
|
2103
|
-
* @deprecated Use `pg.primaryKey()` instead.
|
|
2104
|
-
*/
|
|
2105
|
-
declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<alepha2.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
|
|
2106
|
-
//#endregion
|
|
2107
|
-
//#region ../../src/orm/types/schema.d.ts
|
|
2108
|
-
/**
|
|
2109
|
-
* Postgres schema type.
|
|
2110
|
-
*/
|
|
2111
|
-
declare const schema: <TDocument extends TSchema>(name: string, document: TDocument) => drizzle_orm0.$Type<drizzle_orm_pg_core0.PgCustomColumnBuilder<{
|
|
2112
|
-
name: string;
|
|
2113
|
-
dataType: "custom";
|
|
2114
|
-
columnType: "PgCustomColumn";
|
|
2115
|
-
data: typebox1.StaticType<[], "Decode", {}, {}, TDocument>;
|
|
2116
|
-
driverParam: string;
|
|
2117
|
-
enumValues: undefined;
|
|
2118
|
-
}>, typebox1.StaticType<[], "Decode", {}, {}, TDocument>>;
|
|
2119
|
-
//#endregion
|
|
2120
|
-
//#region ../../src/orm/index.d.ts
|
|
2121
2261
|
declare module "alepha" {
|
|
2122
2262
|
interface Hooks {
|
|
2123
2263
|
/**
|
|
2124
|
-
|
|
2125
|
-
|
|
2264
|
+
* Fires before creating an entity in the repository.
|
|
2265
|
+
*/
|
|
2126
2266
|
"repository:create:before": {
|
|
2127
2267
|
tableName: string;
|
|
2128
2268
|
data: any;
|
|
2129
2269
|
};
|
|
2130
2270
|
/**
|
|
2131
|
-
|
|
2132
|
-
|
|
2271
|
+
* Fires after creating an entity in the repository.
|
|
2272
|
+
*/
|
|
2133
2273
|
"repository:create:after": {
|
|
2134
2274
|
tableName: string;
|
|
2135
2275
|
data: any;
|
|
2136
2276
|
entity: any;
|
|
2137
2277
|
};
|
|
2138
2278
|
/**
|
|
2139
|
-
|
|
2140
|
-
|
|
2279
|
+
* Fires before updating entities in the repository.
|
|
2280
|
+
*/
|
|
2141
2281
|
"repository:update:before": {
|
|
2142
2282
|
tableName: string;
|
|
2143
2283
|
where: any;
|
|
2144
2284
|
data: any;
|
|
2145
2285
|
};
|
|
2146
2286
|
/**
|
|
2147
|
-
|
|
2148
|
-
|
|
2287
|
+
* Fires after updating entities in the repository.
|
|
2288
|
+
*/
|
|
2149
2289
|
"repository:update:after": {
|
|
2150
2290
|
tableName: string;
|
|
2151
2291
|
where: any;
|
|
@@ -2153,30 +2293,30 @@ declare module "alepha" {
|
|
|
2153
2293
|
entities: any[];
|
|
2154
2294
|
};
|
|
2155
2295
|
/**
|
|
2156
|
-
|
|
2157
|
-
|
|
2296
|
+
* Fires before deleting entities from the repository.
|
|
2297
|
+
*/
|
|
2158
2298
|
"repository:delete:before": {
|
|
2159
2299
|
tableName: string;
|
|
2160
2300
|
where: any;
|
|
2161
2301
|
};
|
|
2162
2302
|
/**
|
|
2163
|
-
|
|
2164
|
-
|
|
2303
|
+
* Fires after deleting entities from the repository.
|
|
2304
|
+
*/
|
|
2165
2305
|
"repository:delete:after": {
|
|
2166
2306
|
tableName: string;
|
|
2167
2307
|
where: any;
|
|
2168
2308
|
ids: Array<string | number>;
|
|
2169
2309
|
};
|
|
2170
2310
|
/**
|
|
2171
|
-
|
|
2172
|
-
|
|
2311
|
+
* Fires before reading entities from the repository.
|
|
2312
|
+
*/
|
|
2173
2313
|
"repository:read:before": {
|
|
2174
2314
|
tableName: string;
|
|
2175
2315
|
query: any;
|
|
2176
2316
|
};
|
|
2177
2317
|
/**
|
|
2178
|
-
|
|
2179
|
-
|
|
2318
|
+
* Fires after reading entities from the repository.
|
|
2319
|
+
*/
|
|
2180
2320
|
"repository:read:after": {
|
|
2181
2321
|
tableName: string;
|
|
2182
2322
|
query: any;
|
|
@@ -2187,6 +2327,10 @@ declare module "alepha" {
|
|
|
2187
2327
|
/**
|
|
2188
2328
|
* Postgres client based on Drizzle ORM, Alepha type-safe friendly.
|
|
2189
2329
|
*
|
|
2330
|
+
* Automatically selects the appropriate provider based on runtime:
|
|
2331
|
+
* - Bun: Uses `BunPostgresProvider` or `BunSqliteProvider`
|
|
2332
|
+
* - Node.js: Uses `NodePostgresProvider` or `NodeSqliteProvider`
|
|
2333
|
+
*
|
|
2190
2334
|
* ```ts
|
|
2191
2335
|
* import { t } from "alepha";
|
|
2192
2336
|
* import { $entity, $repository, db } from "alepha/postgres";
|
|
@@ -2225,9 +2369,13 @@ declare module "alepha" {
|
|
|
2225
2369
|
* @see {@link $sequence}
|
|
2226
2370
|
* @see {@link $repository}
|
|
2227
2371
|
* @see {@link $transaction}
|
|
2372
|
+
* @see {@link NodePostgresProvider} - Node.js Postgres implementation
|
|
2373
|
+
* @see {@link NodeSqliteProvider} - Node.js SQLite implementation
|
|
2374
|
+
* @see {@link BunPostgresProvider} - Bun Postgres implementation
|
|
2375
|
+
* @see {@link BunSqliteProvider} - Bun SQLite implementation
|
|
2228
2376
|
* @module alepha.postgres
|
|
2229
2377
|
*/
|
|
2230
|
-
declare const AlephaPostgres:
|
|
2378
|
+
declare const AlephaPostgres: alepha34.Service<alepha34.Module>;
|
|
2231
2379
|
//#endregion
|
|
2232
|
-
export { $entity, $repository, $sequence, $transaction, AlephaPostgres, CloudflareD1Provider, D1Database, D1ExecResult, D1PreparedStatement, D1Result, DatabaseProvider, DatabaseTypeProvider, DbConflictError, DbEntityNotFoundError, DbError, DbMigrationError, DbVersionMismatchError, DrizzleKitProvider, EntityColumn, EntityColumns, EntityPrimitive, EntityPrimitiveOptions, FilterOperators, FromSchema, NodePostgresProvider, NodeSqliteProvider, NodeSqliteProviderOptions, OrderBy, OrderByClause, OrderDirection, PG_CREATED_AT, PG_DEFAULT, PG_DELETED_AT, PG_ENUM, PG_IDENTITY, PG_PRIMARY_KEY, PG_REF, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, type Page, type PageQuery, PgAttr, PgAttrField, PgDefault, PgEnumOptions, PgIdentityOptions, PgPrimaryKey, PgQuery, PgQueryRelations, PgQueryWhere, PgQueryWhereOrSQL, PgRef, PgRefOptions, PgRelation, PgRelationMap, PgStatic, PgSymbolKeys, PgSymbols, Repository, RepositoryProvider, SQLLike, SchemaToTableConfig, SequencePrimitive, SequencePrimitiveOptions, StatementOptions, TObjectInsert, TObjectUpdate, TransactionContext, TransactionPrimitiveOptions, buildQueryString, db, drizzle_orm0 as drizzle, getAttrFields, insertSchema, legacyIdSchema, nodeSqliteOptions, pageQuerySchema, pageSchema, parseQueryString, pg, pgAttr, schema, sql, updateSchema };
|
|
2380
|
+
export { $entity, $repository, $sequence, $transaction, AlephaPostgres, BunPostgresProvider, BunSqliteProvider, BunSqliteProviderOptions, CloudflareD1Provider, D1Database, D1ExecResult, D1PreparedStatement, D1Result, DatabaseProvider, DatabaseTypeProvider, DbConflictError, DbEntityNotFoundError, DbError, DbMigrationError, DbVersionMismatchError, DrizzleKitProvider, EntityColumn, EntityColumns, EntityPrimitive, EntityPrimitiveOptions, FilterOperators, FromSchema, NodePostgresProvider, NodeSqliteProvider, NodeSqliteProviderOptions, OrderBy, OrderByClause, OrderDirection, PG_CREATED_AT, PG_DEFAULT, PG_DELETED_AT, PG_ENUM, PG_IDENTITY, PG_PRIMARY_KEY, PG_REF, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, type Page, type PageQuery, PgAttr, PgAttrField, PgDefault, PgEnumOptions, PgIdentityOptions, PgPrimaryKey, PgQuery, PgQueryRelations, PgQueryWhere, PgQueryWhereOrSQL, PgRef, PgRefOptions, PgRelation, PgRelationMap, PgStatic, PgSymbolKeys, PgSymbols, Repository, RepositoryProvider, SQLLike, SchemaToTableConfig, SequencePrimitive, SequencePrimitiveOptions, StatementOptions, TObjectInsert, TObjectUpdate, TransactionContext, TransactionPrimitiveOptions, buildQueryString, bunSqliteOptions, db, drizzle_orm0 as drizzle, getAttrFields, insertSchema, legacyIdSchema, nodeSqliteOptions, pageQuerySchema, pageSchema, parseQueryString, pg, pgAttr, schema, sql, updateSchema };
|
|
2233
2381
|
//# sourceMappingURL=index.d.ts.map
|