@expressive/sql 0.1.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.
@@ -0,0 +1,607 @@
1
+ declare namespace Type {
2
+ type EntityType<T extends Type = Type> = (abstract new () => T) & typeof Type;
3
+ type Fields<T extends Type, O extends Partial<Field> = never> = {
4
+ [K in keyof T]: T[K] extends Field ? T[K] extends O ? never : K : never;
5
+ }[keyof T];
6
+ type Required<T extends Type> = Fields<T, Nullable | Optional>;
7
+ type NonNull<T extends Type> = Fields<T, Nullable>;
8
+ type Insert<T extends Type> = {
9
+ [K in Fields<T>]?: Field.Assigns<T[K]>;
10
+ } & {
11
+ [K in Required<T>]: Field.Assigns<T[K]>;
12
+ };
13
+ type Values<T extends Type> = {
14
+ "id": number;
15
+ } & {
16
+ [K in Fields<T>]: T[K] extends Field.Returns<infer U> ? U : never;
17
+ };
18
+ type Query<T extends Type, R> = (query: Query.From<T>, where: Query.Where) => R;
19
+ interface InsertOp extends PromiseLike<void> {
20
+ toString(): string;
21
+ }
22
+ }
23
+ declare abstract class Type {
24
+ this: Type.EntityType;
25
+ /**
26
+ * Primary key of this entity.
27
+ * May be any name in the actual database, however requred to be `id` as property of this type.
28
+ */
29
+ id: Primary;
30
+ static schema: string;
31
+ static connection?: Connection;
32
+ static get fields(): Map<string, Field<unknown>>;
33
+ static get table(): string;
34
+ static set table(value: string);
35
+ static toString(): string;
36
+ static is(obj: unknown): obj is Type.EntityType;
37
+ static insert<T extends Type>(this: Type.EntityType<T>, entries: Type.Insert<T> | Type.Insert<T>[]): Query<number>;
38
+ static insert<T extends Type>(this: Type.EntityType<T>, number: number, map: (index: number) => Type.Insert<T>): Query<number>;
39
+ static insert<T extends Type, I>(this: Type.EntityType<T>, forEach: Array<I>, map: (value: I, index: number) => Type.Insert<T>): Query<number>;
40
+ static get<T extends Type>(this: Type.EntityType<T>, limit?: number): Query.Selects<T>;
41
+ static get<T extends Type>(this: Type.EntityType<T>, where?: Type.Query<T, void>): Query.Selects<T>;
42
+ static get<T extends Type, R>(this: Type.EntityType<T>, limit: number, where: Type.Query<T, R>): Query.Selects<R>;
43
+ static one<T extends Type, R extends {}>(this: Type.EntityType<T>, query: Type.Query<T, R>): Promise<Query.Extract<R>>;
44
+ static one<T extends Type>(this: Type.EntityType<T>, query?: Type.Query<T, void>): Promise<Type.Values<T>>;
45
+ static one<T extends Type>(this: Type.EntityType<T>, id: number): Promise<Type.Values<T>>;
46
+ }
47
+ declare class Primary extends Field<number> {
48
+ readonly type = "int";
49
+ readonly increment = true;
50
+ readonly optional = true;
51
+ readonly nullable = false;
52
+ readonly primary = true;
53
+ readonly unique = true;
54
+ }
55
+
56
+ type ANumeric = Query.Value<string | number>;
57
+ type Numeric = Query.Value<number>;
58
+ interface Bitwise {
59
+ not(value: Numeric): Numeric;
60
+ and(left: Numeric, right: Numeric): Numeric;
61
+ or(left: Numeric, right: Numeric): Numeric;
62
+ xor(left: Numeric, right: Numeric): Numeric;
63
+ left(value: Numeric, shift: Numeric): Numeric;
64
+ right(value: Numeric, shift: Numeric): Numeric;
65
+ }
66
+ interface MathOps {
67
+ add(left: Numeric, right: Numeric): Numeric;
68
+ add(left: ANumeric, right: ANumeric): ANumeric;
69
+ sub(left: Numeric, right: Numeric): Numeric;
70
+ mul(left: Numeric, right: Numeric): Numeric;
71
+ div(left: Numeric, right: Numeric): Numeric;
72
+ mod(left: Numeric, right: Numeric): Numeric;
73
+ neg(value: Numeric): Numeric;
74
+ pos(value: Numeric): Numeric;
75
+ }
76
+ declare const math: MathOps;
77
+ declare const bit: Bitwise;
78
+ declare class Computed<T> extends Value {
79
+ readonly left?: Query.Value | Field<T> | Computed<T>;
80
+ readonly right: Query.Value | Field<T> | Computed<T>;
81
+ readonly operator: string;
82
+ readonly rank: number;
83
+ constructor(operator: string, value: Value | Field<T> | Computed<T>, right?: Value | Field<T> | Computed<T>, rank?: number);
84
+ }
85
+
86
+ declare class Generator {
87
+ query: Builder;
88
+ cte: Map<string, string>;
89
+ constructor(query: Builder);
90
+ toString(): string;
91
+ escape(name: unknown): string;
92
+ protected insert(): false | (string | false | (string | undefined)[] | undefined)[];
93
+ protected with(): string | undefined;
94
+ protected value(input: unknown): string;
95
+ protected jsonTable(table: DataTable): void;
96
+ computed(from: Computed<any>): string;
97
+ protected joins(main: Builder.Table): string | undefined;
98
+ protected set(updates: Map<Query.Table, Builder.Insert>): string;
99
+ protected update(multiTableAllowed?: boolean): (string | undefined)[] | undefined;
100
+ protected delete(): (string | false | undefined)[] | undefined;
101
+ protected reference(from: Field | Value): Field<unknown> | Value;
102
+ protected select(): (Field<unknown> | Value | undefined)[];
103
+ protected from(): (string | undefined)[] | undefined;
104
+ protected param(from: Parameter): string;
105
+ protected filter(left: Field, op: string, right: unknown): string;
106
+ protected where(): string[] | undefined;
107
+ protected order(): string | undefined;
108
+ protected limit(): (string | number)[] | undefined;
109
+ }
110
+
111
+ declare namespace Connection {
112
+ type Types = typeof Type[] | {
113
+ [key: string | number]: typeof Type;
114
+ };
115
+ type Using = {
116
+ [key: string | number]: typeof Type;
117
+ };
118
+ type Ready<T extends Connection = Connection> = Omit<T, "then">;
119
+ let None: Connection;
120
+ }
121
+ declare abstract class Connection {
122
+ static generator: typeof Generator;
123
+ readonly using: Readonly<Set<typeof Type>>;
124
+ readonly ready: boolean;
125
+ constructor(using: Connection.Types);
126
+ generate(builder: Builder): string;
127
+ then(onfulfilled?: (value: Connection.Ready<this>) => any, onrejected?: (reason: any) => any): Promise<any>;
128
+ abstract get schema(): string;
129
+ close(): Promise<void>;
130
+ abstract sync(fix?: boolean): Promise<void>;
131
+ abstract valid(type: Type.EntityType): Promise<boolean>;
132
+ abstract prepare<T = any>(query: string): {
133
+ all: (args?: any[]) => Promise<T[]>;
134
+ get: (args?: any[]) => Promise<T | undefined>;
135
+ run: (args?: any[]) => Promise<number>;
136
+ };
137
+ }
138
+
139
+ declare namespace Query {
140
+ type Table = Builder.Table;
141
+ type From<T extends Type = Type> = {
142
+ [K in Type.Fields<T>]: T[K] extends Field.Queries<infer U> ? U : T[K];
143
+ };
144
+ type Join<T extends Type = Type> = {
145
+ [K in Type.Fields<T>]?: T[K] extends Field.Queries<infer U> ? U : T[K];
146
+ };
147
+ type Update<T extends Type> = {
148
+ [K in Type.Fields<T>]?: Updates<T[K]>;
149
+ };
150
+ type FromData<T extends {}> = {
151
+ [K in keyof T]: Field<T[K]>;
152
+ };
153
+ type Value<T = any> = T | Field<T> | Computed<T>;
154
+ type Insert<T extends Type> = {
155
+ [K in Type.Required<T>]: Field.Assigns<T[K]> | Field;
156
+ } & {
157
+ [K in Type.Fields<T>]?: Field.Assigns<T[K]> | Field;
158
+ };
159
+ /** Main callback for adding instructions to a Query. */
160
+ type Where = {
161
+ /**
162
+ * Declare inserts to be made into a given table.
163
+ */
164
+ <T extends Type>(entity: Type.EntityType<T>, ...inserts: Insert<T>[]): Query.From<T>;
165
+ /**
166
+ * Create a reference to the primary table, returned
167
+ * object can be used to query against that table.
168
+ */
169
+ <T extends Type>(entity: Type.EntityType<T>): Query.From<T>;
170
+ /**
171
+ * Registers a type as a left join, returned object has optional
172
+ * properties which may be undefined where the join is not present.
173
+ */
174
+ <T extends Type>(entity: Type.EntityType<T>, optional: true): Query.Join<T>;
175
+ /**
176
+ * Select a table for comparison or write operations.
177
+ */
178
+ <T extends Type>(field: Query.From<T> | Query.Join<T>): Query.Verbs<T>;
179
+ /**
180
+ * Prepare comparison against a particilar field,
181
+ * returns operations for the given type.
182
+ */
183
+ <T extends Field>(field: T | undefined): Query.Asserts<T>;
184
+ <T extends {}>(data: Iterable<T>): {
185
+ [K in keyof T]: Field<T[K]>;
186
+ };
187
+ /**
188
+ * Accepts other where() assertions for nesting in parenthesis.
189
+ *
190
+ * Will alternate between AND-OR depending on depth, starting with OR.
191
+ */
192
+ (...orWhere: (Cond | Group)[]): Group;
193
+ /** Specify the limit of results returned. */
194
+ (limit: number): void;
195
+ connection: Connection.Ready;
196
+ };
197
+ type Updates<T> = Field.Updates<T> | T | Field;
198
+ type Function<R> = (this: Builder, where: Where) => R;
199
+ type Factory<R, A extends any[]> = (this: Builder, where: Where) => (...args: A) => R;
200
+ interface Template<A extends any[]> {
201
+ (...args: A): Query;
202
+ /** Prepared query for this template. */
203
+ toString(): string;
204
+ }
205
+ type TemplateSelects<T, A extends any[]> = (...args: A) => Selects<T>;
206
+ type Extract<T> = T extends Field.Returns<infer R> ? R : T extends From<infer U> ? {
207
+ [J in Type.Fields<U>]: Extract<U[J]>;
208
+ } : T extends {} ? {
209
+ [K in keyof T]: Extract<T[K]>;
210
+ } : T;
211
+ type Asserts<T extends Field> = ReturnType<T["where"]> & {
212
+ asc(): void;
213
+ desc(): void;
214
+ };
215
+ interface Verbs<T extends Type> {
216
+ delete(): void;
217
+ update(values: Query.Update<T>): void;
218
+ }
219
+ interface Selects<T> extends Query<Extract<T>[]> {
220
+ /**
221
+ * Returns rows which match creteria.
222
+ */
223
+ get(): Promise<Extract<T>[]>;
224
+ /**
225
+ * Returns the first row that matches creteria.
226
+ *
227
+ * @param orFail If true, will throw an error if no match is found.
228
+ */
229
+ one(orFail?: boolean): Promise<Extract<T>>;
230
+ }
231
+ }
232
+ interface Query<T = any> extends PromiseLike<T> {
233
+ /** Returns the SQL string prepared by this query. */
234
+ toString(): string;
235
+ /**
236
+ * Inputs to be sent with SQL for this query.
237
+ * Data has already been serialized and matched to query parameters in template.
238
+ */
239
+ params: (string | number)[];
240
+ }
241
+ declare function Query<T extends {}, A extends unknown[]>(from: Query.Factory<T, A>): Query.TemplateSelects<T, A>;
242
+ declare function Query<A extends unknown[]>(from: Query.Factory<void, A>): Query.Template<A>;
243
+ declare function Query<T extends {}>(from: Query.Function<T>): Query.Selects<T>;
244
+ /**
245
+ * Creates a new query.
246
+ * Will return the number of rows that would be selected or modified.
247
+ */
248
+ declare function Query(from: Query.Function<void>): Query<number>;
249
+ declare namespace Query {
250
+ var Builder: typeof Builder;
251
+ }
252
+
253
+ declare namespace Builder {
254
+ interface Table<T extends Type = any> {
255
+ toString(): string;
256
+ name: string;
257
+ proxy: Query.From<T>;
258
+ fields: Map<string, Field>;
259
+ alias?: string;
260
+ optional?: boolean;
261
+ joins: Cond[];
262
+ }
263
+ type Using<T extends Type> = (self: Query.From<T>, where: Query.Where) => void;
264
+ type Insert = Map<Field, unknown>;
265
+ }
266
+ declare class Builder {
267
+ /**
268
+ * Parameters which will be sent with query.
269
+ * May either be placeholders for a template, or values
270
+ * which the query deems unsafe to interpolate directly.
271
+ */
272
+ params: Parameter[];
273
+ filters: Group;
274
+ pending: Set<() => void>;
275
+ order: Map<Field<unknown>, "asc" | "desc">;
276
+ tables: Map<{}, Query.Table>;
277
+ deletes: Set<Query.Table>;
278
+ updates: Map<Query.Table, Builder.Insert>;
279
+ inserts: Map<Query.Table, Builder.Insert>;
280
+ returns?: Map<string, Field | Value> | Field | Value;
281
+ limit?: number;
282
+ commit(returns: unknown): void;
283
+ inject(args: number): (() => Parameter)[];
284
+ table(table: Query.From): Query.Verbs<Type>;
285
+ field<T extends Field>(field: T): {
286
+ asc: () => void;
287
+ desc: () => void;
288
+ is(value: unknown): Cond;
289
+ not(value: unknown): Cond;
290
+ over(value: unknown, orEqual?: boolean | undefined): Cond;
291
+ under(value: unknown, orEqual?: boolean | undefined): Cond;
292
+ in(value: unknown[]): Cond;
293
+ };
294
+ andOr(...args: (Cond | Group)[]): Group;
295
+ use<T extends Type>(type: Type.EntityType<T>, optional?: false): Query.From<T>;
296
+ use<T extends Type>(type: Type.EntityType<T>, optional: boolean): Query.Join<T>;
297
+ use<T extends Type>(type: Type.EntityType<T>, ...inserts: Type.Insert<T>[]): Query.From<T>;
298
+ insert<T extends Type>(table: Builder.Table<T>, input: Type.Insert<T>): void;
299
+ digest(value: any, field: Field): any;
300
+ where(left: Field, op: string, right: unknown): Cond | Group;
301
+ with<T extends Record<string, any>>(data: Iterable<T>): { [K in keyof T]: Field<T[K]>; };
302
+ accept(args: unknown[]): unknown[];
303
+ parse(raw: Record<string, any>): any;
304
+ }
305
+ declare class Value {
306
+ }
307
+ declare class Parameter extends Value {
308
+ index: number;
309
+ constructor(index?: number);
310
+ constructor(data?: () => unknown);
311
+ digest(value: unknown): unknown;
312
+ toParam(from: Record<string, any>): unknown;
313
+ }
314
+ declare class DataField extends Value {
315
+ column: string;
316
+ table: DataTable;
317
+ field?: Field;
318
+ constructor(column: string, table: DataTable);
319
+ get datatype(): string;
320
+ }
321
+ declare class DataTable<T extends Record<string, unknown> = any> extends Parameter implements Builder.Table {
322
+ parent: Builder;
323
+ proxy: {
324
+ [K in keyof T]: Field<T[K]>;
325
+ };
326
+ output: {
327
+ [K in keyof T]: unknown;
328
+ }[];
329
+ used: Set<DataField>;
330
+ joins: Cond[];
331
+ optional: boolean;
332
+ fields: Map<string, Field<unknown>>;
333
+ name: string;
334
+ constructor(parent: Builder, input: Iterable<T>);
335
+ toParam(): any;
336
+ }
337
+ declare class Cond {
338
+ readonly left: Field;
339
+ readonly op: string;
340
+ readonly right: unknown;
341
+ readonly restricted: boolean;
342
+ constructor(left: Field, op: string, right: unknown, restricted?: boolean);
343
+ }
344
+ declare class Group {
345
+ children: Set<Cond | Group>;
346
+ add(left: Field | Group | Cond, op?: string, right?: unknown): Cond | Group;
347
+ delete(child: Cond | Group): void;
348
+ get size(): number;
349
+ }
350
+
351
+ type Nullable = {
352
+ nullable: true;
353
+ };
354
+ type Optional = {
355
+ optional: true;
356
+ };
357
+ declare namespace Field {
358
+ type Init<T extends Field = Field> = (self: T) => Partial<T> | void;
359
+ type Opts<T extends Field = Field> = Partial<T> | Init<T>;
360
+ type Modifier<T, TT extends Field> = T extends {
361
+ nullable: true;
362
+ } ? TT & Nullable : T extends {
363
+ fallback?: any;
364
+ increment?: true;
365
+ } ? TT & Optional : TT;
366
+ type Specify<T, TT extends Field, D extends Field = TT> = Modifier<T, T extends {
367
+ type: infer U;
368
+ } ? Extract<TT, {
369
+ type: U;
370
+ }> : D>;
371
+ type Returns<T> = Field & {
372
+ get(value: any): T;
373
+ };
374
+ type Accepts<T> = Field & {
375
+ set(value: T, data: unknown): void;
376
+ };
377
+ type Queries<T> = Field & {
378
+ use(table: Builder): T;
379
+ };
380
+ type Updates<T> = T extends Accepts<infer U> ? (T extends Nullable ? U | null : U) | undefined : never;
381
+ type Assigns<T> = T extends Accepts<infer U> ? T extends Nullable ? U | null | undefined : T extends Optional ? U | undefined : U : never;
382
+ type Output = Record<string, string | number>;
383
+ type Compare<T> = {
384
+ is(value: Query.Value<T>): Cond;
385
+ not(value: Query.Value<T>): Cond;
386
+ over(value: Query.Value<T>, orEqual?: boolean): Cond;
387
+ under(value: Query.Value<T>, orEqual?: boolean): Cond;
388
+ in(value: Query.Value<T>[]): Cond;
389
+ };
390
+ }
391
+ declare class Field<T = unknown> {
392
+ private options?;
393
+ type: string;
394
+ unique: boolean;
395
+ nullable: boolean;
396
+ optional: boolean;
397
+ increment: boolean;
398
+ fallback?: unknown;
399
+ property: string;
400
+ parent: Type.EntityType;
401
+ table?: Query.Table;
402
+ query?: Builder;
403
+ foreignKey?: string;
404
+ foreignTable?: string;
405
+ /** Real datatype of this field in database. */
406
+ datatype: string;
407
+ column: string;
408
+ constructor(options?: Field.Opts<Field<unknown>> | undefined);
409
+ init(property: string, parent: Type.EntityType): this;
410
+ /**
411
+ * Optional method generates value of property this Field is applied to when accessed inside a query.
412
+ * If not defined, the value will be the Field itself.
413
+ *
414
+ * @returns {T} Value to be used in context of query, interfacing with this Field.
415
+ */
416
+ use?(query: Builder): unknown;
417
+ /**
418
+ * This method dictates behavior of this field when converted from a javascript context to SQL.
419
+ *
420
+ * Use this method to validate, sanitize or convert data before it is inserted into the database.
421
+ */
422
+ set(value: T): any;
423
+ /**
424
+ * This method dictates behavior of this field when converted from a SQL context to javascript.
425
+ *
426
+ * Use this method to parse data incoming from the database itself. For example, you might convert
427
+ * a TINYINT(1) field to a boolean, or a DATETIME field to a Date object.
428
+ */
429
+ get(value: any): T;
430
+ raw(value: T): string;
431
+ /**
432
+ * This method is used to compare this field with another value in a query.
433
+ *
434
+ * @param acc Set of comparisons to be added to if not part of a group.
435
+ */
436
+ where(): Field.Compare<T>;
437
+ }
438
+
439
+ declare class BooleanColumn extends Field<boolean> {
440
+ readonly type: "tinyint" | "varchar";
441
+ readonly datatype: string;
442
+ readonly TRUE: string | number;
443
+ readonly FALSE: string | number;
444
+ constructor(opts?: Bool.Opts);
445
+ get(value: unknown): boolean;
446
+ set(value: boolean): string | number;
447
+ }
448
+ declare namespace Bool {
449
+ interface TinyInt extends BooleanColumn {
450
+ readonly type: "tinyint";
451
+ }
452
+ interface Char extends BooleanColumn {
453
+ readonly type: "varchar";
454
+ either?: [true: string, false: string];
455
+ }
456
+ type Any = TinyInt | Char;
457
+ type Opts = Partial<Any>;
458
+ }
459
+ interface Bool extends BooleanColumn {
460
+ }
461
+ declare function Bool<T extends Bool.Opts>(opts?: T): Field.Modifier<T, T extends {
462
+ type: infer U;
463
+ } ? Extract<Bool.TinyInt, {
464
+ type: U;
465
+ }> | Extract<Bool.Char, {
466
+ type: U;
467
+ }> : Bool.Any>;
468
+ declare namespace Bool {
469
+ var Type: typeof BooleanColumn;
470
+ }
471
+
472
+ declare class NumericColumn extends Field<number> {
473
+ readonly type: "int" | "tinyint" | "smallint" | "bigint" | "float" | "double";
474
+ set(value: number): number;
475
+ }
476
+ declare namespace Num {
477
+ interface Int extends Num {
478
+ readonly type: "int";
479
+ }
480
+ interface TinyInt extends Num {
481
+ readonly type: "tinyint";
482
+ }
483
+ interface SmallInt extends Num {
484
+ readonly type: "smallint";
485
+ }
486
+ interface BigInt extends Num {
487
+ readonly type: "bigint";
488
+ }
489
+ interface Float extends Num {
490
+ readonly type: "float";
491
+ }
492
+ interface Double extends Num {
493
+ readonly type: "double";
494
+ }
495
+ type Any = Int | TinyInt | SmallInt | BigInt | Float | Double;
496
+ type Opts = Partial<Any>;
497
+ }
498
+ interface Num extends NumericColumn {
499
+ }
500
+ declare function Num<T extends Num.Opts>(opts?: T): Field.Modifier<T, T extends {
501
+ type: infer U;
502
+ } ? Extract<Num.Int, {
503
+ type: U;
504
+ }> | Extract<Num.TinyInt, {
505
+ type: U;
506
+ }> | Extract<Num.SmallInt, {
507
+ type: U;
508
+ }> | Extract<Num.BigInt, {
509
+ type: U;
510
+ }> | Extract<Num.Float, {
511
+ type: U;
512
+ }> | Extract<Num.Double, {
513
+ type: U;
514
+ }> : Num.Int>;
515
+ declare namespace Num {
516
+ var Type: typeof NumericColumn;
517
+ }
518
+
519
+ declare class ForeignColumn<T extends Type> extends Field<Type.Values<T>> {
520
+ readonly entity: Type.EntityType<T>;
521
+ readonly foreignKey: string;
522
+ readonly foreignTable: string;
523
+ readonly nullable: boolean;
524
+ constructor(type: Type.EntityType<T>, nullable?: boolean);
525
+ set(value: Type.Values<T> | number): any;
526
+ use(query: Builder): any;
527
+ }
528
+ interface One<T extends Type> extends ForeignColumn<T> {
529
+ }
530
+ declare function One<T extends Type>(type: Type.EntityType<T>, nullable?: false): One<T>;
531
+ declare function One<T extends Type>(type: Type.EntityType<T>, nullable: boolean): One<T> & Nullable;
532
+ declare namespace One {
533
+ var Type: typeof ForeignColumn;
534
+ }
535
+
536
+ declare class StringColumn extends Field<string> {
537
+ readonly type: "char" | "varchar" | "text" | "tinytext" | "mediumtext" | "longtext";
538
+ readonly length = 255;
539
+ constructor(opts?: Str.Opts);
540
+ set(value: string): string;
541
+ }
542
+ declare namespace Str {
543
+ interface Char extends Str {
544
+ readonly type: "char";
545
+ }
546
+ interface VarChar extends Str {
547
+ readonly type: "varchar";
548
+ }
549
+ interface Text extends Str {
550
+ readonly type: "text";
551
+ }
552
+ interface TinyText extends Str {
553
+ readonly type: "tinytext";
554
+ }
555
+ interface MediumText extends Str {
556
+ readonly type: "mediumtext";
557
+ }
558
+ interface LongText extends Str {
559
+ readonly type: "longtext";
560
+ }
561
+ type Any = Char | VarChar | Text | TinyText | MediumText | LongText;
562
+ type Opts = Partial<Any>;
563
+ }
564
+ interface Str extends StringColumn {
565
+ }
566
+ declare function Str<T extends Str.Opts>(opts?: T): Field.Modifier<T, T extends {
567
+ type: infer U;
568
+ } ? Extract<Str.Char, {
569
+ type: U;
570
+ }> | Extract<Str.VarChar, {
571
+ type: U;
572
+ }> | Extract<Str.Text, {
573
+ type: U;
574
+ }> | Extract<Str.TinyText, {
575
+ type: U;
576
+ }> | Extract<Str.MediumText, {
577
+ type: U;
578
+ }> | Extract<Str.LongText, {
579
+ type: U;
580
+ }> : Str.VarChar>;
581
+ declare namespace Str {
582
+ var Type: typeof StringColumn;
583
+ }
584
+
585
+ declare class TimeColumn extends Field<Date> {
586
+ readonly type: "datetime";
587
+ readonly fallback?: "NOW" | Date;
588
+ get(value: string): Date;
589
+ set(value: string | Date): string;
590
+ }
591
+ interface Time extends TimeColumn {
592
+ }
593
+ declare function Time(options?: Partial<Time>): Time;
594
+ declare namespace Time {
595
+ var Type: typeof TimeColumn;
596
+ }
597
+
598
+ declare namespace Table {
599
+ interface Options {
600
+ name?: string;
601
+ schema?: string;
602
+ }
603
+ }
604
+ declare function Table(name: string, opts?: Table.Options): Type.EntityType;
605
+ declare function Table(opts: Table.Options): Type.EntityType;
606
+
607
+ export { Bool, Builder, Connection, DataTable, Field, Generator, type Nullable, Num, One, type Optional, Parameter, Query, Str, Table, Time, Type, bit, math };