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