leoric 2.7.2 → 2.8.1
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/History.md +28 -0
- package/index.d.ts +20 -808
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/adapters/sequelize.d.ts +190 -0
- package/src/adapters/sequelize.js +21 -17
- package/src/bone.d.ts +53 -0
- package/src/bone.js +2 -2
- package/src/decorators.js.map +1 -1
- package/src/decorators.ts +2 -2
- package/src/drivers/index.d.ts +188 -0
- package/src/expr.js +2 -1
- package/src/{types/hint.d.ts → hint.d.ts} +49 -31
- package/src/hint.js +7 -1
- package/src/realm.js +2 -2
- package/src/spell.d.ts +160 -0
- package/src/spell.js +24 -9
- package/src/types/abstract_bone.d.ts +360 -0
- package/src/types/common.d.ts +115 -2
package/index.d.ts
CHANGED
|
@@ -1,826 +1,38 @@
|
|
|
1
1
|
import DataTypes, { DataType, AbstractDataType, LENGTH_VARIANTS } from './src/data_types';
|
|
2
|
-
import { Hint, IndexHint } from './src/types/hint';
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Hint, IndexHint, HintInterface,
|
|
4
|
+
INDEX_HINT_SCOPE_TYPE, INDEX_HINT_SCOPE, INDEX_HINT_TYPE
|
|
5
|
+
} from './src/hint';
|
|
6
|
+
import {
|
|
7
|
+
Literal, Validator,
|
|
8
|
+
Connection, QueryOptions,
|
|
9
|
+
Raw, ColumnMeta, AttributeMeta,
|
|
10
|
+
BeforeHooksType, AfterHooksType, Collection,
|
|
7
11
|
} from './src/types/common';
|
|
12
|
+
import { SpellMeta, Spell, SpellBookFormatResult } from './src/spell';
|
|
13
|
+
import Bone from './src/bone';
|
|
14
|
+
import { ConnectOptions, AbstractDriver } from './src/drivers';
|
|
15
|
+
import { RawQueryResult } from './src/types/abstract_bone';
|
|
8
16
|
|
|
9
17
|
export {
|
|
10
18
|
LENGTH_VARIANTS as LENGTH_VARIANTS,
|
|
11
19
|
DataTypes, Literal, Validator, Connection,
|
|
12
|
-
Hint, IndexHint,
|
|
20
|
+
Hint, IndexHint, HintInterface, INDEX_HINT_SCOPE_TYPE, INDEX_HINT_SCOPE, INDEX_HINT_TYPE,
|
|
21
|
+
Bone, Raw, Collection,
|
|
22
|
+
SpellMeta, Spell, ColumnMeta, AttributeMeta, SpellBookFormatResult
|
|
13
23
|
};
|
|
14
|
-
export * from './src/decorators';
|
|
15
|
-
|
|
16
|
-
export class Raw {
|
|
17
|
-
value: string;
|
|
18
|
-
type: 'raw';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type RawQueryResult = typeof Bone | ResultSet | boolean | number;
|
|
22
|
-
|
|
23
|
-
interface ExprIdentifier {
|
|
24
|
-
type: 'id';
|
|
25
|
-
value: string;
|
|
26
|
-
qualifiers?: string[]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface ExprFunc {
|
|
30
|
-
type: 'func';
|
|
31
|
-
name: string;
|
|
32
|
-
args: (ExprLiteral | ExprIdentifier)[];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface ExprLiteral {
|
|
36
|
-
type: 'literal';
|
|
37
|
-
value: Literal;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface ExprBinaryOperator {
|
|
41
|
-
type: 'op';
|
|
42
|
-
name: string;
|
|
43
|
-
args: [ExprIdentifier, ExprLiteral, ExprLiteral];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface ExprTernaryOperator {
|
|
47
|
-
type: 'op';
|
|
48
|
-
name: 'between' | 'not between';
|
|
49
|
-
args: [ExprIdentifier, ExprLiteral, ExprLiteral];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type ExprOperator = ExprBinaryOperator | ExprTernaryOperator;
|
|
53
|
-
type SpellColumn = ExprIdentifier | Raw;
|
|
54
|
-
|
|
55
|
-
interface Join {
|
|
56
|
-
[key: string]: {
|
|
57
|
-
Model: typeof Bone;
|
|
58
|
-
on: ExprBinaryOperator
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
interface SpellOptions {
|
|
63
|
-
command?: command;
|
|
64
|
-
columns: SpellColumn[];
|
|
65
|
-
table: ExprIdentifier;
|
|
66
|
-
whereConditions: ExprOperator[];
|
|
67
|
-
groups: (ExprIdentifier | ExprFunc)[];
|
|
68
|
-
orders: (ExprIdentifier | ExprFunc)[];
|
|
69
|
-
havingCondtions: ExprOperator[];
|
|
70
|
-
joins: Join;
|
|
71
|
-
skip: number;
|
|
72
|
-
scopes: Function[];
|
|
73
|
-
subqueryIndex: number;
|
|
74
|
-
rowCount?: number;
|
|
75
|
-
connection?: Connection;
|
|
76
|
-
sets?: { [key: string]: Literal } | { [key: string]: Literal }[];
|
|
77
|
-
hints?: Array<Hint | IndexHint>;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface SpellMeta extends SpellOptions {
|
|
81
|
-
Model: typeof Bone;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
type OrderOptions = { [name: string]: 'desc' | 'asc' };
|
|
85
|
-
|
|
86
|
-
type SetOptions = { [key: string]: Literal };
|
|
87
|
-
|
|
88
|
-
type WithOptions = {
|
|
89
|
-
[qualifier: string]: { select: string | string[], throughRelation?: string }
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export class Spell<T extends typeof Bone, U = InstanceType<T> | Collection<InstanceType<T>> | ResultSet | number | null> extends Promise<U> {
|
|
93
|
-
constructor(Model: T, opts: SpellOptions);
|
|
94
|
-
|
|
95
|
-
command: string;
|
|
96
|
-
scopes: Function[];
|
|
97
|
-
|
|
98
|
-
select(...names: Array<string | Raw> | Array<(name: string) => boolean>): Spell<T, U>;
|
|
99
|
-
insert(opts: SetOptions): Spell<T, QueryResult>;
|
|
100
|
-
update(opts: SetOptions): Spell<T, QueryResult>;
|
|
101
|
-
upsert(opts: SetOptions): Spell<T, QueryResult>;
|
|
102
|
-
delete(): Spell<T, QueryResult>;
|
|
103
|
-
|
|
104
|
-
from(table: string | Spell<T>): Spell<T, U>;
|
|
105
|
-
|
|
106
|
-
with(opts: WithOptions): Spell<T, U>;
|
|
107
|
-
with(...qualifiers: string[]): Spell<T, U>;
|
|
108
|
-
|
|
109
|
-
join<V extends typeof Bone>(Model: V, onConditions: string, ...values: Literal[]): Spell<T, U>;
|
|
110
|
-
join<V extends typeof Bone>(Model: V, onConditions: WhereConditions<T>): Spell<T, U>;
|
|
111
|
-
|
|
112
|
-
$where(conditions: WhereConditions<T>): this;
|
|
113
|
-
$where(conditions: string, ...values: Literal[]): this;
|
|
114
|
-
where(conditions: WhereConditions<T>): Spell<T, U>;
|
|
115
|
-
where(conditions: string, ...values: Literal[]): Spell<T, U>;
|
|
116
|
-
|
|
117
|
-
orWhere(conditions: WhereConditions<T>): Spell<T, U>;
|
|
118
|
-
orWhere(conditions: string, ...values: Literal[]): Spell<T, U>;
|
|
119
|
-
|
|
120
|
-
group(...names: Array<string | Raw>): Spell<T, ResultSet>;
|
|
121
|
-
|
|
122
|
-
having(conditions: string, ...values: Literal[]): Spell<T, ResultSet>;
|
|
123
|
-
having(conditions: WhereConditions<T>): Spell<T, ResultSet>;
|
|
124
|
-
|
|
125
|
-
orHaving(conditions: string, ...values: Literal[]): Spell<T, ResultSet>;
|
|
126
|
-
orHaving(conditions: WhereConditions<T>): Spell<T, ResultSet>;
|
|
127
|
-
|
|
128
|
-
order(name: string, order?: 'desc' | 'asc'): Spell<T, U>;
|
|
129
|
-
order(opts: OrderOptions): Spell<T, U>;
|
|
130
|
-
|
|
131
|
-
offset(skip: number): Spell<T, U>;
|
|
132
|
-
limit(skip: number): Spell<T, U>;
|
|
133
|
-
|
|
134
|
-
count(name?: string): Spell<T, Extract<U, ResultSet | number>>;
|
|
135
|
-
average(name?: string): Spell<T, Extract<U, ResultSet | number>>;
|
|
136
|
-
minimum(name?: string): Spell<T, Extract<U, ResultSet | number>>;
|
|
137
|
-
maximum(name?: string): Spell<T, Extract<U, ResultSet | number>>;
|
|
138
|
-
sum(name?: string): Spell<T, Extract<U, ResultSet | number>>;
|
|
139
|
-
|
|
140
|
-
batch(size?: number): AsyncIterable<T>;
|
|
141
|
-
|
|
142
|
-
increment(name: string, by?: number, options?: QueryOptions): Spell<T, QueryResult>;
|
|
143
|
-
decrement(name: string, by?: number, options?: QueryOptions): Spell<T, QueryResult>;
|
|
144
|
-
|
|
145
|
-
toSqlString(): string;
|
|
146
|
-
toString(): string;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
type OperatorCondition = {
|
|
150
|
-
[key in '$eq' | '$ne']?: Literal;
|
|
151
|
-
} & {
|
|
152
|
-
[key in '$in' | '$nin' | '$notIn']?: Literal[] | Set<Literal>;
|
|
153
|
-
} & {
|
|
154
|
-
[key in '$like' | '$notLike']?: string;
|
|
155
|
-
} & {
|
|
156
|
-
[key in '$gt' | '$gte' | '$lt' | '$lte']?: number;
|
|
157
|
-
} & {
|
|
158
|
-
[key in '$between' | '$notBetween']?: [number, number] | [Date, Date];
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
type WhereConditions<T extends typeof Bone> = {
|
|
162
|
-
[Property in keyof Extract<InstanceType<T>, Literal>]?: Literal | Literal[] | OperatorCondition;
|
|
163
|
-
} | {
|
|
164
|
-
[key in '$and' | '$or']?: WhereConditions<T>[];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
type Values<T extends typeof Bone> = {
|
|
168
|
-
[Property in keyof Extract<InstanceType<T>, Literal>]?: Literal;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
type InstanceValues<T> = {
|
|
172
|
-
[Property in keyof Extract<T, Literal>]?: Extract<T, Literal>[Property]
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export interface ColumnMeta extends ColumnBase {
|
|
176
|
-
dataType?: string;
|
|
177
|
-
datetimePrecision?: string;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export interface AttributeMeta extends ColumnMeta {
|
|
181
|
-
jsType?: Literal;
|
|
182
|
-
type: AbstractDataType<DataType>;
|
|
183
|
-
virtual?: boolean,
|
|
184
|
-
toSqlString?: () => string;
|
|
185
|
-
validate?: {
|
|
186
|
-
[key: string]: Validator;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
interface TransactionOptions {
|
|
191
|
-
connection: Connection;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
declare class Pool {
|
|
195
|
-
getConnection(): Connection;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
declare class Attribute {
|
|
199
|
-
/**
|
|
200
|
-
* attribute name
|
|
201
|
-
*/
|
|
202
|
-
name: string;
|
|
203
|
-
/**
|
|
204
|
-
* primaryKey tag
|
|
205
|
-
*/
|
|
206
|
-
primaryKey: boolean;
|
|
207
|
-
allowNull: boolean;
|
|
208
|
-
/**
|
|
209
|
-
* attribute column name in table
|
|
210
|
-
*/
|
|
211
|
-
columnName: string;
|
|
212
|
-
columnType: string;
|
|
213
|
-
type: typeof DataType;
|
|
214
|
-
defaultValue: Literal;
|
|
215
|
-
dataType: string;
|
|
216
|
-
jsType: Literal;
|
|
217
|
-
virtual: boolean;
|
|
218
|
-
|
|
219
|
-
euals(columnInfo: ColumnMeta): boolean;
|
|
220
|
-
cast(value: Literal): Literal;
|
|
221
|
-
uncast(value: Literal): Literal;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
interface SpellBookFormatStandardResult {
|
|
225
|
-
sql?: string;
|
|
226
|
-
values?: Array<Literal> | {
|
|
227
|
-
[key: string]: Literal
|
|
228
|
-
};
|
|
229
|
-
[key: string]: Literal
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export type SpellBookFormatResult<T> = SpellBookFormatStandardResult | T;
|
|
233
|
-
|
|
234
|
-
declare class Spellbook {
|
|
235
|
-
|
|
236
|
-
format(spell: SpellMeta): SpellBookFormatResult<SpellBookFormatStandardResult>;
|
|
237
|
-
|
|
238
|
-
formatInsert(spell: SpellMeta): SpellBookFormatResult<SpellBookFormatStandardResult>;
|
|
239
|
-
formatSelect(spell: SpellMeta): SpellBookFormatResult<SpellBookFormatStandardResult>;
|
|
240
|
-
formatUpdate(spell: SpellMeta): SpellBookFormatResult<SpellBookFormatStandardResult>;
|
|
241
|
-
formatDelete(spell: SpellMeta): SpellBookFormatResult<SpellBookFormatStandardResult>;
|
|
242
|
-
formatUpsert(spell: SpellMeta): SpellBookFormatResult<SpellBookFormatStandardResult>;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
declare class AbstractDriver {
|
|
246
|
-
|
|
247
|
-
static Spellbook: typeof Spellbook;
|
|
248
|
-
static DataType: typeof DataType;
|
|
249
|
-
static Attribute: typeof Attribute;
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* The type of driver, currently there are mysql, sqlite, and postgres
|
|
253
|
-
*/
|
|
254
|
-
type: string;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* The database current driver is using.
|
|
258
|
-
*/
|
|
259
|
-
database: string;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* The connection pool of the driver.
|
|
263
|
-
*/
|
|
264
|
-
pool: Pool;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* The SQL dialect
|
|
268
|
-
*/
|
|
269
|
-
dialect: string;
|
|
270
|
-
|
|
271
|
-
spellbook: Spellbook;
|
|
272
|
-
|
|
273
|
-
DataType: DataType;
|
|
274
|
-
|
|
275
|
-
Attribute: Attribute;
|
|
276
|
-
|
|
277
|
-
constructor(options: ConnectOptions);
|
|
278
|
-
|
|
279
|
-
escape: (v: string) => string;
|
|
280
|
-
escapeId: (v: string) => string;
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Grab a connection and query the database
|
|
284
|
-
*/
|
|
285
|
-
query(sql: string | { sql: string, nestTables?: boolean}, values?: Array<Literal | Literal[]>, opts?: SpellMeta): Promise<QueryResult>;
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* disconnect manually
|
|
289
|
-
* @param callback
|
|
290
|
-
*/
|
|
291
|
-
disconnect(callback?: Function): Promise<boolean | void>;
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* query with spell
|
|
295
|
-
* @param spell
|
|
296
|
-
*/
|
|
297
|
-
cast(spell: Spell<typeof Bone, ResultSet | number | null>): Promise<QueryResult>;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* format spell
|
|
301
|
-
* @param spell SpellMeta
|
|
302
|
-
*/
|
|
303
|
-
format(spell: SpellMeta): any;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* create table
|
|
307
|
-
* @param tabe table name
|
|
308
|
-
* @param attributes attributes
|
|
309
|
-
*/
|
|
310
|
-
createTable(tabe: string, attributes: { [key: string]: AbstractDataType<DataType> | AttributeMeta }): Promise<void>;
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* alter table
|
|
314
|
-
* @param tabe table name
|
|
315
|
-
* @param attributes alter attributes
|
|
316
|
-
*/
|
|
317
|
-
alterTable(tabe: string, attributes: { [key: string]: AbstractDataType<DataType> | AttributeMeta }): Promise<void>;
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* describe table
|
|
321
|
-
* @param table table name
|
|
322
|
-
*/
|
|
323
|
-
describeTable(table: string): Promise<{ [key: string]: ColumnMeta }>;
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* query table schemas
|
|
327
|
-
* @param database database name
|
|
328
|
-
* @param table table name or table name array
|
|
329
|
-
*/
|
|
330
|
-
querySchemaInfo(database: string, table: string | string[]): Promise<{ [key: string] : { [key: string]: ColumnMeta }[]}>;
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* add column to table
|
|
334
|
-
* @param table table name
|
|
335
|
-
* @param name column name
|
|
336
|
-
* @param params column meta info
|
|
337
|
-
*/
|
|
338
|
-
addColumn(table: string, name: string, params: ColumnMeta): Promise<void>;
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* change column meta in table
|
|
342
|
-
* @param table table name
|
|
343
|
-
* @param name column name
|
|
344
|
-
* @param params column meta info
|
|
345
|
-
*/
|
|
346
|
-
changeColumn(table: string, name: string, params: ColumnMeta): Promise<void>;
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* remove column in table
|
|
350
|
-
* @param table table name
|
|
351
|
-
* @param name column name
|
|
352
|
-
*/
|
|
353
|
-
removeColumn(table: string, name: string): Promise<void>;
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* rename column in table
|
|
357
|
-
* @param table table name
|
|
358
|
-
* @param name column name
|
|
359
|
-
* @param newName new column name
|
|
360
|
-
*/
|
|
361
|
-
renameColumn(table: string, name: string, newName: string): Promise<void>;
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* rename table
|
|
365
|
-
* @param table table name
|
|
366
|
-
* @param newTable new table name
|
|
367
|
-
*/
|
|
368
|
-
renameTable(table: string, newTable: string): Promise<void>;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* drop table
|
|
372
|
-
* @param table table name
|
|
373
|
-
*/
|
|
374
|
-
dropTable(table: string): Promise<void>;
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* truncate table
|
|
378
|
-
* @param table table name
|
|
379
|
-
*/
|
|
380
|
-
truncateTable(table: string): Promise<void>;
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* add index in table
|
|
384
|
-
* @param table table name
|
|
385
|
-
* @param attributes attributes name
|
|
386
|
-
* @param opts
|
|
387
|
-
*/
|
|
388
|
-
addIndex(table: string, attributes: string[], opts?: { unique?: boolean, type?: string }): Promise<void>;
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* remove index in table
|
|
392
|
-
* @param table string
|
|
393
|
-
* @param attributes attributes name
|
|
394
|
-
* @param opts
|
|
395
|
-
*/
|
|
396
|
-
removeIndex(table: string, attributes: string[], opts?: { unique?: boolean, type?: string }): Promise<void>;
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
export class MysqlDriver extends AbstractDriver {
|
|
401
|
-
type: 'mysql';
|
|
402
|
-
dialect: 'mysql';
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
export class PostgresDriver extends AbstractDriver {
|
|
406
|
-
type: 'postgres';
|
|
407
|
-
dialect: 'postgres';
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
export class SqliteDriver extends AbstractDriver {
|
|
411
|
-
type: 'sqlite';
|
|
412
|
-
dialect: 'sqlite';
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
export class Collection<T extends Bone> extends Array<T> {
|
|
416
|
-
save(): Promise<void>;
|
|
417
|
-
toJSON(): Object[];
|
|
418
|
-
toObject(): Object[];
|
|
419
|
-
}
|
|
420
24
|
|
|
421
|
-
export
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* get the connection pool of the driver
|
|
426
|
-
*/
|
|
427
|
-
static pool: Pool;
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* The driver that powers the model
|
|
431
|
-
*/
|
|
432
|
-
static driver: AbstractDriver;
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* The connected models structured as `{ [model.name]: model }`, e.g. `Bone.model.Post => Post`
|
|
436
|
-
*/
|
|
437
|
-
static models: { [key: string]: typeof Bone };
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* The table name of the model, which needs to be specified by the model subclass.
|
|
441
|
-
*/
|
|
442
|
-
static table: string;
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* The plural model name in camelCase, e.g. `Post => posts`
|
|
446
|
-
*/
|
|
447
|
-
static tableAlias: string;
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* The primary key of the model, defaults to `id`.
|
|
451
|
-
*/
|
|
452
|
-
static primaryKey: string;
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* The primary column of the table, defaults to `id`. This is {@link Bone.primaryKey} in snake case.
|
|
456
|
-
*/
|
|
457
|
-
static primaryColumn: string;
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* The attribute definitions of the model.
|
|
461
|
-
*/
|
|
462
|
-
static attributes: { [key: string]: AbstractDataType<DataType> | AttributeMeta };
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* The schema info of current model.
|
|
466
|
-
*/
|
|
467
|
-
static columns: Array<AttributeMeta>;
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* If the table consists of multiple partition tables then a sharding key is needed to perform actual query. The sharding key can be specified through overridding this property, which will then be used to check the query before it hits database.
|
|
471
|
-
*/
|
|
472
|
-
static shardingKey: string;
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* If the table name is just an alias and the schema info can only be fetched by one of its partition table names, physic tables should be specified.
|
|
476
|
-
*/
|
|
477
|
-
static physicTables: string[];
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* restore rows
|
|
481
|
-
* @example
|
|
482
|
-
* Bone.restore({ title: 'aaa' })
|
|
483
|
-
* Bone.restore({ title: 'aaa' }, { hooks: false })
|
|
484
|
-
* @param conditions query conditions
|
|
485
|
-
* @param opts query options
|
|
486
|
-
*/
|
|
487
|
-
static restore<T extends typeof Bone>(this: T, conditions: Object, opts?: QueryOptions): Spell<T, number>;
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Override attribute metadata
|
|
491
|
-
* @example
|
|
492
|
-
* Bone.attribute('foo', { type: JSON })
|
|
493
|
-
*/
|
|
494
|
-
static attribute(name: string, meta: AttributeMeta): void;
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Rename attribute
|
|
498
|
-
* @example
|
|
499
|
-
* Bone.renameAttribute('foo', 'bar')
|
|
500
|
-
*/
|
|
501
|
-
static renameAttribute(originalName: string, newName: string): void;
|
|
502
|
-
|
|
503
|
-
static alias(name: string): string;
|
|
504
|
-
static alias(data: Record<string, Literal>): Record<string, Literal>;
|
|
505
|
-
static unalias(name: string): string;
|
|
506
|
-
|
|
507
|
-
static hasOne(name: string, opts?: AssociateOptions): void;
|
|
508
|
-
static hasMany(name: string, opts?: AssociateOptions): void;
|
|
509
|
-
static belongsTo(name: string, opts?: AssociateOptions): void;
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* INSERT rows
|
|
513
|
-
* @example
|
|
514
|
-
* Bone.create({ foo: 1, bar: 'baz' })
|
|
515
|
-
*/
|
|
516
|
-
static create<T extends typeof Bone>(this: T, values: Values<T>, options?: QueryOptions): Promise<InstanceType<T>>;
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* INSERT or UPDATE rows
|
|
520
|
-
* @example
|
|
521
|
-
* Bone.upsert(values, { hooks: false })
|
|
522
|
-
* @param values values
|
|
523
|
-
* @param opt query options
|
|
524
|
-
*/
|
|
525
|
-
static upsert<T extends typeof Bone>(this: T, values: Object, options?: QueryOptions): Spell<T, number>;
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Batch INSERT
|
|
529
|
-
*/
|
|
530
|
-
static bulkCreate<T extends typeof Bone>(this: T, records: Array<Record<string, Literal>>, options?: QueryOptions): Promise<Array<InstanceType<T>>>;
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* SELECT rows
|
|
534
|
-
* @example
|
|
535
|
-
* Bone.find('foo = ?', 1)
|
|
536
|
-
* Bone.find({ foo: { $eq: 1 } })
|
|
537
|
-
*/
|
|
538
|
-
static find<T extends typeof Bone>(this: T, whereConditions: WhereConditions<T>): Spell<T, Collection<InstanceType<T>>>;
|
|
539
|
-
static find<T extends typeof Bone>(this: T, whereConditions: string, ...values: Literal[]): Spell<T, Collection<InstanceType<T>>>;
|
|
540
|
-
static find<T extends typeof Bone>(this: T, primaryKey: number | number[]): Spell<T, Collection<InstanceType<T>>>;
|
|
541
|
-
static find<T extends typeof Bone>(this: T, ): Spell<T, Collection<InstanceType<T>>>;
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* SELECT all rows. In production, when the table is at large, it is not recommended to access records in this way. To iterate over all records, {@link Bone.batch} shall be considered as the better alternative. For tables with soft delete enabled, which means they've got `deletedAt` attribute, use {@link Bone.unscoped} to discard the default scope.
|
|
545
|
-
*/
|
|
546
|
-
static all: Spell<typeof Bone, Collection<Bone>>;
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* Discard all the applied scopes.
|
|
550
|
-
* @example
|
|
551
|
-
* Bone.all.unscoped // includes soft deleted rows
|
|
552
|
-
*/
|
|
553
|
-
static unscoped: Spell<typeof Bone>;
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* SELECT rows LIMIT 1. Besides limiting the results to one rows, the type of the return value is different from {@link Bone.find} too. If no results were found, {@link Bone.findOne} returns null. If results were found, it returns the found record instead of wrapping them as a collection.
|
|
557
|
-
* @example
|
|
558
|
-
* Bone.findOne('foo = ?', 1)
|
|
559
|
-
* Bone.findOne({ foo: { $eq: 1 } })
|
|
560
|
-
*/
|
|
561
|
-
static findOne<T extends typeof Bone>(this: T, whereConditions: WhereConditions<T>): Spell<T, InstanceType<T> | null>;
|
|
562
|
-
static findOne<T extends typeof Bone>(this: T, whereConditions: string, ...values: Literal[]): Spell<T, InstanceType<T> | null>;
|
|
563
|
-
static findOne<T extends typeof Bone>(this: T, primaryKey: number | number[]): Spell<T, InstanceType<T> | null>;
|
|
564
|
-
static findOne<T extends typeof Bone>(this: T, ): Spell<T, InstanceType<T> | null>;
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* SELECT rows OFFSET index LIMIT 1
|
|
568
|
-
* @example
|
|
569
|
-
* Bone.get(8)
|
|
570
|
-
* Bone.find({ foo: { $gt: 1 } }).get(42)
|
|
571
|
-
*/
|
|
572
|
-
static get<T extends typeof Bone>(this: T, index: number): Spell<T, InstanceType<T> | null>;
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* SELECT rows ORDER BY id ASC LIMIT 1
|
|
576
|
-
*/
|
|
577
|
-
static first: Spell<typeof Bone, Bone | null>;
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* SELECT rows ORDER BY id DESC LIMIT 1
|
|
581
|
-
*/
|
|
582
|
-
static last: Spell<typeof Bone, Bone | null>;
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Short of `Bone.find().with(...names)`
|
|
586
|
-
* @example
|
|
587
|
-
* Post.include('author', 'comments').where('posts.id = ?', 1)
|
|
588
|
-
*/
|
|
589
|
-
static include<T extends typeof Bone>(this: T, ...names: string[]) : Spell<T>;
|
|
590
|
-
|
|
591
|
-
/**
|
|
592
|
-
* Whitelist SELECT fields by names or filter function
|
|
593
|
-
* @example
|
|
594
|
-
* Bone.select('foo')
|
|
595
|
-
* Bone.select('foo, bar')
|
|
596
|
-
* Bone.select('foo', 'bar')
|
|
597
|
-
* Bone.select('MONTH(date), foo + 1')
|
|
598
|
-
* Bone.select(name => name !== foo)
|
|
599
|
-
*/
|
|
600
|
-
static select<T extends typeof Bone>(this: T, ...names: string[]): Spell<T>;
|
|
601
|
-
static select<T extends typeof Bone>(this: T, filter: (name: string) => boolean): Spell<T>;
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* JOIN arbitrary models with given ON conditions
|
|
605
|
-
* @example
|
|
606
|
-
* Bone.join(Muscle, 'bones.id == muscles.boneId')
|
|
607
|
-
*/
|
|
608
|
-
static join<T extends typeof Bone>(this: T, Model: Bone, onConditions: string, ...values: Literal[]): Spell<T, Collection<InstanceType<T>>>;
|
|
609
|
-
static join<T extends typeof Bone>(this: T, Model: Bone, onConditions: WhereConditions<T>): Spell<T, Collection<InstanceType<T>>>;
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Set WHERE conditions
|
|
613
|
-
* @example
|
|
614
|
-
* Bone.where('foo = ?', 1)
|
|
615
|
-
* Bone.where({ foo: { $eq: 1 } })
|
|
616
|
-
*/
|
|
617
|
-
static where<T extends typeof Bone>(this: T, whereConditions: string, ...values: Literal[]): Spell<T, Collection<InstanceType<T>>>;
|
|
618
|
-
static where<T extends typeof Bone>(this: T, whereConditions: WhereConditions<T>): Spell<T, Collection<InstanceType<T>>>;
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* Set GROUP fields
|
|
622
|
-
* @example
|
|
623
|
-
* Bone.group('foo')
|
|
624
|
-
* Bone.group('MONTH(createdAt)')
|
|
625
|
-
*/
|
|
626
|
-
static group<T extends typeof Bone>(this: T, ...names: string[]): Spell<T, ResultSet>;
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Set ORDER fields
|
|
630
|
-
* @example
|
|
631
|
-
* Bone.order('foo')
|
|
632
|
-
* Bone.order('foo', 'desc')
|
|
633
|
-
* Bone.order({ foo: 'desc' })
|
|
634
|
-
*/
|
|
635
|
-
static order<T extends typeof Bone>(this: T, name: string, order?: 'desc' | 'asc'): Spell<T>;
|
|
636
|
-
static order<T extends typeof Bone>(this: T, opts: OrderOptions): Spell<T>;
|
|
637
|
-
|
|
638
|
-
static count<T extends typeof Bone>(this: T, name?: string): Spell<T, ResultSet | number>;
|
|
639
|
-
static average<T extends typeof Bone>(this: T, name?: string): Spell<T, ResultSet | number>;
|
|
640
|
-
static minimum<T extends typeof Bone>(this: T, name?: string): Spell<T, ResultSet | number>;
|
|
641
|
-
static maximum<T extends typeof Bone>(this: T, name?: string): Spell<T, ResultSet | number>;
|
|
642
|
-
static sum<T extends typeof Bone>(this: T, name?: string): Spell<T, ResultSet | number>;
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* UPDATE rows.
|
|
646
|
-
*/
|
|
647
|
-
static update<T extends typeof Bone>(this: T, whereConditions: WhereConditions<T>, values?: Object, opts?: QueryOptions): Spell<T, number>;
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
* Remove rows. If soft delete is applied, an UPDATE query is performed instead of DELETing records directly. Set `forceDelete` to true to force a `DELETE` query.
|
|
651
|
-
*/
|
|
652
|
-
static remove<T extends typeof Bone>(this: T, whereConditions: WhereConditions<T>, forceDelete?: boolean, opt?: QueryOptions): Spell<T, number>;
|
|
653
|
-
|
|
654
|
-
/**
|
|
655
|
-
* Grabs a connection and starts a transaction process. Both GeneratorFunction and AsyncFunction are acceptable. If GeneratorFunction is used, the connection of the transaction process will be passed around automatically.
|
|
656
|
-
* @example
|
|
657
|
-
* Bone.transaction(function* () {
|
|
658
|
-
* const bone = yield Bone.create({ foo: 1 })
|
|
659
|
-
* yield Muscle.create({ boneId: bone.id, bar: 1 })
|
|
660
|
-
* });
|
|
661
|
-
*/
|
|
662
|
-
static transaction(callback: GeneratorFunction): Promise<RawQueryResult>;
|
|
663
|
-
static transaction(callback: (connection: TransactionOptions) => Promise<RawQueryResult | void>): Promise<RawQueryResult>;
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
* DROP the table
|
|
667
|
-
*/
|
|
668
|
-
static drop(): Promise<void>;
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* TRUNCATE table to clear records.
|
|
672
|
-
*/
|
|
673
|
-
static truncate(): Promise<void>;
|
|
674
|
-
|
|
675
|
-
static sync(options: SyncOptions): Promise<void>;
|
|
676
|
-
|
|
677
|
-
static initialize(): void;
|
|
678
|
-
|
|
679
|
-
constructor(values: { [key: string]: Literal }, opts?: { isNewRecord?: boolean });
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* @example
|
|
683
|
-
* bone.attribute('foo'); // => 1
|
|
684
|
-
* bone.attribute('foo', 2); // => bone
|
|
685
|
-
*/
|
|
686
|
-
attribute(name: string, value: Literal): void;
|
|
687
|
-
attribute(name: string): Literal;
|
|
688
|
-
|
|
689
|
-
/**
|
|
690
|
-
* Get the original attribute value.
|
|
691
|
-
* @example
|
|
692
|
-
* bone.attributeWas('foo') // => 1
|
|
693
|
-
*/
|
|
694
|
-
attributeWas(name: string): Literal;
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* See if attribute has been changed or not.
|
|
698
|
-
* @deprecated {@link Bone#changed} is preferred
|
|
699
|
-
* @example
|
|
700
|
-
* bone.attributeChanged('foo')
|
|
701
|
-
*/
|
|
702
|
-
attributeChanged(name: string): boolean;
|
|
703
|
-
|
|
704
|
-
/**
|
|
705
|
-
* Get changed attributes or check if given attribute is changed or not
|
|
706
|
-
*/
|
|
707
|
-
changed(name: string): boolean;
|
|
708
|
-
changed(): Array<string> | false;
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
* Get attribute changes
|
|
712
|
-
*/
|
|
713
|
-
changes(name: string): Record<string, [ Literal, Literal ]>;
|
|
714
|
-
changes(): Record<string, [ Literal, Literal ]>;
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
* See if attribute was changed previously or not.
|
|
718
|
-
*/
|
|
719
|
-
previousChanged(name: string): boolean;
|
|
720
|
-
previousChanged(): Array<string>;
|
|
721
|
-
|
|
722
|
-
previousChanges(name: string): boolean;
|
|
723
|
-
previousChanges(): Array<string>;
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* Persist changes of current record to database. If current record has never been saved before, an INSERT query is performed. If the primary key was set and is not changed since, an UPDATE query is performed. If the primary key is changed, an INSERT ... UPDATE query is performed instead.
|
|
727
|
-
*
|
|
728
|
-
* If `affectedRows` is needed, consider using the corresponding methods directly.
|
|
729
|
-
* @example
|
|
730
|
-
* new Bone({ foo: 1 }).save() // => INSERT
|
|
731
|
-
* new Bone({ foo: 1, id: 1 }).save() // => INSERT ... UPDATE
|
|
732
|
-
* (await Bone.fist).attribute('foo', 2).save() // => UPDATE
|
|
733
|
-
* new Bone({ foo: 1, id: 1 }).save({ hooks: false }) // => INSERT ... UPDATE
|
|
734
|
-
*/
|
|
735
|
-
save(opts?: QueryOptions): Promise<this>;
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Remove current record. If `deletedAt` attribute exists, then instead of DELETing records from database directly, the records will have their `deletedAt` attribute UPDATEd instead. To force `DELETE`, no matter the existence of `deletedAt` attribute, pass `true` as the argument.
|
|
739
|
-
* @example
|
|
740
|
-
* bone.remove() // => UPDATE ... SET deleted_at = now() WHERE ...
|
|
741
|
-
* bone.remove(true) // => DELETE FROM ... WHERE ...
|
|
742
|
-
* bone.remove(true, { hooks: false })
|
|
743
|
-
*/
|
|
744
|
-
remove(forceDelete?: boolean): Promise<number>;
|
|
745
|
-
remove(forceDelete?: boolean, opts?: QueryOptions): Promise<number>;
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
* update or insert record.
|
|
749
|
-
* @example
|
|
750
|
-
* bone.upsert() // INERT ... VALUES ON DUPLICATE KEY UPDATE ...
|
|
751
|
-
* bone.upsert({ hooks: false })
|
|
752
|
-
* @param opts queryOptions
|
|
753
|
-
*/
|
|
754
|
-
upsert(opts?: QueryOptions): Promise<number>;
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* update rows
|
|
758
|
-
* @param changes data changes
|
|
759
|
-
* @param opts query options
|
|
760
|
-
*/
|
|
761
|
-
update(changes: Object, opts?: QueryOptions): Promise<number>;
|
|
762
|
-
|
|
763
|
-
/**
|
|
764
|
-
* create instance
|
|
765
|
-
* @param opts query options
|
|
766
|
-
*/
|
|
767
|
-
create(opts?: QueryOptions): Promise<this>;
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
* reload instance
|
|
771
|
-
*/
|
|
772
|
-
reload(): Promise<this>;
|
|
773
|
-
|
|
774
|
-
/**
|
|
775
|
-
* restore data
|
|
776
|
-
* @param opts query options
|
|
777
|
-
*/
|
|
778
|
-
restore(opts?: QueryOptions): Promise<this>;
|
|
779
|
-
|
|
780
|
-
/**
|
|
781
|
-
* Gets called when `JSON.stringify(instance)` is invoked.
|
|
782
|
-
* {@link Bone#toJSON} might be called on descents of Bone that does not have attributes defined on them directly, hence for..in is preferred.
|
|
783
|
-
* - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
|
|
784
|
-
* @example
|
|
785
|
-
* const post = await Post.first
|
|
786
|
-
* post.toJSON() // => { id: 1, ... }
|
|
787
|
-
* @return {Object}
|
|
788
|
-
*/
|
|
789
|
-
toJSON(): InstanceValues<this>;
|
|
790
|
-
|
|
791
|
-
/**
|
|
792
|
-
* This is the loyal twin of {@link Bone#toJSON} because when generating the result object, the raw values of attributes are used, instead of the values returned by custom getters (if any).
|
|
793
|
-
* {@link Bone#toObject} might be called on descents of Bone that does not have attributes defined on them directly, hence for..in is preferred.
|
|
794
|
-
* - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
|
|
795
|
-
* @example
|
|
796
|
-
* const post = await Post.first
|
|
797
|
-
* post.toObject() // => { id: 1, ... }
|
|
798
|
-
* @return {Object}
|
|
799
|
-
*/
|
|
800
|
-
toObject(): InstanceValues<this>;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
export interface ConnectOptions {
|
|
804
|
-
client?: 'mysql' | 'mysql2' | 'pg' | 'sqlite3' | '@journeyapps/sqlcipher';
|
|
805
|
-
dialect?: 'mysql' | 'postgres' | 'sqlite';
|
|
806
|
-
host?: string;
|
|
807
|
-
port?: number | string;
|
|
808
|
-
user?: string;
|
|
809
|
-
password?: string;
|
|
810
|
-
database: string;
|
|
811
|
-
charset?: string;
|
|
812
|
-
models?: string | (typeof Bone)[];
|
|
813
|
-
subclass?: boolean;
|
|
814
|
-
driver?: typeof AbstractDriver;
|
|
815
|
-
}
|
|
25
|
+
export * from './src/decorators';
|
|
26
|
+
export * from './src/drivers';
|
|
27
|
+
export * from './src/adapters/sequelize';
|
|
816
28
|
|
|
817
29
|
interface InitOptions {
|
|
818
30
|
underscored?: boolean;
|
|
819
31
|
tableName?: string;
|
|
820
32
|
hooks?: {
|
|
821
|
-
[key in
|
|
33
|
+
[key in BeforeHooksType ]: (options: QueryOptions) => Promise<void>
|
|
822
34
|
} | {
|
|
823
|
-
[key in
|
|
35
|
+
[key in AfterHooksType ]: (instance: Bone, result: Object) => Promise<void>
|
|
824
36
|
};
|
|
825
37
|
}
|
|
826
38
|
|