leoric 2.6.0 → 2.6.3

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 ADDED
@@ -0,0 +1,760 @@
1
+ 2.6.3 / 2022-08-04
2
+ ==================
3
+
4
+ ## What's Changed
5
+ * fix: aggregator not parse null result by @killagu in https://github.com/cyjake/leoric/pull/322
6
+ * test: switch the auth protocol of test mysql database by @cyjake in https://github.com/cyjake/leoric/pull/323
7
+ * feat: add leoric_bone meta data to Bone by @JimmyDaddy in https://github.com/cyjake/leoric/pull/324
8
+ * docs: fix declarations of findOne(primaryKey) & findOne({ $or }) by @cyjake in https://github.com/cyjake/leoric/pull/325
9
+
10
+
11
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.6.2...v2.6.3
12
+
13
+ 2.6.2 / 2022-07-12
14
+ ==================
15
+
16
+ ## What's Changed
17
+ * fix: format select with out * if use aggreator by @killagu in https://github.com/cyjake/leoric/pull/320
18
+ * fix: fix transaction typing by @killagu in https://github.com/cyjake/leoric/pull/321
19
+
20
+ ## New Contributors
21
+ * @killagu made their first contribution in https://github.com/cyjake/leoric/pull/320
22
+
23
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.6.1...v2.6.2
24
+
25
+ 2.6.1 / 2022-06-24
26
+ ==================
27
+
28
+ ## What's Changed
29
+ * build: switch to latest postgres by @cyjake in https://github.com/cyjake/leoric/pull/316
30
+ * fix: fix [bug] init models with bone class should work #317 by @JimmyDaddy in https://github.com/cyjake/leoric/pull/318
31
+
32
+
33
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.6.0...v2.6.1
34
+
35
+ 2.6.0 / 2022-06-02
36
+ ==================
37
+
38
+ ## What's Changed
39
+ * feat: support export sql query template in logger by @JimmyDaddy in https://github.com/cyjake/leoric/pull/314
40
+ * fix: fix uncast date string without milliseconds error by jsCore in Android/iOS by @JimmyDaddy in https://github.com/cyjake/leoric/pull/315
41
+
42
+
43
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.5.0...v2.6.0
44
+
45
+ 2.5.0 / 2022-05-13
46
+ ==================
47
+
48
+ ## What's Changed
49
+ * feat: support disconnect and fix timestamps init by @JimmyDaddy in https://github.com/cyjake/leoric/pull/313
50
+
51
+
52
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.4.1...v2.5.0
53
+
54
+ 2.4.1 / 2022-04-27
55
+ ==================
56
+
57
+ ## What's Changed
58
+ * fix: realm.Bone.DataTypes should be invokable, Invokable.TYPE.toSqlString() get wrong default length(1), DataType definitions by @JimmyDaddy in https://github.com/cyjake/leoric/pull/307
59
+
60
+
61
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.4.0...v2.4.1
62
+
63
+ 2.4.0 / 2022-04-24
64
+ ==================
65
+
66
+ ## What's Changed
67
+ * feat: support custom driver by @JimmyDaddy in https://github.com/cyjake/leoric/pull/304
68
+ * chore: update build status badge by @snapre in https://github.com/cyjake/leoric/pull/305
69
+ * feat: export more ts type definitions and use deep-equal module by @JimmyDaddy in https://github.com/cyjake/leoric/pull/306
70
+
71
+ ## New Contributors
72
+ * @snapre made their first contribution in https://github.com/cyjake/leoric/pull/305
73
+
74
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.3.2...v2.4.0
75
+
76
+ 2.3.2 / 2022-04-15
77
+ ==================
78
+
79
+ ## What's Changed
80
+ * fix: order by raw with mix-type array in sequelize mode by @JimmyDaddy in https://github.com/cyjake/leoric/pull/298
81
+ * docs: monthly updates and example about egg-orm usage with TypeScript by @cyjake in https://github.com/cyjake/leoric/pull/299
82
+ * docs: monthly updates in en & docmentation about typescript support by @cyjake in https://github.com/cyjake/leoric/pull/300
83
+ * fix: raw query should format replacements with extra blank by @JimmyDaddy in https://github.com/cyjake/leoric/pull/301
84
+ * docs: elaborate on querying by @cyjake in https://github.com/cyjake/leoric/pull/302
85
+ * feat: transaction should return result by @JimmyDaddy in https://github.com/cyjake/leoric/pull/303
86
+
87
+
88
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.3.1...v2.3.2
89
+
90
+ 2.3.1 / 2022-03-22
91
+ ==================
92
+
93
+ ## What's Changed
94
+ * fix: mysql2 Invalid Date compatible by @JimmyDaddy in https://github.com/cyjake/leoric/pull/291
95
+ * fix: order by raw in sequelize mode by @JimmyDaddy in https://github.com/cyjake/leoric/pull/292
96
+ * fix: bulk update query conditions duplicated in sequelize mode by @JimmyDaddy in https://github.com/cyjake/leoric/pull/293
97
+ * fix: bulk destroy query conditions duplicated in sequelize mode by @JimmyDaddy in https://github.com/cyjake/leoric/pull/295
98
+ * fix: drop column if not defined in attributes when alter table by @cyjake in https://github.com/cyjake/leoric/pull/296
99
+
100
+
101
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.3.0...v2.3.1
102
+
103
+ 2.3.0 / 2022-03-10
104
+ ==================
105
+
106
+ ## What's Changed
107
+ * feat: model declaration with decorators by @cyjake in https://github.com/cyjake/leoric/pull/287
108
+ * feat: add VIRTUAL data type by @JimmyDaddy in https://github.com/cyjake/leoric/pull/289
109
+ * fix: create instance dirty check rule fix by @JimmyDaddy in https://github.com/cyjake/leoric/pull/290
110
+
111
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.2.3...v2.3.0
112
+ 2.2.3 / 2022-03-01
113
+ ==================
114
+
115
+ ## What's Changed
116
+ * fix: normalize attribute defaultValue by @cyjake in https://github.com/cyjake/leoric/pull/285
117
+ * fix: instance beforeUpdate hooks should not modify any Raw if there are no Raw assignment in them by @JimmyDaddy in https://github.com/cyjake/leoric/pull/283
118
+
119
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.2.2...v2.2.3
120
+
121
+ 2.2.2 / 2022-02-28
122
+ ==================
123
+
124
+ ## What's Changed
125
+ * fix: tddl gives misleading information_schema.columns.table_name by @cyjake in https://github.com/cyjake/leoric/pull/284
126
+
127
+
128
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.2.1...v2.2.2
129
+
130
+ 2.2.1 / 2022-02-24
131
+ ==================
132
+
133
+ ## What's Changed
134
+ * fix: realm.DataTypes should be invokable by @cyjake in https://github.com/cyjake/leoric/pull/282
135
+
136
+
137
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.2.0...v2.2.1
138
+
139
+ 2.2.0 / 2022-02-24
140
+ ==================
141
+
142
+ ## What's Changed
143
+ * fix: add missing `password` field for `ConnectOptions` by @luckydrq in https://github.com/cyjake/leoric/pull/280
144
+ * feat: integer types (mostly mysql specific) by @cyjake in https://github.com/cyjake/leoric/pull/281
145
+
146
+
147
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.1.1...v2.2.0
148
+
149
+ 2.1.1 / 2022-02-23
150
+ ==================
151
+
152
+ ## What's Changed
153
+ * fix: fix #274 update with fields option by @JimmyDaddy in https://github.com/cyjake/leoric/pull/275
154
+ * fix: upsert should set createdAt by default while createdAt not set by @JimmyDaddy in https://github.com/cyjake/leoric/pull/277
155
+ * fix: previousChanges should check instance is new record or not while specific attributes' values were undefined by @JimmyDaddy in https://github.com/cyjake/leoric/pull/276
156
+ * docs: add types for realm by @luckydrq in https://github.com/cyjake/leoric/pull/278
157
+
158
+ ## New Contributors
159
+ * @luckydrq made their first contribution in https://github.com/cyjake/leoric/pull/278
160
+
161
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.1.0...v2.1.1
162
+
163
+ 2.1.0 / 2022-02-17
164
+ ==================
165
+
166
+ ## What's Changed
167
+ * feat: fix #270 sequelize mode bulkBuild by @JimmyDaddy in https://github.com/cyjake/leoric/pull/273
168
+ * fix: mysql delete/remove/destroy with limit and orders by @JimmyDaddy in https://github.com/cyjake/leoric/pull/272
169
+
170
+
171
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.4...v2.1.0
172
+
173
+ 2.0.4 / 2022-02-16
174
+ ==================
175
+
176
+ ## What's Changed
177
+ * fix: fix unit test error by @LB4027221 in https://github.com/cyjake/leoric/pull/269
178
+ * fix: attribute.defaultValue should be set when init attributes by @cyjake in https://github.com/cyjake/leoric/pull/271
179
+
180
+
181
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.3...v2.0.4
182
+
183
+ 2.0.3 / 2022-02-11
184
+ ==================
185
+
186
+ ## What's Changed
187
+ * fix: default updatedAt to new date if model has no createdAt by @LB4027221 in https://github.com/cyjake/leoric/pull/268
188
+
189
+ ## New Contributors
190
+ * @LB4027221 made their first contribution in https://github.com/cyjake/leoric/pull/268
191
+
192
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.2...v2.0.3
193
+
194
+ 2.0.2 / 2022-02-10
195
+ ==================
196
+
197
+ ## What's Changed
198
+ * fix: order by alias should not throw by @cyjake in https://github.com/cyjake/leoric/pull/255
199
+ * fix: fix #257 DataType.uncast should skip Raw type at type checking by @JimmyDaddy in https://github.com/cyjake/leoric/pull/258
200
+ * docs: async function in transaction by @cyjake in https://github.com/cyjake/leoric/pull/259
201
+ * fix: fixed #256 static create instance should check all default attri… by @JimmyDaddy in https://github.com/cyjake/leoric/pull/262
202
+ * fix: fix #260 UPDATE with LIMIT and ORDER should be formatted(mysql only) by @JimmyDaddy in https://github.com/cyjake/leoric/pull/261
203
+ * refactor: keep the UPDATE ... ORDER BY ... LIMIT to mysql driver by @cyjake in https://github.com/cyjake/leoric/pull/264
204
+ * fix: fix #263 upsert attributes should use defaultValue while there i… by @JimmyDaddy in https://github.com/cyjake/leoric/pull/265
205
+ * fix: fix restore Error `Undefined attribute "deletedAt"` by @JimmyDaddy in https://github.com/cyjake/leoric/pull/267
206
+ * fix: type checking adaption by @JimmyDaddy in https://github.com/cyjake/leoric/pull/266
207
+
208
+
209
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.1...v2.0.2
210
+
211
+ 2.0.1 / 2022-01-05
212
+ ==================
213
+
214
+ ## What's Changed
215
+ * fix: format numeric result by @JimmyDaddy in https://github.com/cyjake/leoric/pull/253
216
+ * fix: should still return number if value is '0.000' by @cyjake in https://github.com/cyjake/leoric/pull/254
217
+
218
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.15.1...v2.0.1
219
+
220
+ 2.0.0 / 2021-12-28
221
+ ==================
222
+
223
+ ## What's Changed
224
+ * breaking: model.sync add force/alter option by @SmartOrange in https://github.com/cyjake/leoric/pull/224
225
+ * breaking: logQueryError(err, sql, duration, options) by @cyjake in https://github.com/cyjake/leoric/pull/237
226
+ * test: add utf8mb4 test cases by @fengmk2 in https://github.com/cyjake/leoric/pull/239
227
+ * Merge 1.x changes by @cyjake in https://github.com/cyjake/leoric/pull/249
228
+
229
+ ## New Contributors
230
+ * @SmartOrange made their first contribution in https://github.com/cyjake/leoric/pull/222
231
+
232
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.15.1...v2.0.0
233
+
234
+ 1.15.1 / 2021-12-28
235
+ ===================
236
+
237
+ ## What's Changed
238
+ * fix: fix #242 date string format by @JimmyDaddy in https://github.com/cyjake/leoric/pull/243
239
+ * fix: update with empty conditions by @JimmyDaddy in https://github.com/cyjake/leoric/pull/241
240
+ * fix: silent option's priority should be lower than valueSet by @JimmyDaddy in https://github.com/cyjake/leoric/pull/244
241
+ * fix: information_schema.columns.datetime_precision by @cyjake in https://github.com/cyjake/leoric/pull/246
242
+ * fix: should not hoist subquery if query is ordered by external columns by @cyjake in https://github.com/cyjake/leoric/pull/247
243
+
244
+
245
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.15.0...v1.15.1
246
+
247
+ 1.15.0 / 2021-11-22
248
+ ===================
249
+
250
+ ## What's Changed
251
+ * feat: make duration in precise milliseconds by @fengmk2 in https://github.com/cyjake/leoric/pull/236
252
+ * fix: spell.increment() & spell.decrement() @cyjake https://github.com/cyjake/leoric/pull/234
253
+ * fix: bulkCreate should adapte empty data @JimmyDaddy https://github.com/cyjake/leoric/pull/232
254
+
255
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.4...v1.14.5
256
+
257
+ 1.14.4 / 2021-11-15
258
+ ===================
259
+
260
+ ## What's Changed
261
+
262
+ * test: PostgreSQL v14 test case compatibility by @cyjake https://github.com/cyjake/leoric/pull/230
263
+ * fix: turn off subquery optimization if query criteria contains other column by @cyjake https://github.com/cyjake/leoric/pull/229
264
+ * fix: bone.changed() return `false | string[]` type by @fengmk2 https://github.com/cyjake/leoric/pull/231
265
+
266
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.3...v1.14.4
267
+
268
+ 1.14.3 / 2021-11-12
269
+ ===================
270
+
271
+ ## What's Changed
272
+ * fix: logger.logQuery should be guarded in case of error by @SmartOrange in https://github.com/cyjake/leoric/pull/222
273
+ * fix: findOne without result should return null by @JimmyDaddy in https://github.com/cyjake/leoric/pull/225
274
+ * fix: Literal should support bigint type by @fengmk2 in https://github.com/cyjake/leoric/pull/226
275
+ * fix: select((name: string) => boolean) by @cyjake in https://github.com/cyjake/leoric/pull/227
276
+
277
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.2...v1.14.3
278
+
279
+ 1.14.2 / 2021-11-01
280
+ ===================
281
+
282
+ ## What's Changed
283
+ * fix: accept timestamps in snake case by @cyjake in https://github.com/cyjake/leoric/pull/221
284
+
285
+
286
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.1...v1.14.2
287
+
288
+ 1.14.1 / 2021-11-01
289
+ ===================
290
+
291
+ ## What's Changed
292
+ * docs: export { Collection } by @cyjake in https://github.com/cyjake/leoric/pull/220
293
+
294
+
295
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.0...v1.14.1
296
+
297
+ 1.14.0 / 2021-11-01
298
+ ===================
299
+
300
+ Two options regarding `Model.init()` were added in this release:
301
+
302
+ ```js
303
+ class User extends Bone {}
304
+ User.init({ name: STRING }, {
305
+ timestamps: true, // which is the default
306
+ paranoid: true, // which default to `false`
307
+ });
308
+ assert.deepEqual(Object.keys(User.attributes), [
309
+ 'id',
310
+ 'name',
311
+ 'createdAt',
312
+ 'updatedAt',
313
+ 'deletedAt',
314
+ ]);
315
+ ```
316
+
317
+ ## What's Changed
318
+ * docs: update 'primayKey' typos by @freshgum-bubbles in https://github.com/cyjake/leoric/pull/211
319
+ * docs: DataTypes definitions in d.ts by @cyjake in https://github.com/cyjake/leoric/pull/210
320
+ * fix: fix#209 sequelize mode should update all changed fields in instance update method by @JimmyDaddy in https://github.com/cyjake/leoric/pull/212
321
+ * fix: fix #213 findAndCountAll should ignore attributes by @JimmyDaddy in https://github.com/cyjake/leoric/pull/214
322
+ * fix: opts.connectTimeout by @cyjake in https://github.com/cyjake/leoric/pull/216
323
+ * fix: reload instance with sharding key should not throw by @cyjake in https://github.com/cyjake/leoric/pull/217
324
+ * feat: timestamps should be defined by default by @cyjake in https://github.com/cyjake/leoric/pull/218
325
+ * fix: instance.reload() should not rely on `static findOne()` by @cyjake in https://github.com/cyjake/leoric/pull/219
326
+
327
+ ## New Contributors
328
+ * @freshgum-bubbles made their first contribution in https://github.com/cyjake/leoric/pull/211
329
+
330
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.5...v1.14.0
331
+
332
+ 1.13.5 / 2021-10-26
333
+ ===================
334
+
335
+ ## What's Changed
336
+ * docs: enhance aggregation query types & fix raw query result type by @cyjake in https://github.com/cyjake/leoric/pull/208
337
+
338
+
339
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.4...v1.13.5
340
+
341
+ 1.13.4 / 2021-10-25
342
+ ===================
343
+
344
+ ## What's Changed
345
+ * docs: spell & model methods should be generic by @cyjake in https://github.com/cyjake/leoric/pull/206
346
+ * docs: enhance query options, instance type, and toJSON() result type by @cyjake in https://github.com/cyjake/leoric/pull/207
347
+
348
+ This version brings correct (and hopefully better) typescript definitions, with the dts checked continuously at test/types tests. With this version, users that have model types correctly pinned at Bone will get code completion including class fields. Such as:
349
+
350
+ ![image](https://user-images.githubusercontent.com/252317/138683240-98ee9e79-4b3e-449c-bc95-a449d457d64f.png)
351
+
352
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.3...v1.13.4
353
+
354
+ 1.13.3 / 2021-10-21
355
+ ===================
356
+
357
+ ## What's Changed
358
+ * refactor: persist edge cases of type casting in integration tests by @cyjake in https://github.com/cyjake/leoric/pull/202
359
+ * docs: renaming attributes by @cyjake in https://github.com/cyjake/leoric/pull/203
360
+ * fix: JSON.uncast(string) should not serialize twice by @cyjake in https://github.com/cyjake/leoric/pull/205
361
+
362
+
363
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.2...v1.13.3
364
+
365
+ 1.13.2 / 2021-10-18
366
+ ===================
367
+
368
+ ## What's Changed
369
+ * fix: attribute.uncast([]) and realm.connect with synchronized models by @cyjake in https://github.com/cyjake/leoric/pull/201
370
+
371
+
372
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.1...v1.13.2
373
+
374
+ 1.13.1 / 2021-10-18
375
+ ===================
376
+
377
+ ## What's Changed
378
+ * fix: skip connecting if models are synchronized already by @cyjake in https://github.com/cyjake/leoric/pull/200
379
+
380
+
381
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.0...v1.13.1
382
+
383
+ 1.13.0 / 2021-10-18
384
+ ===================
385
+
386
+ ## What's Changed
387
+ * docs: monthly updates of 2021.09; support dark mode by @cyjake in https://github.com/cyjake/leoric/pull/196
388
+ * feat: coerce literal values into accurate attribute type by @cyjake in https://github.com/cyjake/leoric/pull/197
389
+ * fix: dispatched result should be in attribute names by @cyjake in https://github.com/cyjake/leoric/pull/198
390
+
391
+
392
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.12.0...v1.13.0
393
+
394
+ 1.12.0 / 2021-10-12
395
+ ===================
396
+
397
+ * feat: support custom fields query and sequelize mode export rawAttributes (#192)
398
+ * refactor: collection format query result (#194)
399
+ * refactor: object condition parsing and expression formatting (#191)
400
+
401
+ 1.11.1 / 2021-09-28
402
+ ===================
403
+
404
+ This version fixes lots of issues regarding logical operator in object conditions.
405
+
406
+ * fix: logical operator with multiple conditions such as (#190)
407
+ * fix: sequelize mode support HAVING, and select fields raw sql support (#187)
408
+ * fix: support len validator (#188)
409
+ * fix: normalize logical operator conditions before formatting with spellbook (#186)
410
+
411
+ 1.11.0 / 2021-09-24
412
+ ===================
413
+
414
+ * feat: support BINARY(length), VARBINARY(length), and BLOB (#169)
415
+ * fix: logic operate should adapt one argument (#183)
416
+ * fix: Bone.load() should be idempotent, make sure associations is intact (#184)
417
+ * fix: selected instance isNewRecord is false (#182)
418
+ * fix: set options.busyTimeout to mitigate SQLITE_BUSY (#176)
419
+ * fix: turn on long stack trace of sqlite driver (#175)
420
+ * docs: how to contribute (#180)
421
+
422
+ 1.10.0 / 2021-09-14
423
+ ===================
424
+
425
+ * feat: SQLite driver should emit "connection" event when new connection is created (#168)
426
+ * fix: bulkCreate(...records) should recognize custom setters (#168)
427
+ * fix: attribute.equals() check should ignore defaultValue (#172)
428
+
429
+ 1.9.0 / 2021-09-04
430
+ ==================
431
+
432
+ > should've been a major release but since existing users have all migrated to the new api...
433
+
434
+ * breaking: drop the deprecated `Model.describe()` (#167)
435
+
436
+ 1.8.0 / 2021-08-30
437
+ ==================
438
+
439
+ * feat: silent option fix #164 (#165)
440
+ * feat: binary type (#166)
441
+
442
+ 1.7.1 / 2021-08-17
443
+ ==================
444
+
445
+ * revert: drop Driver#recycleConnections due to poor interoperability (#162)
446
+ * fix: validator call array arguments (#160)
447
+
448
+ 1.7.0 / 2021-08-17
449
+ =================
450
+
451
+ * feat: close connections that exceeds opts.idleTimeout (#159)
452
+ * feat: `opts.connectionLimit` support for SQLite (#159)
453
+ * feat: raw query relpacements, closes #149 (#155)
454
+ * fix: upsert created_at default (#154)
455
+ * test: validator unit test (#157)
456
+ * test: setup_hooks unit test (#158)
457
+
458
+ 1.6.7 / 2021-08-05
459
+ ==================
460
+
461
+ * fix: prevent from calling Date.prototype.toJSON (#153)
462
+
463
+ 1.6.6 / 2021-07-22
464
+ ==================
465
+
466
+ * fix: subclassing data type in dialects (#145)
467
+ * fix: where('width / height >= 16 / 9') (#144)
468
+ * docs: logging and sequelzie adapter (zh) (#142)
469
+ * test: include test/unit/utils (#143)
470
+ * test: more tests cases about sequelize adapter (#141)
471
+
472
+ 1.6.5 / 2021-07-16
473
+ ==================
474
+
475
+ * fix: define assign Bone.models #140
476
+
477
+ 1.6.4 / 2021-07-16
478
+ ==================
479
+
480
+ * refactor: connect({ Bone }) still necessary (#139)
481
+ * fix: formatting select join with subqueries should not tamper the subquery itself (#138)
482
+ * fix: describe table with more compatible syntax (#137)
483
+
484
+ 1.6.3 / 2021-07-14
485
+ ==================
486
+
487
+ * fix: transaction option passing in sequelize adapter (#136)
488
+ * fix: this.Model and proper Model.describe() (#135)
489
+
490
+ 1.6.2 / 2021-07-09
491
+ ==================
492
+
493
+ * fix: convert datetime in seconds/milliseconds back to Date (#134)
494
+ * fix: renamed attribute should remain enumerable (#133)
495
+
496
+ 1.6.1 / 2021-07-07
497
+ ==================
498
+
499
+ * fix: collection convert should handle tddl results as well (#132)
500
+
501
+ 1.6.0 / 2021-07-06
502
+ ==================
503
+
504
+ * feat: support class static attributes and hooks (#131)
505
+ * fix: names defined in Bone.attributes should always be enumerable (#128)
506
+ * chore: add quality badge to readme (#129)
507
+
508
+ 1.5.2 / 2021-07-02
509
+ ==================
510
+
511
+ * fix: leave the getter properties defined in class syntax as is (#127)
512
+
513
+ 1.5.1 / 2021-06-30
514
+ ==================
515
+
516
+ * fix: export Logger and Spell to let users intercept lower level api calls (#126)
517
+
518
+ 1.5.0 / 2021-06-30
519
+ ==================
520
+
521
+ * feat: provide Bone.pool to be backward compatible with v0.x (#124)
522
+ * feat: complete bone/spine.restore and Bone API type definitions (#125)
523
+ * feat: support more data types (mediumtext, mediumint, char, date...) (#123)
524
+
525
+ 1.4.1 / 2021-06-25
526
+ ==================
527
+
528
+ * refactor: simplify legacy timestamps support (#120)
529
+ * refactor: do not subclass Bone unless asked specifically (#120)
530
+
531
+ 1.4.0 / 2021-06-24
532
+ ==================
533
+
534
+ * feat: `realm.raw('SELECT ...')` and `Model.raw('SELECT ...')` (#94)
535
+ * feat: support multiple order rules in one single string or one-dimensional array (#92)
536
+ * feat: `Model.truncate()` now uses TRUNCATE if possible
537
+ * feat: `Model.find().optimizerHints('SET_VAR(foreign_key_checks=OFF)')`
538
+ * fix: Bone.bulkCreate() should not throw when called with non attribute (#117)
539
+ * fix: batch upsert (#108)
540
+ * fix: make sure connection is passed around in all queries carried out within transaction (#105)
541
+ * fix: update, sequelize mode get API, destroy compitable (#104)
542
+ * fix: `setDataValue` in sequelize adapter should not check prop name strictly
543
+ * refactor: spell_insert (#118)
544
+ * docs: about egg-orm & migrations (#119)
545
+ * docs: revise instructions for installing Jekyll (#111)
546
+ * docs: migrations, validations, hooks, and sequelize adapter (#103)
547
+ * docs: contributing guides
548
+
549
+ 1.3.0 / 2021-03-01
550
+ ==================
551
+
552
+ * feat: hook support
553
+ * feat: dirty check (`changes()` & `previousChanges()`)
554
+ * feat: compatible with mysql longtext conversion
555
+ * feat: NOT condition
556
+
557
+ 1.2.0 / 2020-12-10
558
+ ==================
559
+
560
+ * feat: `Realm.prototype.transaction()` with async function support
561
+ * feat: `Realm.prototype.query()` for raw queries
562
+ * feat: `logger.logQuery(sql, duration, { Model, command })`
563
+ * feat: `logger.logQueryError(sql, err, duration, { Model, command })`
564
+
565
+ 1.1.0 / 2020-11-23
566
+ ==================
567
+
568
+ * feat: JSON and JSONB data types
569
+ * feat: support `stringifyObjects` option for mysql client
570
+ * feat: aggregate functions for sequelize adapter
571
+ * feat: `Spell.prototype.nodeify()`
572
+
573
+ 1.0.3 / 2020-03-16
574
+ ==================
575
+
576
+ * fix: replace `deep-equal` (which is bloated) with `util.isDeepStrictEqual`
577
+
578
+ 1.0.2 / 2020-03-04
579
+ ==================
580
+
581
+ * fix: driver.alterTable() with multiple columns to add in SQLite
582
+
583
+ 1.0.1 / 2020-02-25
584
+ ==================
585
+
586
+ * fix: bulkCreate in sequelize shim
587
+
588
+ 1.0.0 / 2020-02-24
589
+ ==================
590
+
591
+ First major release. Let's get serious with semver.
592
+
593
+ * feat: logger.logQuery(sql, duration) & logger.logQueryError(sql, err)
594
+
595
+ 0.5.3 / 2020-02-22
596
+ ==================
597
+
598
+ * fix: `connect({ sequelize, dialect, client })` to allow mandatory sqlite client
599
+ * fix: prevent queries being performed unless model is correctly connected
600
+
601
+ 0.5.2 / 2020-02-21
602
+ ==================
603
+
604
+ * fix: drop the default and unused `require('sqlite3')`
605
+
606
+ 0.5.1 / 2020-02-21
607
+ ==================
608
+
609
+ * fix: `connect({ client: '@journeyapps/sqlcipher' })`
610
+
611
+ 0.5.0 / 2020-02-19
612
+ ==================
613
+
614
+ * feat: `Bone.sync()` to synchronize model with database
615
+ * feat: `Bone.createMigrationFile()` to create migration file
616
+ * feat: `Bone.migrate()` to run migrations
617
+ * feat: `Bone.bulkCreate()` to bulk insert records
618
+ * feat: `require('leoric')` now exports `Realm` to connect with multiple databases
619
+ * feat: `realm.define()` to define models in an old fashioned way
620
+ * feat: `realm.connect()` to connect with database
621
+ * feat: SQLite support without hacking node-sqlite3
622
+ * feat: `Bone.DataTypes` for type references
623
+ * feat: `Bone.init()` to initialize models
624
+ * feat: an adaptor to use Leoric in (partially) Sequelize complaint API
625
+ * refactor: a complete re-write of JOIN queries
626
+ * refactor: added `Bone.driver` to better encapsulate and planish database nuances
627
+
628
+ 0.4.5 / 2019-12-14
629
+ ==================
630
+
631
+ * fix: prevent primary key from being overridden with incorrect `LAST_INSERT_ID()`
632
+
633
+ 0.4.4 / 2019-07-15
634
+ ==================
635
+
636
+ * fix: append default scope when declaring relations, fixes #10
637
+
638
+ 0.4.3 / 2019-05-09
639
+ ==================
640
+
641
+ * fix: prevent Bone.dispatch from creating duplicated records of main table
642
+
643
+ 0.4.2 / 2019-04-26
644
+ ==================
645
+
646
+ * feat: `Spell#orWhere()` and `Spell#orHaving()`
647
+ * feat: arithmetic operators
648
+ * feat: unary operators such as unary minus `-` and bit invertion `~`
649
+ * fix: unset attribute should be overwritable
650
+ * fix: `attributeChanged()` should be false if attribute is unset and not overwritten
651
+ * fix: subclass with incomplete getter/setter should be complemented
652
+ * fix: sharding key validation on `Bone.update()` and `Bone.save()`
653
+ * fix: sharding key should be along with primary key on `bone.remove()`
654
+ * fix: `Bone.cast()` should leave `null` as is
655
+ * fix: `INSERT ... UPDATE` with `id = LAST_INSERT_ID(id)` in MySQL
656
+ * fix: `Model.find({ name: { $op1, $op2 } })` object conditions with multiple operators
657
+ * fix: prefixing result set with qualifiers if query contains join relations and is not dispatchable
658
+ * fix: `Spell#$get(index)` with LIMIT
659
+ * doc: `Model.transaction()`
660
+ * doc: definition types with `index.d.ts`
661
+
662
+ 0.4.1 / 2019-03-21
663
+ ==================
664
+
665
+ * feat: premature sharding key validation
666
+ * fix: output complete SQL instead of parameterized query with values.
667
+ * fix: both `connect({ model })` and `connect({ models })` are allowed.
668
+ * doc: no more `.findOrCreate()`, just `.upsert()`
669
+ * doc: table of contents with kramdown's `{:toc}`
670
+ * chore: droped experimental sqlite3 support
671
+
672
+ 0.4.0 / 2018-11-05
673
+ ==================
674
+
675
+ * feat: PostgreSQL support
676
+ * feat: Transaction support
677
+ * upgrade: (forked) SQLite client updated to SQLite 3.24
678
+
679
+
680
+ 0.3.0 / 2018-10-31
681
+ ==================
682
+
683
+ * feat: SQLite support with a [forked sqlite3](https://github.com/cyjake/node-sqlite3)
684
+ * feat: mysql2 support (which is trivial since both mysql and mysql2 share the same API)
685
+ * refactor: Spell now formats SQL with the literals separated, which gets escaped by the corresponding client itself later on.
686
+
687
+ 0.2.0 / 2018-01-03
688
+ ==================
689
+
690
+ * breaking: renaming
691
+
692
+ 0.1.8 / 2017-12-31
693
+ ==================
694
+
695
+ * fix: implement `query.batch()` as async iterator
696
+ * fix: `NOT (expr)`
697
+ * fix: `IFNULL(foo, default)`
698
+ * fix: support `.select(name[])`, `.select(name => {})`, and `.select("...name")`
699
+ * doc: `Model => className` in association options
700
+ * doc: use [jsdoc](http://usejsdoc.org) to generate docs/api
701
+ * doc: `.include()`
702
+
703
+ 0.1.7 / 2017-12-22
704
+ ==================
705
+
706
+ * refactor: `{ type: 'op', name: 'as' }` renamed to `{ type: 'alias' }`
707
+ * feat: `{ type: 'mod' }` for modifier, currently only `DISTINCT` is recognized
708
+ * feat: unary operators like `!` and `NOT`
709
+ * feat: `IS` and `IS NOT`
710
+ * fix: logic operator precendences
711
+ * fix: polymorphic hasMany({ through }) relations
712
+ * fix: dispatching multiple results with joins correctly
713
+
714
+ 0.1.6 / 2017-12-21
715
+ ==================
716
+
717
+ * feat: proper `.first`, `.last`, `.all`, and `.get(index)`
718
+ * fix: accept `Date`, `boolean`, and `Set` values
719
+ * fix: `Model.unscoped`
720
+ * fix: `Model.remove({}, true)` should be unscoped
721
+
722
+ 0.1.5 / 2017-12-20
723
+ ==================
724
+
725
+ * refactor: encapsulate column names. Keep them from the users even if the query results can not be dispatched.
726
+ * fix: complicated groups with joins should discard the use of subquery.
727
+ * fix: camelCase should replace globally
728
+ * fix: avoid missing attribtue exception when toJSON/toObject
729
+
730
+ 0.1.4 / 2017-12-18
731
+ ==================
732
+
733
+ * fix: should format condition arrays by hand instead of hand it over to formatExpr
734
+ * fix: whereConditions of subquery should retain the order of the whereConditions in major query
735
+ * fix: calculated columns should be kept in the final columns when sorting out the attributes
736
+ * fix: doesn't depend on co anymore
737
+
738
+ 0.1.3 / 2017-12-17
739
+ ==================
740
+
741
+ * fix: `select distict foo from table`;
742
+ * fix: `where (a = 1 or a = 2) and b = 3`;
743
+ * doc: a syntax table to provide a better glance over the querying ability.
744
+
745
+ 0.1.2 / 2017-12-14
746
+ ==================
747
+
748
+ * fix: copy left table's orders into subquery to make order/limit work when combined.
749
+ * fix: errors should be thrown when accessing attributes that weren't selected at the first place.
750
+
751
+ 0.1.1 / 2017-12-13
752
+ ==================
753
+
754
+ * refactor: automatic versioning on spells. When client calls query methods with chaining, new versions of spell gets duplicated. Makes reuse of spells possible.
755
+ * doc: english verion is almost complete <http://cyj.me/leoric>.
756
+
757
+ 0.1.0 / 2017-12-09
758
+ ==================
759
+
760
+ * Initial version, covers basic usage such as model authoring, database connection, query interface, and association.
package/index.js CHANGED
@@ -14,6 +14,7 @@ const Realm = require('./src/realm');
14
14
  const Decorators = require('./src/decorators');
15
15
  const Raw = require('./src/raw');
16
16
  const { MysqlDriver, PostgresDriver, SqliteDriver, AbstractDriver } = require('./src/drivers');
17
+ const { isBone } = require('./src/utils');
17
18
 
18
19
  /**
19
20
  * @typedef {Object} RawSql
@@ -64,6 +65,7 @@ Object.assign(Realm, {
64
65
  SqliteDriver,
65
66
  AbstractDriver,
66
67
  Raw,
68
+ isBone,
67
69
  });
68
70
 
69
71
  module.exports = Realm;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leoric",
3
- "version": "2.6.0",
3
+ "version": "2.6.3",
4
4
  "description": "JavaScript Object-relational mapping alchemy",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
package/src/bone.js CHANGED
@@ -21,6 +21,7 @@ const {
21
21
  LEGACY_TIMESTAMP_COLUMN_MAP,
22
22
  ASSOCIATE_METADATA_MAP,
23
23
  TIMESTAMP_ATTRIBUTE_NAMES,
24
+ IS_LEORIC_BONE,
24
25
  } = require('./constants');
25
26
 
26
27
  const columnAttributesKey = Symbol('leoric#columns');
@@ -1715,4 +1716,6 @@ for (const getter of Spell_getters) {
1715
1716
  });
1716
1717
  }
1717
1718
 
1719
+ Reflect.defineMetadata(IS_LEORIC_BONE, true, Bone);
1720
+
1718
1721
  module.exports = Bone;
package/src/collection.js CHANGED
@@ -1,8 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const { AGGREGATOR_MAP } = require('./constants');
4
-
5
- const AGGREGATORS = Object.values(AGGREGATOR_MAP);
6
3
  /**
7
4
  * An extended Array to represent collections of models.
8
5
  */
@@ -92,11 +89,6 @@ function dispatch(spell, rows, fields) {
92
89
  const row = rows[0];
93
90
  const record = row && (row[''] || row[table]);
94
91
  const result = record && record[value];
95
- // see https://www.w3schools.com/mysql/mysql_ref_functions.asp
96
- if (AGGREGATORS.includes(args[0].name)) {
97
- const num = Number(result);
98
- return isNaN(num) ? result : num;
99
- }
100
92
  return result;
101
93
  }
102
94
  }
package/src/constants.js CHANGED
@@ -8,6 +8,8 @@ const AGGREGATOR_MAP = {
8
8
  sum: 'sum'
9
9
  };
10
10
 
11
+ const AGGREGATORS = Object.values(AGGREGATOR_MAP);
12
+
11
13
  const LEGACY_TIMESTAMP_MAP = {
12
14
  gmtCreate: 'createdAt',
13
15
  gmtModified: 'updatedAt',
@@ -20,7 +22,7 @@ const LEGACY_TIMESTAMP_COLUMN_MAP = {
20
22
  deleted_at: 'gmt_deleted',
21
23
  };
22
24
 
23
- const TIMESTAMP_ATTRIBUTE_NAMES = [
25
+ const TIMESTAMP_ATTRIBUTE_NAMES = [
24
26
  'createdAt', 'updatedAt', 'deletedAt',
25
27
  'gmtCreate', 'gmtModified', 'gmtDeleted',
26
28
  'created_at', 'updated_at', 'deleted_at',
@@ -34,11 +36,15 @@ const ASSOCIATE_METADATA_MAP = {
34
36
  belongsTo: Symbol('belongsTo'),
35
37
  };
36
38
 
39
+ const IS_LEORIC_BONE = Symbol('leoric#bone');
40
+
37
41
  module.exports = {
38
42
  AGGREGATOR_MAP,
39
43
  LEGACY_TIMESTAMP_MAP,
40
44
  TIMESTAMP_NAMES,
41
45
  LEGACY_TIMESTAMP_COLUMN_MAP,
42
46
  ASSOCIATE_METADATA_MAP,
43
- TIMESTAMP_ATTRIBUTE_NAMES
47
+ TIMESTAMP_ATTRIBUTE_NAMES,
48
+ AGGREGATORS,
49
+ IS_LEORIC_BONE,
44
50
  };
package/src/data_types.js CHANGED
@@ -358,7 +358,8 @@ class DATE extends DataType {
358
358
  // @deprecated
359
359
  // vaguely standard date formats such as 2021-10-15 15:50:02,548
360
360
  if (typeof value === 'string' && rDateFormat.test(value)) {
361
- // 2021-10-15 15:50:02,548 => 2021-10-15T15:50:02,548, 2021-10-15 15:50:02 => 2021-10-15T15:50:02.000
361
+ // 2021-10-15 15:50:02,548 => 2021-10-15T15:50:02,548,
362
+ // 2021-10-15 15:50:02 => 2021-10-15T15:50:02.000
362
363
  value = new Date(`${value.replace(' ', 'T').replace(',', '.')}`);
363
364
  }
364
365
 
@@ -3,7 +3,7 @@
3
3
  const SqlString = require('sqlstring');
4
4
 
5
5
  const { copyExpr, findExpr, walkExpr } = require('../../expr');
6
- const { formatExpr, formatConditions, collectLiteral } = require('../../expr_formatter');
6
+ const { formatExpr, formatConditions, collectLiteral, isAggregatorExpr } = require('../../expr_formatter');
7
7
  const Raw = require('../../raw');
8
8
 
9
9
  /**
@@ -91,10 +91,12 @@ function formatSelectExpr(spell, values) {
91
91
  const baseName = Model.tableAlias;
92
92
  const selects = new Set();
93
93
  const map = {};
94
+ let isAggregate = false;
94
95
 
95
96
  for (const token of columns) {
96
97
  collectLiteral(spell, token, values);
97
98
  const selectExpr = formatExpr(spell, token);
99
+ isAggregate = isAggregate || isAggregatorExpr(spell, token);
98
100
  const qualifier = token.qualifiers ? token.qualifiers[0] : '';
99
101
  const list = map[qualifier] || (map[qualifier] = []);
100
102
  list.push(selectExpr);
@@ -104,7 +106,7 @@ function formatSelectExpr(spell, values) {
104
106
  const list = map[qualifier];
105
107
  if (list) {
106
108
  for (const selectExpr of list) selects.add(selectExpr);
107
- } else if (groups.length === 0 && Model.driver.type !== 'sqlite') {
109
+ } else if (groups.length === 0 && Model.driver.type !== 'sqlite' && !isAggregate) {
108
110
  selects.add(`${escapeId(qualifier)}.*`);
109
111
  }
110
112
  }
@@ -163,7 +165,7 @@ class SpellBook {
163
165
  const { escapeId } = Model.driver;
164
166
  let columns = [];
165
167
  let updateOnDuplicateColumns = [];
166
-
168
+
167
169
  let values = [];
168
170
  let placeholders = [];
169
171
  if (Array.isArray(sets)) {
@@ -181,14 +183,14 @@ class SpellBook {
181
183
  columnAttributes.push(Model.columnAttributes[name]);
182
184
  }
183
185
  }
184
-
186
+
185
187
  for (const entry of columnAttributes) {
186
188
  columns.push(entry.columnName);
187
- if (updateOnDuplicate && createdAt && entry.name === createdAt
189
+ if (updateOnDuplicate && createdAt && entry.name === createdAt
188
190
  && !(Array.isArray(updateOnDuplicate) && updateOnDuplicate.includes(createdAt))) continue;
189
191
  updateOnDuplicateColumns.push(entry.columnName);
190
192
  }
191
-
193
+
192
194
  for (const entry of sets) {
193
195
  if (shardingKey && entry[shardingKey] == null) {
194
196
  throw new Error(`Sharding key ${Model.table}.${shardingKey} cannot be NULL.`);
@@ -199,7 +201,7 @@ class SpellBook {
199
201
  }
200
202
  placeholders.push(`(${new Array(columnAttributes.length).fill('?').join(',')})`);
201
203
  }
202
-
204
+
203
205
  } else {
204
206
  if (shardingKey && sets[shardingKey] == null) {
205
207
  throw new Error(`Sharding key ${Model.table}.${shardingKey} cannot be NULL.`);
@@ -216,10 +218,10 @@ class SpellBook {
216
218
  updateOnDuplicateColumns.push(Model.unalias(name));
217
219
  }
218
220
  }
219
-
220
-
221
+
222
+
221
223
  const chunks = ['INSERT'];
222
-
224
+
223
225
  // see https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
224
226
  const hintStr = this.formatOptimizerHints(spell);
225
227
  if (hintStr) {
@@ -50,6 +50,7 @@ class MysqlDriver extends AbstractDriver {
50
50
  const {
51
51
  host, port, user, password,
52
52
  connectTimeout, connectionLimit, charset, stringifyObjects = true,
53
+ decimalNumbers = true,
53
54
  } = opts;
54
55
 
55
56
  if (client !== 'mysql' && client !== 'mysql2') {
@@ -66,6 +67,7 @@ class MysqlDriver extends AbstractDriver {
66
67
  database,
67
68
  charset,
68
69
  stringifyObjects,
70
+ decimalNumbers,
69
71
  });
70
72
  }
71
73
 
@@ -5,7 +5,7 @@ const { performance } = require('perf_hooks');
5
5
  const AbstractDriver = require('../abstract');
6
6
  const Attribute = require('./attribute');
7
7
  const DataTypes = require('./data_types');
8
- const {
8
+ const {
9
9
  escape, escapeId, formatAddColumn,
10
10
  formatAlterColumns, formatDropColumn,
11
11
  cast, nest, parameterize,
@@ -36,6 +36,9 @@ class PostgresDriver extends AbstractDriver {
36
36
 
37
37
  createPool(opts) {
38
38
  const { host, port, user, password, database } = opts;
39
+ // dynamic require pg type parse
40
+ // if not use pg, pg-types may not exits
41
+ require('./type_parser');
39
42
  return new (require('pg')).Pool({ host, port, user, password, database });
40
43
  }
41
44
 
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const pgTypes = require('pg-types');
4
+
5
+ pgTypes.setTypeParser(1700, 'text', function (val) {
6
+ return Number(val);
7
+ });
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const { precedes, walkExpr } = require('./expr');
4
+ const { AGGREGATORS } = require('./constants');
4
5
 
5
6
  /**
6
7
  * Find model by qualifiers.
@@ -65,6 +66,31 @@ function formatLiteral(spell, ast) {
65
66
  return '?';
66
67
  }
67
68
 
69
+ /**
70
+ * Format the abstract syntax tree of an expression into escaped string.
71
+ * @param {Spell} spell
72
+ * @param {Object} ast
73
+ */
74
+ function isAggregatorExpr(spell, ast) {
75
+ const { type, name, args } = ast;
76
+ switch (type) {
77
+ case 'literal':
78
+ case 'subquery':
79
+ case 'wildcard':
80
+ case 'mod':
81
+ case 'id':
82
+ case 'raw':
83
+ case 'op':
84
+ return false;
85
+ case 'alias':
86
+ return isAggregatorExpr(spell, args[0]);
87
+ case 'func':
88
+ return AGGREGATORS.includes(name);
89
+ default:
90
+ throw new Error(`Unexpected type ${type}`);
91
+ }
92
+ }
93
+
68
94
  /**
69
95
  * Format the abstract syntax tree of an expression into escaped string.
70
96
  * @param {Spell} spell
@@ -216,4 +242,4 @@ function coerceLiteral(spell, ast) {
216
242
  }
217
243
  }
218
244
 
219
- module.exports = { formatExpr, formatConditions, collectLiteral };
245
+ module.exports = { formatExpr, formatConditions, collectLiteral, isAggregatorExpr };
package/src/realm.js CHANGED
@@ -6,6 +6,7 @@ const path = require('path');
6
6
  const Bone = require('./bone');
7
7
  const { findDriver, AbstractDriver } = require('./drivers');
8
8
  const { camelCase } = require('./utils/string');
9
+ const { isBone } = require('./utils');
9
10
  const sequelize = require('./adapters/sequelize');
10
11
  const Raw = require('./raw');
11
12
  const { LEGACY_TIMESTAMP_MAP } = require('./constants');
@@ -33,7 +34,7 @@ async function findModels(dir) {
33
34
  const extname = path.extname(entry.name);
34
35
  if (entry.isFile() && ['.js', '.mjs'].includes(extname)) {
35
36
  const model = require(path.join(dir, entry.name));
36
- if (model.prototype instanceof Bone) models.push(model);
37
+ if (isBone(model)) models.push(model);
37
38
  }
38
39
  }
39
40
 
@@ -75,6 +76,10 @@ async function loadModels(Spine, models, opts) {
75
76
  const schemaInfo = await Spine.driver.querySchemaInfo(database, tables);
76
77
 
77
78
  for (const model of models) {
79
+ // assign driver if model's driver not exist
80
+ if (!model.driver) model.driver = Spine.driver;
81
+ // assign options if model's options not exist
82
+ if (!model.options) model.options = Spine.options;
78
83
  const columns = schemaInfo[model.physicTable] || schemaInfo[model.table];
79
84
  if (!model.attributes) initAttributes(model, columns);
80
85
  model.load(columns);
package/src/spell.js CHANGED
@@ -15,8 +15,8 @@ const { AGGREGATOR_MAP } = require('./constants');
15
15
 
16
16
  /**
17
17
  * check condition to avoid use virtual fields as where condtions
18
- * @param {Bone} Model
19
- * @param {Array<Object>} conds
18
+ * @param {Bone} Model
19
+ * @param {Array<Object>} conds
20
20
  */
21
21
  function checkCond(Model, conds) {
22
22
  if (Array.isArray(conds)) {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const { performance } = require('perf_hooks');
4
+ const { IS_LEORIC_BONE } = require('../constants');
4
5
 
5
6
  function isPlainObject(value) {
6
7
  return Object.prototype.toString.call(value) === '[object Object]';
@@ -43,10 +44,17 @@ const logger = {};
43
44
  };
44
45
  });
45
46
 
47
+ function isBone(bone) {
48
+ if (!bone || (typeof bone !== 'object' && typeof bone !== 'function')) return false;
49
+ const metaValue = Reflect.getMetadata(IS_LEORIC_BONE, bone);
50
+ return metaValue === true;
51
+ }
52
+
46
53
  module.exports = {
47
54
  isPlainObject,
48
55
  compose,
49
56
  getPropertyNames,
50
57
  calculateDuration,
51
58
  logger,
59
+ isBone,
52
60
  };
package/types/index.d.ts CHANGED
@@ -160,6 +160,8 @@ type OperatorCondition = {
160
160
 
161
161
  type WhereConditions<T extends typeof Bone> = {
162
162
  [Property in keyof Extract<InstanceType<T>, Literal>]?: Literal | Literal[] | OperatorCondition;
163
+ } | {
164
+ [key in '$and' | '$or']?: WhereConditions<T>[];
163
165
  }
164
166
 
165
167
  type Values<T extends typeof Bone> = {
@@ -205,6 +207,11 @@ interface QueryOptions {
205
207
  hooks?: boolean;
206
208
  paranoid?: boolean;
207
209
  silent?: boolean;
210
+ connection?: Connection;
211
+ }
212
+
213
+ interface TransactionOptions {
214
+ connection: Connection;
208
215
  }
209
216
 
210
217
  interface QueryResult {
@@ -214,7 +221,7 @@ interface QueryResult {
214
221
  fields?: Array<{ table: string, name: string }>,
215
222
  }
216
223
 
217
- interface Connection {
224
+ export interface Connection {
218
225
  /**
219
226
  * MySQL
220
227
  */
@@ -322,10 +329,10 @@ declare class AbstractDriver {
322
329
  * @param callback
323
330
  */
324
331
  disconnect(callback?: Function): Promise<boolean | void>;
325
-
332
+
326
333
  /**
327
334
  * query with spell
328
- * @param spell
335
+ * @param spell
329
336
  */
330
337
  cast(spell: Spell<typeof Bone, ResultSet | number | null>): Promise<QueryResult>;
331
338
 
@@ -424,7 +431,7 @@ declare class AbstractDriver {
424
431
  * remove index in table
425
432
  * @param table string
426
433
  * @param attributes attributes name
427
- * @param opts
434
+ * @param opts
428
435
  */
429
436
  removeIndex(table: string, attributes: string[], opts?: { unique?: boolean, type?: string }): Promise<void>;
430
437
 
@@ -574,6 +581,7 @@ export class Bone {
574
581
  */
575
582
  static find<T extends typeof Bone>(this: T, whereConditions: WhereConditions<T>): Spell<T, Collection<InstanceType<T>>>;
576
583
  static find<T extends typeof Bone>(this: T, whereConditions: string, ...values: Literal[]): Spell<T, Collection<InstanceType<T>>>;
584
+ static find<T extends typeof Bone>(this: T, primaryKey: number | number[]): Spell<T, Collection<InstanceType<T>>>;
577
585
  static find<T extends typeof Bone>(this: T, ): Spell<T, Collection<InstanceType<T>>>;
578
586
 
579
587
  /**
@@ -596,6 +604,7 @@ export class Bone {
596
604
  */
597
605
  static findOne<T extends typeof Bone>(this: T, whereConditions: WhereConditions<T>): Spell<T, InstanceType<T> | null>;
598
606
  static findOne<T extends typeof Bone>(this: T, whereConditions: string, ...values: Literal[]): Spell<T, InstanceType<T> | null>;
607
+ static findOne<T extends typeof Bone>(this: T, primaryKey: number | number[]): Spell<T, InstanceType<T> | null>;
599
608
  static findOne<T extends typeof Bone>(this: T, ): Spell<T, InstanceType<T> | null>;
600
609
 
601
610
  /**
@@ -695,7 +704,7 @@ export class Bone {
695
704
  * });
696
705
  */
697
706
  static transaction(callback: GeneratorFunction): Promise<RawQueryResult>;
698
- static transaction(callback: (connection: Connection) => Promise<RawQueryResult>): Promise<RawQueryResult>;
707
+ static transaction(callback: (connection: TransactionOptions) => Promise<RawQueryResult | void>): Promise<RawQueryResult>;
699
708
 
700
709
  /**
701
710
  * DROP the table