drizzle-orm 0.27.3-e080bed → 0.28.0-5dd9190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/{alias-5aeeb2f5.cjs → alias-3f5ac719.cjs} +267 -142
  2. package/alias-3f5ac719.cjs.map +1 -0
  3. package/{alias-6eaa2e87.mjs → alias-7164ff43.mjs} +223 -126
  4. package/alias-7164ff43.mjs.map +1 -0
  5. package/aws-data-api/pg/index.cjs +1 -1
  6. package/aws-data-api/pg/index.d.ts +4 -4
  7. package/aws-data-api/pg/index.mjs +2 -2
  8. package/aws-data-api/pg/migrator.d.ts +4 -4
  9. package/better-sqlite3/index.cjs +2 -2
  10. package/better-sqlite3/index.d.ts +5 -5
  11. package/better-sqlite3/index.mjs +2 -2
  12. package/better-sqlite3/migrator.d.ts +5 -5
  13. package/bun-sqlite/index.cjs +2 -2
  14. package/bun-sqlite/index.d.ts +5 -5
  15. package/bun-sqlite/index.mjs +2 -2
  16. package/bun-sqlite/migrator.d.ts +5 -5
  17. package/column.d-9d2f4045.d.ts +1151 -0
  18. package/d1/index.cjs +2 -2
  19. package/d1/index.d.ts +5 -5
  20. package/d1/index.mjs +2 -2
  21. package/d1/migrator.d.ts +5 -5
  22. package/{driver.d-58d095ec.d.ts → driver.d-055d4782.d.ts} +2 -2
  23. package/{driver.d-d2f034d7.d.ts → driver.d-20707624.d.ts} +2 -2
  24. package/{driver.d-7f308b1e.d.ts → driver.d-ab0f126f.d.ts} +2 -2
  25. package/{driver.d-f55c470d.d.ts → driver.d-b8dd753f.d.ts} +2 -2
  26. package/{driver.d-28b0b849.d.ts → driver.d-c4dd56f7.d.ts} +2 -2
  27. package/{driver.d-53ed595e.d.ts → driver.d-eb654ed5.d.ts} +2 -2
  28. package/index.cjs +3 -3
  29. package/index.d.ts +4 -4
  30. package/index.mjs +2 -2
  31. package/knex/index.d.ts +1 -1
  32. package/kysely/index.d.ts +1 -1
  33. package/libsql/index.cjs +2 -2
  34. package/libsql/index.d.ts +5 -5
  35. package/libsql/index.mjs +2 -2
  36. package/libsql/migrator.d.ts +5 -5
  37. package/mysql-core/index.cjs +57 -21
  38. package/mysql-core/index.cjs.map +1 -1
  39. package/mysql-core/index.d.ts +184 -344
  40. package/mysql-core/index.mjs +58 -22
  41. package/mysql-core/index.mjs.map +1 -1
  42. package/mysql2/index.cjs +14 -10
  43. package/mysql2/index.cjs.map +1 -1
  44. package/mysql2/index.d.ts +16 -12
  45. package/mysql2/index.mjs +15 -11
  46. package/mysql2/index.mjs.map +1 -1
  47. package/mysql2/migrator.d.ts +4 -4
  48. package/neon-http/index.cjs +1 -1
  49. package/neon-http/index.d.ts +4 -4
  50. package/neon-http/index.mjs +2 -2
  51. package/neon-http/migrator.cjs +1 -1
  52. package/neon-http/migrator.d.ts +4 -4
  53. package/neon-http/migrator.mjs +1 -1
  54. package/neon-serverless/index.cjs +1 -1
  55. package/neon-serverless/index.d.ts +4 -4
  56. package/neon-serverless/index.mjs +2 -2
  57. package/neon-serverless/migrator.d.ts +4 -4
  58. package/node-postgres/index.cjs +1 -1
  59. package/node-postgres/index.d.ts +4 -4
  60. package/node-postgres/index.mjs +2 -2
  61. package/node-postgres/migrator.d.ts +4 -4
  62. package/package.json +3 -3
  63. package/pg-core/index.cjs +1 -1
  64. package/pg-core/index.cjs.map +1 -1
  65. package/pg-core/index.d.ts +207 -373
  66. package/pg-core/index.mjs +48 -18
  67. package/pg-core/index.mjs.map +1 -1
  68. package/planetscale-serverless/index.cjs +5 -5
  69. package/planetscale-serverless/index.cjs.map +1 -1
  70. package/planetscale-serverless/index.d.ts +5 -5
  71. package/planetscale-serverless/index.mjs +5 -5
  72. package/planetscale-serverless/index.mjs.map +1 -1
  73. package/planetscale-serverless/migrator.d.ts +4 -4
  74. package/postgres-js/index.cjs +1 -1
  75. package/postgres-js/index.d.ts +4 -4
  76. package/postgres-js/index.mjs +2 -2
  77. package/postgres-js/migrator.d.ts +4 -4
  78. package/{query-promise.d-fd15f63a.d.ts → query-promise.d-bc96befc.d.ts} +48 -45
  79. package/{db.d-2e828d8c.d.ts → select.types.d-570dd25a.d.ts} +281 -465
  80. package/{select.types.d-35b6e089.d.ts → select.types.d-73209a67.d.ts} +47 -258
  81. package/{select.types.d-1ea8ee3b.d.ts → select.types.d-a3c4c974.d.ts} +20 -19
  82. package/{db.d-9d586c00.d.ts → select.types.d-d0a10728.d.ts} +471 -731
  83. package/{session-c47f12d9.mjs → session-0c131cde.mjs} +2 -2
  84. package/{session-c47f12d9.mjs.map → session-0c131cde.mjs.map} +1 -1
  85. package/{session-2431f9e1.mjs → session-16f863cd.mjs} +36 -64
  86. package/session-16f863cd.mjs.map +1 -0
  87. package/{session-6bfef963.cjs → session-805d2876.cjs} +64 -131
  88. package/session-805d2876.cjs.map +1 -0
  89. package/{session-fa99bfce.mjs → session-ac71392b.mjs} +67 -134
  90. package/session-ac71392b.mjs.map +1 -0
  91. package/{session-fa9720a5.cjs → session-e9306785.cjs} +61 -71
  92. package/session-e9306785.cjs.map +1 -0
  93. package/sql-js/index.cjs +2 -2
  94. package/sql-js/index.d.ts +5 -5
  95. package/sql-js/index.mjs +2 -2
  96. package/sql-js/migrator.d.ts +5 -5
  97. package/sqlite-core/index.cjs +2 -2
  98. package/sqlite-core/index.d.ts +83 -137
  99. package/sqlite-core/index.mjs +28 -10
  100. package/sqlite-core/index.mjs.map +1 -1
  101. package/sqlite-proxy/index.cjs +2 -2
  102. package/sqlite-proxy/index.d.ts +6 -6
  103. package/sqlite-proxy/index.mjs +2 -2
  104. package/sqlite-proxy/migrator.cjs +1 -1
  105. package/sqlite-proxy/migrator.d.ts +5 -5
  106. package/sqlite-proxy/migrator.mjs +1 -1
  107. package/vercel-postgres/index.cjs +1 -1
  108. package/vercel-postgres/index.d.ts +4 -4
  109. package/vercel-postgres/index.mjs +2 -2
  110. package/vercel-postgres/migrator.d.ts +4 -4
  111. package/version.cjs +1 -1
  112. package/version.d.ts +1 -1
  113. package/version.mjs +1 -1
  114. package/alias-5aeeb2f5.cjs.map +0 -1
  115. package/alias-6eaa2e87.mjs.map +0 -1
  116. package/column.d-9d74a4f3.d.ts +0 -558
  117. package/session-2431f9e1.mjs.map +0 -1
  118. package/session-6bfef963.cjs.map +0 -1
  119. package/session-fa9720a5.cjs.map +0 -1
  120. package/session-fa99bfce.mjs.map +0 -1
@@ -1,558 +0,0 @@
1
- declare const entityKind: unique symbol;
2
- declare const hasOwnEntityKind: unique symbol;
3
- interface DrizzleEntity {
4
- [entityKind]: string;
5
- }
6
- type DrizzleEntityClass<T> = ((abstract new (...args: any[]) => T) | (new (...args: any[]) => T)) & DrizzleEntity;
7
- declare function is<T extends DrizzleEntityClass<any>>(value: any, type: T): value is InstanceType<T>;
8
-
9
- interface Logger {
10
- logQuery(query: string, params: unknown[]): void;
11
- }
12
- interface LogWriter {
13
- write(message: string): void;
14
- }
15
- declare class ConsoleLogWriter implements LogWriter {
16
- static readonly [entityKind]: string;
17
- write(message: string): void;
18
- }
19
- declare class DefaultLogger implements Logger {
20
- static readonly [entityKind]: string;
21
- readonly writer: LogWriter;
22
- constructor(config?: {
23
- writer: LogWriter;
24
- });
25
- logQuery(query: string, params: unknown[]): void;
26
- }
27
- declare class NoopLogger implements Logger {
28
- static readonly [entityKind]: string;
29
- logQuery(): void;
30
- }
31
-
32
- type UpdateSet = Record<string, SQL | Param | null | undefined>;
33
- type OneOrMany<T> = T | T[];
34
- type Update<T, TUpdate> = SimplifyShallow<Omit<T, keyof TUpdate> & TUpdate>;
35
- /**
36
- @see Simplify
37
- */
38
- interface SimplifyOptions {
39
- /**
40
- Do the simplification recursively.
41
-
42
- @default false
43
- */
44
- deep?: boolean;
45
- }
46
- type Flatten<AnyType, Options extends SimplifyOptions = {}> = Options['deep'] extends true ? {
47
- [KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>;
48
- } : {
49
- [KeyType in keyof AnyType]: AnyType[KeyType];
50
- };
51
- /**
52
- Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
53
-
54
- @example
55
- ```
56
- import type {Simplify} from 'type-fest';
57
-
58
- type PositionProps = {
59
- top: number;
60
- left: number;
61
- };
62
-
63
- type SizeProps = {
64
- width: number;
65
- height: number;
66
- };
67
-
68
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
69
- type Props = Simplify<PositionProps & SizeProps>;
70
- ```
71
-
72
- Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
73
-
74
- If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
75
-
76
- @example
77
- ```
78
- import type {Simplify} from 'type-fest';
79
-
80
- interface SomeInterface {
81
- foo: number;
82
- bar?: string;
83
- baz: number | undefined;
84
- }
85
-
86
- type SomeType = {
87
- foo: number;
88
- bar?: string;
89
- baz: number | undefined;
90
- };
91
-
92
- const literal = {foo: 123, bar: 'hello', baz: 456};
93
- const someType: SomeType = literal;
94
- const someInterface: SomeInterface = literal;
95
-
96
- function fn(object: Record<string, unknown>): void {}
97
-
98
- fn(literal); // Good: literal object type is sealed
99
- fn(someType); // Good: type is sealed
100
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
101
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
102
- ```
103
-
104
- @link https://github.com/microsoft/TypeScript/issues/15300
105
-
106
- @category Object
107
- */
108
- type Simplify<AnyType, Options extends SimplifyOptions = {}> = Flatten<AnyType> extends AnyType ? Flatten<AnyType, Options> : AnyType;
109
- type SimplifyShallow<T> = {
110
- [K in keyof T]: T[K];
111
- } & {};
112
- type Assume<T, U> = T extends U ? T : U;
113
- type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
114
- interface DrizzleTypeError<T> {
115
- $brand: 'DrizzleTypeError';
116
- $error: T;
117
- }
118
- type ValueOrArray<T> = T | T[];
119
- type Or<T1, T2> = T1 extends true ? true : T2 extends true ? true : false;
120
- type IfThenElse<If, Then, Else> = If extends true ? Then : Else;
121
- type PromiseOf<T> = T extends Promise<infer U> ? U : T;
122
- type Writable<T> = {
123
- -readonly [P in keyof T]: T[P];
124
- };
125
- declare function getTableColumns<T extends AnyTable>(table: T): T['_']['columns'];
126
- type ColumnsWithTable<TTableName extends string, TForeignTableName extends string, TColumns extends AnyColumn<{
127
- tableName: TTableName;
128
- }>[]> = {
129
- [Key in keyof TColumns]: AnyColumn<{
130
- tableName: TForeignTableName;
131
- }>;
132
- };
133
- interface DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> {
134
- logger?: boolean | Logger;
135
- schema?: TSchema;
136
- }
137
- type KnownKeysOnly<T, U> = {
138
- [K in keyof T]: K extends keyof U ? T[K] : never;
139
- };
140
- declare function iife<T extends unknown[], U>(fn: (...args: T) => U, ...args: T): U;
141
-
142
- interface TableConfig<TColumn extends AnyColumn = AnyColumn> {
143
- name: string;
144
- schema: string | undefined;
145
- columns: Record<string, TColumn>;
146
- }
147
- type UpdateTableConfig<T extends TableConfig, TUpdate extends Partial<TableConfig>> = Required<Update<T, TUpdate>>;
148
- declare const IsDrizzleTable: unique symbol;
149
- declare class Table<T extends TableConfig = TableConfig> {
150
- static readonly [entityKind]: string;
151
- readonly _: {
152
- readonly brand: 'Table';
153
- readonly config: T;
154
- readonly name: T['name'];
155
- readonly schema: T['schema'];
156
- readonly columns: T['columns'];
157
- readonly model: {
158
- select: InferModel<Table<T>>;
159
- insert: InferModel<Table<T>, 'insert'>;
160
- };
161
- };
162
- [IsDrizzleTable]: boolean;
163
- constructor(name: string, schema: string | undefined, baseName: string);
164
- }
165
- declare function isTable(table: unknown): table is Table;
166
- type AnyTable<TPartial extends Partial<TableConfig> = {}> = Table<UpdateTableConfig<TableConfig, TPartial>>;
167
- interface AnyTableHKT {
168
- readonly brand: 'TableHKT';
169
- config: unknown;
170
- type: unknown;
171
- }
172
- interface AnyTableHKTBase extends AnyTableHKT {
173
- type: AnyTable<Assume<this['config'], Partial<TableConfig>>>;
174
- }
175
- type AnyTableKind<THKT extends AnyTableHKT, TConfig extends Partial<TableConfig>> = (THKT & {
176
- config: TConfig;
177
- })['type'];
178
- declare function getTableName<T extends Table>(table: T): T['_']['name'];
179
- type MapColumnName<TName extends string, TColumn extends AnyColumn, TDBColumNames extends boolean> = TDBColumNames extends true ? TColumn['_']['name'] : TName;
180
- type InferModelFromColumns<TColumns extends Record<string, AnyColumn>, TInferMode extends 'select' | 'insert' = 'select', TConfig extends {
181
- dbColumnNames: boolean;
182
- } = {
183
- dbColumnNames: false;
184
- }> = TInferMode extends 'insert' ? SimplifyShallow<{
185
- [Key in keyof TColumns & string as RequiredKeyOnly<MapColumnName<Key, TColumns[Key], TConfig['dbColumnNames']>, TColumns[Key]>]: GetColumnData<TColumns[Key], 'query'>;
186
- } & {
187
- [Key in keyof TColumns & string as OptionalKeyOnly<MapColumnName<Key, TColumns[Key], TConfig['dbColumnNames']>, TColumns[Key]>]?: GetColumnData<TColumns[Key], 'query'>;
188
- }> : {
189
- [Key in keyof TColumns & string as MapColumnName<Key, TColumns[Key], TConfig['dbColumnNames']>]: GetColumnData<TColumns[Key], 'query'>;
190
- };
191
- type InferModel<TTable extends AnyTable, TInferMode extends 'select' | 'insert' = 'select', TConfig extends {
192
- dbColumnNames: boolean;
193
- } = {
194
- dbColumnNames: false;
195
- }> = InferModelFromColumns<TTable['_']['columns'], TInferMode, TConfig>;
196
-
197
- type RequiredKeyOnly<TKey extends string, T extends AnyColumn> = T extends AnyColumn<{
198
- notNull: true;
199
- hasDefault: false;
200
- }> ? TKey : never;
201
- type OptionalKeyOnly<TKey extends string, T extends AnyColumn> = TKey extends RequiredKeyOnly<TKey, T> ? never : TKey;
202
- type SelectedFieldsFlat<TColumn extends AnyColumn> = Record<string, TColumn | SQL | SQL.Aliased>;
203
- type SelectedFieldsFlatFull<TColumn extends AnyColumn> = Record<string, TColumn | SQL | SQL.Aliased>;
204
- type SelectedFields<TColumn extends AnyColumn, TTable extends Table> = Record<string, SelectedFieldsFlat<TColumn>[string] | TTable | SelectedFieldsFlat<TColumn>>;
205
- type SelectedFieldsOrdered<TColumn extends AnyColumn> = {
206
- path: string[];
207
- field: TColumn | SQL | SQL.Aliased;
208
- }[];
209
-
210
- declare const ViewBaseConfig: unique symbol;
211
- type ColumnsSelection = Record<string, unknown>;
212
- declare abstract class View<TName extends string = string, TExisting extends boolean = boolean, TSelection extends ColumnsSelection = ColumnsSelection> {
213
- static readonly [entityKind]: string;
214
- _: {
215
- brand: 'View';
216
- viewBrand: string;
217
- name: TName;
218
- existing: TExisting;
219
- selectedFields: TSelection;
220
- };
221
- constructor({ name, schema, selectedFields, query }: {
222
- name: TName;
223
- schema: string | undefined;
224
- selectedFields: SelectedFields<AnyColumn, Table>;
225
- query: SQL | undefined;
226
- });
227
- }
228
-
229
- declare const SubqueryConfig: unique symbol;
230
- declare class Subquery<TAlias extends string = string, TSelectedFields = unknown> {
231
- static readonly [entityKind]: string;
232
- _: {
233
- brand: 'Subquery';
234
- selectedFields: TSelectedFields;
235
- alias: TAlias;
236
- };
237
- constructor(sql: SQL, selection: Record<string, unknown>, alias: string, isWith?: boolean);
238
- }
239
- declare class WithSubquery<TAlias extends string = string, TSelection = unknown> extends Subquery<TAlias, TSelection> {
240
- static readonly [entityKind]: string;
241
- }
242
- declare class SelectionProxyHandler<T extends Subquery | Record<string, unknown> | View> implements ProxyHandler<Subquery | Record<string, unknown> | View> {
243
- static readonly [entityKind]: string;
244
- private config;
245
- constructor(config: SelectionProxyHandler<T>['config']);
246
- get(subquery: T, prop: string | symbol): any;
247
- }
248
-
249
- /**
250
- * This class is used to indicate a primitive param value that is used in `sql` tag.
251
- * It is only used on type level and is never instantiated at runtime.
252
- * If you see a value of this type in the code, its runtime value is actually the primitive param value.
253
- */
254
- declare class FakePrimitiveParam {
255
- static readonly [entityKind]: string;
256
- }
257
- type Chunk = string | Table | View | AnyColumn | Name | Param | Placeholder | SQL;
258
- interface BuildQueryConfig {
259
- escapeName(name: string): string;
260
- escapeParam(num: number, value: unknown): string;
261
- escapeString(str: string): string;
262
- prepareTyping?: (encoder: DriverValueEncoder<unknown, unknown>) => QueryTypingsValue;
263
- paramStartIndex?: {
264
- value: number;
265
- };
266
- inlineParams?: boolean;
267
- }
268
- type QueryTypingsValue = 'json' | 'decimal' | 'time' | 'timestamp' | 'uuid' | 'date' | 'none';
269
- interface Query {
270
- sql: string;
271
- params: unknown[];
272
- typings?: QueryTypingsValue[];
273
- }
274
- interface SQLWrapper {
275
- getSQL(): SQL;
276
- }
277
- declare function isSQLWrapper(value: unknown): value is SQLWrapper;
278
- declare class StringChunk {
279
- static readonly [entityKind]: string;
280
- readonly value: string[];
281
- constructor(value: string | string[]);
282
- }
283
- type GetDecoderResult<T> = T extends DriverValueDecoder<infer TData, any> | DriverValueDecoder<infer TData, any>['mapFromDriverValue'] ? TData : never;
284
- /**
285
- * Any DB name (table, column, index etc.)
286
- */
287
- declare class Name {
288
- readonly value: string;
289
- static readonly [entityKind]: string;
290
- protected brand: 'Name';
291
- constructor(value: string);
292
- }
293
- /**
294
- * Any DB name (table, column, index etc.)
295
- * @deprecated Use `sql.identifier` instead.
296
- */
297
- declare function name(value: string): Name;
298
- interface DriverValueDecoder<TData, TDriverParam> {
299
- mapFromDriverValue(value: TDriverParam): TData;
300
- }
301
- interface DriverValueEncoder<TData, TDriverParam> {
302
- mapToDriverValue(value: TData): TDriverParam | SQL;
303
- }
304
- declare function isDriverValueEncoder(value: unknown): value is DriverValueEncoder<any, any>;
305
- declare const noopDecoder: DriverValueDecoder<any, any>;
306
- declare const noopEncoder: DriverValueEncoder<any, any>;
307
- interface DriverValueMapper<TData, TDriverParam> extends DriverValueDecoder<TData, TDriverParam>, DriverValueEncoder<TData, TDriverParam> {
308
- }
309
- declare const noopMapper: DriverValueMapper<any, any>;
310
- /** Parameter value that is optionally bound to an encoder (for example, a column). */
311
- declare class Param<TDataType = unknown, TDriverParamType = TDataType> {
312
- readonly value: TDataType;
313
- readonly encoder: DriverValueEncoder<TDataType, TDriverParamType>;
314
- static readonly [entityKind]: string;
315
- protected brand: 'BoundParamValue';
316
- /**
317
- * @param value - Parameter value
318
- * @param encoder - Encoder to convert the value to a driver parameter
319
- */
320
- constructor(value: TDataType, encoder?: DriverValueEncoder<TDataType, TDriverParamType>);
321
- }
322
- declare function param<TData, TDriver>(value: TData, encoder?: DriverValueEncoder<TData, TDriver>): Param<TData, TDriver>;
323
- /**
324
- * Anything that can be passed to the `` sql`...` `` tagged function.
325
- */
326
- type SQLChunk = StringChunk | SQLChunk[] | SQLWrapper | SQL | Table | View | Subquery | AnyColumn | Param | Name | undefined | FakePrimitiveParam | Placeholder;
327
- declare function sql<T>(strings: TemplateStringsArray, ...params: any[]): SQL<T>;
328
- declare namespace sql {
329
- function empty(): SQL;
330
- /** @deprecated - use `sql.join()` */
331
- function fromList(list: SQLChunk[]): SQL;
332
- /**
333
- * Convenience function to create an SQL query from a raw string.
334
- * @param str The raw SQL query string.
335
- */
336
- function raw(str: string): SQL;
337
- /**
338
- * Join a list of SQL chunks with a separator.
339
- * @example
340
- * ```ts
341
- * const query = sql.join([sql`a`, sql`b`, sql`c`]);
342
- * // sql`abc`
343
- * ```
344
- * @example
345
- * ```ts
346
- * const query = sql.join([sql`a`, sql`b`, sql`c`], sql`, `);
347
- * // sql`a, b, c`
348
- * ```
349
- */
350
- function join(chunks: SQLChunk[], separator?: SQLChunk): SQL;
351
- /**
352
- * Create a SQL chunk that represents a DB identifier (table, column, index etc.).
353
- * When used in a query, the identifier will be escaped based on the DB engine.
354
- * For example, in PostgreSQL, identifiers are escaped with double quotes.
355
- *
356
- * **WARNING: This function does not offer any protection against SQL injections, so you must validate any user input beforehand.**
357
- *
358
- * @example ```ts
359
- * const query = sql`SELECT * FROM ${sql.identifier('my-table')}`;
360
- * // 'SELECT * FROM "my-table"'
361
- * ```
362
- */
363
- function identifier(value: string): Name;
364
- }
365
- declare class SQL<T = unknown> implements SQLWrapper {
366
- readonly queryChunks: SQLChunk[];
367
- static readonly [entityKind]: string;
368
- _: {
369
- brand: 'SQL';
370
- type: T;
371
- };
372
- private shouldInlineParams;
373
- constructor(queryChunks: SQLChunk[]);
374
- append(query: SQL): this;
375
- toQuery(config: BuildQueryConfig): Query;
376
- buildQueryFromSourceParams(chunks: SQLChunk[], _config: BuildQueryConfig): Query;
377
- private mapInlineParam;
378
- getSQL(): SQL;
379
- as(alias: string): SQL.Aliased<T>;
380
- /**
381
- * @deprecated
382
- * Use ``sql<DataType>`query`.as(alias)`` instead.
383
- */
384
- as<TData>(): SQL<TData>;
385
- /**
386
- * @deprecated
387
- * Use ``sql<DataType>`query`.as(alias)`` instead.
388
- */
389
- as<TData>(alias: string): SQL.Aliased<TData>;
390
- mapWith<TDecoder extends DriverValueDecoder<any, any> | DriverValueDecoder<any, any>['mapFromDriverValue']>(decoder: TDecoder): SQL<GetDecoderResult<TDecoder>>;
391
- inlineParams(): this;
392
- }
393
- declare namespace SQL {
394
- class Aliased<T = unknown> implements SQLWrapper {
395
- readonly sql: SQL;
396
- readonly fieldAlias: string;
397
- static readonly [entityKind]: string;
398
- _: {
399
- brand: 'SQL.Aliased';
400
- type: T;
401
- };
402
- constructor(sql: SQL, fieldAlias: string);
403
- getSQL(): SQL;
404
- }
405
- }
406
- declare class Placeholder<TName extends string = string, TValue = any> {
407
- readonly name: TName;
408
- static readonly [entityKind]: string;
409
- protected: TValue;
410
- constructor(name: TName);
411
- }
412
- declare function placeholder<TName extends string>(name: TName): Placeholder<TName>;
413
- declare function fillPlaceholders(params: unknown[], values: Record<string, unknown>): unknown[];
414
-
415
- interface ColumnBuilderBaseConfig {
416
- name: string;
417
- data: unknown;
418
- driverParam: unknown;
419
- notNull: boolean;
420
- hasDefault: boolean;
421
- }
422
- type ColumnBuilderConfig<TInitial extends Partial<ColumnBuilderBaseConfig> = {}, TDefaults extends Partial<ColumnBuilderBaseConfig> = {}> = SimplifyShallow<Required<Update<ColumnBuilderBaseConfig & {
423
- notNull: false;
424
- hasDefault: false;
425
- }, {
426
- [K in keyof TInitial]: TInitial[K];
427
- } & {
428
- [K in Exclude<keyof TDefaults, keyof TInitial> & string]: TDefaults[K];
429
- }>>>;
430
- type MakeColumnConfig<T extends ColumnBuilderBaseConfig, TTableName extends string> = SimplifyShallow<Pick<T, keyof ColumnBuilderBaseConfig> & {
431
- tableName: TTableName;
432
- }>;
433
- interface ColumnBuilderHKTBase {
434
- config: unknown;
435
- _type: unknown;
436
- _columnHKT: unknown;
437
- }
438
- type ColumnBuilderKind<THKT extends ColumnBuilderHKTBase, TConfig extends ColumnBuilderBaseConfig> = (THKT & {
439
- config: TConfig;
440
- })['_type'];
441
- interface ColumnBuilderHKT extends ColumnBuilderHKTBase {
442
- _type: ColumnBuilder<ColumnBuilderHKT, Assume<this['config'], ColumnBuilderBaseConfig>>;
443
- }
444
- interface ColumnBuilderRuntimeConfig<TData> {
445
- name: string;
446
- notNull: boolean;
447
- default: TData | SQL | undefined;
448
- hasDefault: boolean;
449
- primaryKey: boolean;
450
- isUnique: boolean;
451
- uniqueName: string | undefined;
452
- uniqueType: string | undefined;
453
- }
454
- declare abstract class ColumnBuilder<THKT extends ColumnBuilderHKTBase, T extends ColumnBuilderBaseConfig, TRuntimeConfig extends object = {}, TTypeConfig extends object = {}> {
455
- static readonly [entityKind]: string;
456
- _: {
457
- brand: 'ColumnBuilder';
458
- config: T;
459
- hkt: THKT;
460
- columnHKT: THKT['_columnHKT'];
461
- name: T['name'];
462
- data: T['data'];
463
- driverParam: T['driverParam'];
464
- notNull: T['notNull'];
465
- hasDefault: T['hasDefault'];
466
- } & TTypeConfig;
467
- protected config: ColumnBuilderRuntimeConfig<T['data']> & TRuntimeConfig;
468
- constructor(name: T['name']);
469
- $type<TType extends T['data']>(): ColumnBuilderKind<THKT, Update<T, {
470
- data: TType;
471
- }>>;
472
- notNull(): ColumnBuilderKind<THKT, UpdateCBConfig<T, {
473
- notNull: true;
474
- }>>;
475
- default(value: T['data'] | SQL): ColumnBuilderKind<THKT, UpdateCBConfig<T, {
476
- hasDefault: true;
477
- }>>;
478
- primaryKey(): ColumnBuilderKind<THKT, UpdateCBConfig<T, {
479
- notNull: true;
480
- }>>;
481
- }
482
- type AnyColumnBuilder = ColumnBuilder<ColumnBuilderHKT, ColumnBuilderBaseConfig>;
483
- type UpdateCBConfig<T extends ColumnBuilderBaseConfig, TUpdate extends Partial<ColumnBuilderBaseConfig>> = Update<T, TUpdate>;
484
- type BuildColumn<TTableName extends string, TBuilder extends AnyColumnBuilder> = Assume<ColumnKind<Assume<TBuilder['_']['columnHKT'], ColumnHKTBase>, SimplifyShallow<{
485
- tableName: TTableName;
486
- } & TBuilder['_']['config']>>, AnyColumn>;
487
- type BuildColumns<TTableName extends string, TConfigMap extends Record<string, AnyColumnBuilder>> = SimplifyShallow<{
488
- [Key in keyof TConfigMap]: BuildColumn<TTableName, TConfigMap[Key]>;
489
- }>;
490
- type ChangeColumnTableName<TColumn extends AnyColumn, TAlias extends string> = ColumnKind<TColumn['_']['hkt'], SimplifyShallow<Update<TColumn['_']['config'], {
491
- tableName: TAlias;
492
- }>>>;
493
-
494
- interface ColumnBaseConfig extends ColumnBuilderBaseConfig {
495
- tableName: string;
496
- }
497
- type ColumnConfig<TPartial extends Partial<ColumnBaseConfig> = {}> = Update<ColumnBuilderConfig & {
498
- tableName: string;
499
- }, TPartial>;
500
- interface ColumnHKTBase {
501
- config: unknown;
502
- _type: unknown;
503
- }
504
- type ColumnKind<T extends ColumnHKTBase, TConfig extends ColumnBaseConfig> = (T & {
505
- config: TConfig;
506
- })['_type'];
507
- interface ColumnHKT extends ColumnHKTBase {
508
- _type: Column<ColumnHKT, Assume<this['config'], ColumnBaseConfig>>;
509
- }
510
- declare abstract class Column<THKT extends ColumnHKT = ColumnHKT, T extends ColumnBaseConfig = ColumnBaseConfig, TRuntimeConfig extends object = object, TTypeConfig extends object = object> implements DriverValueMapper<T['data'], T['driverParam']> {
511
- readonly table: Table;
512
- static readonly [entityKind]: string;
513
- _: {
514
- hkt: THKT;
515
- brand: 'Column';
516
- config: T;
517
- tableName: T['tableName'];
518
- name: T['name'];
519
- data: T['data'];
520
- driverParam: T['driverParam'];
521
- notNull: T['notNull'];
522
- hasDefault: T['hasDefault'];
523
- } & TTypeConfig;
524
- readonly name: string;
525
- readonly primary: boolean;
526
- readonly notNull: boolean;
527
- readonly default: T['data'] | SQL | undefined;
528
- readonly hasDefault: boolean;
529
- readonly isUnique: boolean;
530
- readonly uniqueName: string | undefined;
531
- readonly uniqueType: string | undefined;
532
- protected config: ColumnBuilderRuntimeConfig<T['data']> & TRuntimeConfig;
533
- constructor(table: Table, config: ColumnBuilderRuntimeConfig<T['data']> & TRuntimeConfig);
534
- abstract getSQLType(): string;
535
- mapFromDriverValue(value: T['driverParam']): T['data'];
536
- mapToDriverValue(value: T['data']): T['driverParam'];
537
- }
538
- type UpdateColConfig<T extends ColumnBaseConfig, TUpdate extends Partial<ColumnBaseConfig>> = Update<T, TUpdate>;
539
- type AnyColumn<TPartial extends Partial<ColumnBaseConfig> = {}> = Column<ColumnHKT, Required<Update<ColumnBaseConfig, TPartial>>>;
540
- interface AnyColumnHKT {
541
- config: unknown;
542
- type: unknown;
543
- }
544
- interface AnyColumnHKTBase extends AnyColumnHKT {
545
- type: AnyColumn<Assume<this['config'], Partial<ColumnBaseConfig>>>;
546
- }
547
- type AnyColumnKind<THKT extends AnyColumnHKT, TConfig extends Partial<ColumnBaseConfig>> = (THKT & {
548
- config: TConfig;
549
- })['type'];
550
- type GetColumnData<TColumn extends AnyColumn, TInferMode extends 'query' | 'raw' = 'query'> = TInferMode extends 'raw' ? TColumn['_']['data'] : TColumn['_']['notNull'] extends true ? TColumn['_']['data'] : TColumn['_']['data'] | null;
551
- type InferColumnsDataTypes<TColumns extends Record<string, AnyColumn>> = {
552
- [Key in keyof TColumns]: GetColumnData<TColumns[Key], 'query'>;
553
- };
554
- interface WithEnum<T extends [string, ...string[]] = [string, ...string[]]> {
555
- enumValues: T;
556
- }
557
-
558
- export { BuildQueryConfig as $, AnyColumn as A, BuildColumn as B, ColumnBaseConfig as C, DrizzleConfig as D, is as E, LogWriter as F, GetColumnData as G, ConsoleLogWriter as H, InferModel as I, DefaultLogger as J, SelectedFieldsFlat as K, Logger as L, MapColumnName as M, NoopLogger as N, OptionalKeyOnly as O, SelectedFieldsFlatFull as P, Query as Q, RequiredKeyOnly as R, Simplify as S, Table as T, UpdateColConfig as U, View as V, WithEnum as W, SelectedFields as X, SelectedFieldsOrdered as Y, FakePrimitiveParam as Z, Chunk as _, SQL as a, QueryTypingsValue as a0, SQLWrapper as a1, isSQLWrapper as a2, StringChunk as a3, GetDecoderResult as a4, Name as a5, name as a6, DriverValueDecoder as a7, DriverValueEncoder as a8, isDriverValueEncoder as a9, Update as aA, SimplifyOptions as aB, SimplifyShallow as aC, Assume as aD, Equal as aE, DrizzleTypeError as aF, ValueOrArray as aG, Or as aH, IfThenElse as aI, PromiseOf as aJ, Writable as aK, getTableColumns as aL, ColumnsWithTable as aM, KnownKeysOnly as aN, iife as aO, ViewBaseConfig as aP, ColumnsSelection as aQ, noopDecoder as aa, noopEncoder as ab, DriverValueMapper as ac, noopMapper as ad, Param as ae, param as af, SQLChunk as ag, sql as ah, Placeholder as ai, placeholder as aj, fillPlaceholders as ak, SubqueryConfig as al, Subquery as am, WithSubquery as an, SelectionProxyHandler as ao, TableConfig as ap, UpdateTableConfig as aq, isTable as ar, AnyTable as as, AnyTableHKT as at, AnyTableHKTBase as au, AnyTableKind as av, getTableName as aw, InferModelFromColumns as ax, UpdateSet as ay, OneOrMany as az, ColumnConfig as b, ColumnHKTBase as c, ColumnKind as d, entityKind as e, ColumnHKT as f, Column as g, AnyColumnHKT as h, AnyColumnHKTBase as i, AnyColumnKind as j, InferColumnsDataTypes as k, ColumnBuilderBaseConfig as l, ColumnBuilderConfig as m, MakeColumnConfig as n, ColumnBuilderHKTBase as o, ColumnBuilderKind as p, ColumnBuilderHKT as q, ColumnBuilderRuntimeConfig as r, ColumnBuilder as s, AnyColumnBuilder as t, UpdateCBConfig as u, BuildColumns as v, ChangeColumnTableName as w, hasOwnEntityKind as x, DrizzleEntity as y, DrizzleEntityClass as z };