leoric 2.1.0 → 2.1.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 ADDED
@@ -0,0 +1,612 @@
1
+ 2.1.1 / 2022-02-23
2
+ ==================
3
+
4
+ ## What's Changed
5
+ * fix: fix #274 update with fields option by @JimmyDaddy in https://github.com/cyjake/leoric/pull/275
6
+ * fix: upsert should set createdAt by default while createdAt not set by @JimmyDaddy in https://github.com/cyjake/leoric/pull/277
7
+ * 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
8
+ * docs: add types for realm by @luckydrq in https://github.com/cyjake/leoric/pull/278
9
+
10
+ ## New Contributors
11
+ * @luckydrq made their first contribution in https://github.com/cyjake/leoric/pull/278
12
+
13
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.1.0...v2.1.1
14
+
15
+ 2.1.0 / 2022-02-17
16
+ ==================
17
+
18
+ ## What's Changed
19
+ * feat: fix #270 sequelize mode bulkBuild by @JimmyDaddy in https://github.com/cyjake/leoric/pull/273
20
+ * fix: mysql delete/remove/destroy with limit and orders by @JimmyDaddy in https://github.com/cyjake/leoric/pull/272
21
+
22
+
23
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.4...v2.1.0
24
+
25
+ 2.0.4 / 2022-02-16
26
+ ==================
27
+
28
+ ## What's Changed
29
+ * fix: fix unit test error by @LB4027221 in https://github.com/cyjake/leoric/pull/269
30
+ * fix: attribute.defaultValue should be set when init attributes by @cyjake in https://github.com/cyjake/leoric/pull/271
31
+
32
+
33
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.3...v2.0.4
34
+
35
+ 2.0.3 / 2022-02-11
36
+ ==================
37
+
38
+ ## What's Changed
39
+ * fix: default updatedAt to new date if model has no createdAt by @LB4027221 in https://github.com/cyjake/leoric/pull/268
40
+
41
+ ## New Contributors
42
+ * @LB4027221 made their first contribution in https://github.com/cyjake/leoric/pull/268
43
+
44
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.2...v2.0.3
45
+
46
+ 2.0.2 / 2022-02-10
47
+ ==================
48
+
49
+ ## What's Changed
50
+ * fix: order by alias should not throw by @cyjake in https://github.com/cyjake/leoric/pull/255
51
+ * fix: fix #257 DataType.uncast should skip Raw type at type checking by @JimmyDaddy in https://github.com/cyjake/leoric/pull/258
52
+ * docs: async function in transaction by @cyjake in https://github.com/cyjake/leoric/pull/259
53
+ * fix: fixed #256 static create instance should check all default attri… by @JimmyDaddy in https://github.com/cyjake/leoric/pull/262
54
+ * fix: fix #260 UPDATE with LIMIT and ORDER should be formatted(mysql only) by @JimmyDaddy in https://github.com/cyjake/leoric/pull/261
55
+ * refactor: keep the UPDATE ... ORDER BY ... LIMIT to mysql driver by @cyjake in https://github.com/cyjake/leoric/pull/264
56
+ * fix: fix #263 upsert attributes should use defaultValue while there i… by @JimmyDaddy in https://github.com/cyjake/leoric/pull/265
57
+ * fix: fix restore Error `Undefined attribute "deletedAt"` by @JimmyDaddy in https://github.com/cyjake/leoric/pull/267
58
+ * fix: type checking adaption by @JimmyDaddy in https://github.com/cyjake/leoric/pull/266
59
+
60
+
61
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.1...v2.0.2
62
+
63
+ 2.0.1 / 2022-01-05
64
+ ==================
65
+
66
+ ## What's Changed
67
+ * fix: format numeric result by @JimmyDaddy in https://github.com/cyjake/leoric/pull/253
68
+ * fix: should still return number if value is '0.000' by @cyjake in https://github.com/cyjake/leoric/pull/254
69
+
70
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.15.1...v2.0.1
71
+
72
+ 2.0.0 / 2021-12-28
73
+ ==================
74
+
75
+ ## What's Changed
76
+ * breaking: model.sync add force/alter option by @SmartOrange in https://github.com/cyjake/leoric/pull/224
77
+ * breaking: logQueryError(err, sql, duration, options) by @cyjake in https://github.com/cyjake/leoric/pull/237
78
+ * test: add utf8mb4 test cases by @fengmk2 in https://github.com/cyjake/leoric/pull/239
79
+ * Merge 1.x changes by @cyjake in https://github.com/cyjake/leoric/pull/249
80
+
81
+ ## New Contributors
82
+ * @SmartOrange made their first contribution in https://github.com/cyjake/leoric/pull/222
83
+
84
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.15.1...v2.0.0
85
+
86
+ 1.15.1 / 2021-12-28
87
+ ===================
88
+
89
+ ## What's Changed
90
+ * fix: fix #242 date string format by @JimmyDaddy in https://github.com/cyjake/leoric/pull/243
91
+ * fix: update with empty conditions by @JimmyDaddy in https://github.com/cyjake/leoric/pull/241
92
+ * fix: silent option's priority should be lower than valueSet by @JimmyDaddy in https://github.com/cyjake/leoric/pull/244
93
+ * fix: information_schema.columns.datetime_precision by @cyjake in https://github.com/cyjake/leoric/pull/246
94
+ * fix: should not hoist subquery if query is ordered by external columns by @cyjake in https://github.com/cyjake/leoric/pull/247
95
+
96
+
97
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.15.0...v1.15.1
98
+
99
+ 1.15.0 / 2021-11-22
100
+ ===================
101
+
102
+ ## What's Changed
103
+ * feat: make duration in precise milliseconds by @fengmk2 in https://github.com/cyjake/leoric/pull/236
104
+ * fix: spell.increment() & spell.decrement() @cyjake https://github.com/cyjake/leoric/pull/234
105
+ * fix: bulkCreate should adapte empty data @JimmyDaddy https://github.com/cyjake/leoric/pull/232
106
+
107
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.4...v1.14.5
108
+
109
+ 1.14.4 / 2021-11-15
110
+ ===================
111
+
112
+ ## What's Changed
113
+
114
+ * test: PostgreSQL v14 test case compatibility by @cyjake https://github.com/cyjake/leoric/pull/230
115
+ * fix: turn off subquery optimization if query criteria contains other column by @cyjake https://github.com/cyjake/leoric/pull/229
116
+ * fix: bone.changed() return `false | string[]` type by @fengmk2 https://github.com/cyjake/leoric/pull/231
117
+
118
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.3...v1.14.4
119
+
120
+ 1.14.3 / 2021-11-12
121
+ ===================
122
+
123
+ ## What's Changed
124
+ * fix: logger.logQuery should be guarded in case of error by @SmartOrange in https://github.com/cyjake/leoric/pull/222
125
+ * fix: findOne without result should return null by @JimmyDaddy in https://github.com/cyjake/leoric/pull/225
126
+ * fix: Literal should support bigint type by @fengmk2 in https://github.com/cyjake/leoric/pull/226
127
+ * fix: select((name: string) => boolean) by @cyjake in https://github.com/cyjake/leoric/pull/227
128
+
129
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.2...v1.14.3
130
+
131
+ 1.14.2 / 2021-11-01
132
+ ===================
133
+
134
+ ## What's Changed
135
+ * fix: accept timestamps in snake case by @cyjake in https://github.com/cyjake/leoric/pull/221
136
+
137
+
138
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.1...v1.14.2
139
+
140
+ 1.14.1 / 2021-11-01
141
+ ===================
142
+
143
+ ## What's Changed
144
+ * docs: export { Collection } by @cyjake in https://github.com/cyjake/leoric/pull/220
145
+
146
+
147
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.14.0...v1.14.1
148
+
149
+ 1.14.0 / 2021-11-01
150
+ ===================
151
+
152
+ Two options regarding `Model.init()` were added in this release:
153
+
154
+ ```js
155
+ class User extends Bone {}
156
+ User.init({ name: STRING }, {
157
+ timestamps: true, // which is the default
158
+ paranoid: true, // which default to `false`
159
+ });
160
+ assert.deepEqual(Object.keys(User.attributes), [
161
+ 'id',
162
+ 'name',
163
+ 'createdAt',
164
+ 'updatedAt',
165
+ 'deletedAt',
166
+ ]);
167
+ ```
168
+
169
+ ## What's Changed
170
+ * docs: update 'primayKey' typos by @freshgum-bubbles in https://github.com/cyjake/leoric/pull/211
171
+ * docs: DataTypes definitions in d.ts by @cyjake in https://github.com/cyjake/leoric/pull/210
172
+ * fix: fix#209 sequelize mode should update all changed fields in instance update method by @JimmyDaddy in https://github.com/cyjake/leoric/pull/212
173
+ * fix: fix #213 findAndCountAll should ignore attributes by @JimmyDaddy in https://github.com/cyjake/leoric/pull/214
174
+ * fix: opts.connectTimeout by @cyjake in https://github.com/cyjake/leoric/pull/216
175
+ * fix: reload instance with sharding key should not throw by @cyjake in https://github.com/cyjake/leoric/pull/217
176
+ * feat: timestamps should be defined by default by @cyjake in https://github.com/cyjake/leoric/pull/218
177
+ * fix: instance.reload() should not rely on `static findOne()` by @cyjake in https://github.com/cyjake/leoric/pull/219
178
+
179
+ ## New Contributors
180
+ * @freshgum-bubbles made their first contribution in https://github.com/cyjake/leoric/pull/211
181
+
182
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.5...v1.14.0
183
+
184
+ 1.13.5 / 2021-10-26
185
+ ===================
186
+
187
+ ## What's Changed
188
+ * docs: enhance aggregation query types & fix raw query result type by @cyjake in https://github.com/cyjake/leoric/pull/208
189
+
190
+
191
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.4...v1.13.5
192
+
193
+ 1.13.4 / 2021-10-25
194
+ ===================
195
+
196
+ ## What's Changed
197
+ * docs: spell & model methods should be generic by @cyjake in https://github.com/cyjake/leoric/pull/206
198
+ * docs: enhance query options, instance type, and toJSON() result type by @cyjake in https://github.com/cyjake/leoric/pull/207
199
+
200
+ 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:
201
+
202
+ ![image](https://user-images.githubusercontent.com/252317/138683240-98ee9e79-4b3e-449c-bc95-a449d457d64f.png)
203
+
204
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.3...v1.13.4
205
+
206
+ 1.13.3 / 2021-10-21
207
+ ===================
208
+
209
+ ## What's Changed
210
+ * refactor: persist edge cases of type casting in integration tests by @cyjake in https://github.com/cyjake/leoric/pull/202
211
+ * docs: renaming attributes by @cyjake in https://github.com/cyjake/leoric/pull/203
212
+ * fix: JSON.uncast(string) should not serialize twice by @cyjake in https://github.com/cyjake/leoric/pull/205
213
+
214
+
215
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.2...v1.13.3
216
+
217
+ 1.13.2 / 2021-10-18
218
+ ===================
219
+
220
+ ## What's Changed
221
+ * fix: attribute.uncast([]) and realm.connect with synchronized models by @cyjake in https://github.com/cyjake/leoric/pull/201
222
+
223
+
224
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.1...v1.13.2
225
+
226
+ 1.13.1 / 2021-10-18
227
+ ===================
228
+
229
+ ## What's Changed
230
+ * fix: skip connecting if models are synchronized already by @cyjake in https://github.com/cyjake/leoric/pull/200
231
+
232
+
233
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.13.0...v1.13.1
234
+
235
+ 1.13.0 / 2021-10-18
236
+ ===================
237
+
238
+ ## What's Changed
239
+ * docs: monthly updates of 2021.09; support dark mode by @cyjake in https://github.com/cyjake/leoric/pull/196
240
+ * feat: coerce literal values into accurate attribute type by @cyjake in https://github.com/cyjake/leoric/pull/197
241
+ * fix: dispatched result should be in attribute names by @cyjake in https://github.com/cyjake/leoric/pull/198
242
+
243
+
244
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v1.12.0...v1.13.0
245
+
246
+ 1.12.0 / 2021-10-12
247
+ ===================
248
+
249
+ * feat: support custom fields query and sequelize mode export rawAttributes (#192)
250
+ * refactor: collection format query result (#194)
251
+ * refactor: object condition parsing and expression formatting (#191)
252
+
253
+ 1.11.1 / 2021-09-28
254
+ ===================
255
+
256
+ This version fixes lots of issues regarding logical operator in object conditions.
257
+
258
+ * fix: logical operator with multiple conditions such as (#190)
259
+ * fix: sequelize mode support HAVING, and select fields raw sql support (#187)
260
+ * fix: support len validator (#188)
261
+ * fix: normalize logical operator conditions before formatting with spellbook (#186)
262
+
263
+ 1.11.0 / 2021-09-24
264
+ ===================
265
+
266
+ * feat: support BINARY(length), VARBINARY(length), and BLOB (#169)
267
+ * fix: logic operate should adapt one argument (#183)
268
+ * fix: Bone.load() should be idempotent, make sure associations is intact (#184)
269
+ * fix: selected instance isNewRecord is false (#182)
270
+ * fix: set options.busyTimeout to mitigate SQLITE_BUSY (#176)
271
+ * fix: turn on long stack trace of sqlite driver (#175)
272
+ * docs: how to contribute (#180)
273
+
274
+ 1.10.0 / 2021-09-14
275
+ ===================
276
+
277
+ * feat: SQLite driver should emit "connection" event when new connection is created (#168)
278
+ * fix: bulkCreate(...records) should recognize custom setters (#168)
279
+ * fix: attribute.equals() check should ignore defaultValue (#172)
280
+
281
+ 1.9.0 / 2021-09-04
282
+ ==================
283
+
284
+ > should've been a major release but since existing users have all migrated to the new api...
285
+
286
+ * breaking: drop the deprecated `Model.describe()` (#167)
287
+
288
+ 1.8.0 / 2021-08-30
289
+ ==================
290
+
291
+ * feat: silent option fix #164 (#165)
292
+ * feat: binary type (#166)
293
+
294
+ 1.7.1 / 2021-08-17
295
+ ==================
296
+
297
+ * revert: drop Driver#recycleConnections due to poor interoperability (#162)
298
+ * fix: validator call array arguments (#160)
299
+
300
+ 1.7.0 / 2021-08-17
301
+ =================
302
+
303
+ * feat: close connections that exceeds opts.idleTimeout (#159)
304
+ * feat: `opts.connectionLimit` support for SQLite (#159)
305
+ * feat: raw query relpacements, closes #149 (#155)
306
+ * fix: upsert created_at default (#154)
307
+ * test: validator unit test (#157)
308
+ * test: setup_hooks unit test (#158)
309
+
310
+ 1.6.7 / 2021-08-05
311
+ ==================
312
+
313
+ * fix: prevent from calling Date.prototype.toJSON (#153)
314
+
315
+ 1.6.6 / 2021-07-22
316
+ ==================
317
+
318
+ * fix: subclassing data type in dialects (#145)
319
+ * fix: where('width / height >= 16 / 9') (#144)
320
+ * docs: logging and sequelzie adapter (zh) (#142)
321
+ * test: include test/unit/utils (#143)
322
+ * test: more tests cases about sequelize adapter (#141)
323
+
324
+ 1.6.5 / 2021-07-16
325
+ ==================
326
+
327
+ * fix: define assign Bone.models #140
328
+
329
+ 1.6.4 / 2021-07-16
330
+ ==================
331
+
332
+ * refactor: connect({ Bone }) still necessary (#139)
333
+ * fix: formatting select join with subqueries should not tamper the subquery itself (#138)
334
+ * fix: describe table with more compatible syntax (#137)
335
+
336
+ 1.6.3 / 2021-07-14
337
+ ==================
338
+
339
+ * fix: transaction option passing in sequelize adapter (#136)
340
+ * fix: this.Model and proper Model.describe() (#135)
341
+
342
+ 1.6.2 / 2021-07-09
343
+ ==================
344
+
345
+ * fix: convert datetime in seconds/milliseconds back to Date (#134)
346
+ * fix: renamed attribute should remain enumerable (#133)
347
+
348
+ 1.6.1 / 2021-07-07
349
+ ==================
350
+
351
+ * fix: collection convert should handle tddl results as well (#132)
352
+
353
+ 1.6.0 / 2021-07-06
354
+ ==================
355
+
356
+ * feat: support class static attributes and hooks (#131)
357
+ * fix: names defined in Bone.attributes should always be enumerable (#128)
358
+ * chore: add quality badge to readme (#129)
359
+
360
+ 1.5.2 / 2021-07-02
361
+ ==================
362
+
363
+ * fix: leave the getter properties defined in class syntax as is (#127)
364
+
365
+ 1.5.1 / 2021-06-30
366
+ ==================
367
+
368
+ * fix: export Logger and Spell to let users intercept lower level api calls (#126)
369
+
370
+ 1.5.0 / 2021-06-30
371
+ ==================
372
+
373
+ * feat: provide Bone.pool to be backward compatible with v0.x (#124)
374
+ * feat: complete bone/spine.restore and Bone API type definitions (#125)
375
+ * feat: support more data types (mediumtext, mediumint, char, date...) (#123)
376
+
377
+ 1.4.1 / 2021-06-25
378
+ ==================
379
+
380
+ * refactor: simplify legacy timestamps support (#120)
381
+ * refactor: do not subclass Bone unless asked specifically (#120)
382
+
383
+ 1.4.0 / 2021-06-24
384
+ ==================
385
+
386
+ * feat: `realm.raw('SELECT ...')` and `Model.raw('SELECT ...')` (#94)
387
+ * feat: support multiple order rules in one single string or one-dimensional array (#92)
388
+ * feat: `Model.truncate()` now uses TRUNCATE if possible
389
+ * feat: `Model.find().optimizerHints('SET_VAR(foreign_key_checks=OFF)')`
390
+ * fix: Bone.bulkCreate() should not throw when called with non attribute (#117)
391
+ * fix: batch upsert (#108)
392
+ * fix: make sure connection is passed around in all queries carried out within transaction (#105)
393
+ * fix: update, sequelize mode get API, destroy compitable (#104)
394
+ * fix: `setDataValue` in sequelize adapter should not check prop name strictly
395
+ * refactor: spell_insert (#118)
396
+ * docs: about egg-orm & migrations (#119)
397
+ * docs: revise instructions for installing Jekyll (#111)
398
+ * docs: migrations, validations, hooks, and sequelize adapter (#103)
399
+ * docs: contributing guides
400
+
401
+ 1.3.0 / 2021-03-01
402
+ ==================
403
+
404
+ * feat: hook support
405
+ * feat: dirty check (`changes()` & `previousChanges()`)
406
+ * feat: compatible with mysql longtext conversion
407
+ * feat: NOT condition
408
+
409
+ 1.2.0 / 2020-12-10
410
+ ==================
411
+
412
+ * feat: `Realm.prototype.transaction()` with async function support
413
+ * feat: `Realm.prototype.query()` for raw queries
414
+ * feat: `logger.logQuery(sql, duration, { Model, command })`
415
+ * feat: `logger.logQueryError(sql, err, duration, { Model, command })`
416
+
417
+ 1.1.0 / 2020-11-23
418
+ ==================
419
+
420
+ * feat: JSON and JSONB data types
421
+ * feat: support `stringifyObjects` option for mysql client
422
+ * feat: aggregate functions for sequelize adapter
423
+ * feat: `Spell.prototype.nodeify()`
424
+
425
+ 1.0.3 / 2020-03-16
426
+ ==================
427
+
428
+ * fix: replace `deep-equal` (which is bloated) with `util.isDeepStrictEqual`
429
+
430
+ 1.0.2 / 2020-03-04
431
+ ==================
432
+
433
+ * fix: driver.alterTable() with multiple columns to add in SQLite
434
+
435
+ 1.0.1 / 2020-02-25
436
+ ==================
437
+
438
+ * fix: bulkCreate in sequelize shim
439
+
440
+ 1.0.0 / 2020-02-24
441
+ ==================
442
+
443
+ First major release. Let's get serious with semver.
444
+
445
+ * feat: logger.logQuery(sql, duration) & logger.logQueryError(sql, err)
446
+
447
+ 0.5.3 / 2020-02-22
448
+ ==================
449
+
450
+ * fix: `connect({ sequelize, dialect, client })` to allow mandatory sqlite client
451
+ * fix: prevent queries being performed unless model is correctly connected
452
+
453
+ 0.5.2 / 2020-02-21
454
+ ==================
455
+
456
+ * fix: drop the default and unused `require('sqlite3')`
457
+
458
+ 0.5.1 / 2020-02-21
459
+ ==================
460
+
461
+ * fix: `connect({ client: '@journeyapps/sqlcipher' })`
462
+
463
+ 0.5.0 / 2020-02-19
464
+ ==================
465
+
466
+ * feat: `Bone.sync()` to synchronize model with database
467
+ * feat: `Bone.createMigrationFile()` to create migration file
468
+ * feat: `Bone.migrate()` to run migrations
469
+ * feat: `Bone.bulkCreate()` to bulk insert records
470
+ * feat: `require('leoric')` now exports `Realm` to connect with multiple databases
471
+ * feat: `realm.define()` to define models in an old fashioned way
472
+ * feat: `realm.connect()` to connect with database
473
+ * feat: SQLite support without hacking node-sqlite3
474
+ * feat: `Bone.DataTypes` for type references
475
+ * feat: `Bone.init()` to initialize models
476
+ * feat: an adaptor to use Leoric in (partially) Sequelize complaint API
477
+ * refactor: a complete re-write of JOIN queries
478
+ * refactor: added `Bone.driver` to better encapsulate and planish database nuances
479
+
480
+ 0.4.5 / 2019-12-14
481
+ ==================
482
+
483
+ * fix: prevent primary key from being overridden with incorrect `LAST_INSERT_ID()`
484
+
485
+ 0.4.4 / 2019-07-15
486
+ ==================
487
+
488
+ * fix: append default scope when declaring relations, fixes #10
489
+
490
+ 0.4.3 / 2019-05-09
491
+ ==================
492
+
493
+ * fix: prevent Bone.dispatch from creating duplicated records of main table
494
+
495
+ 0.4.2 / 2019-04-26
496
+ ==================
497
+
498
+ * feat: `Spell#orWhere()` and `Spell#orHaving()`
499
+ * feat: arithmetic operators
500
+ * feat: unary operators such as unary minus `-` and bit invertion `~`
501
+ * fix: unset attribute should be overwritable
502
+ * fix: `attributeChanged()` should be false if attribute is unset and not overwritten
503
+ * fix: subclass with incomplete getter/setter should be complemented
504
+ * fix: sharding key validation on `Bone.update()` and `Bone.save()`
505
+ * fix: sharding key should be along with primary key on `bone.remove()`
506
+ * fix: `Bone.cast()` should leave `null` as is
507
+ * fix: `INSERT ... UPDATE` with `id = LAST_INSERT_ID(id)` in MySQL
508
+ * fix: `Model.find({ name: { $op1, $op2 } })` object conditions with multiple operators
509
+ * fix: prefixing result set with qualifiers if query contains join relations and is not dispatchable
510
+ * fix: `Spell#$get(index)` with LIMIT
511
+ * doc: `Model.transaction()`
512
+ * doc: definition types with `index.d.ts`
513
+
514
+ 0.4.1 / 2019-03-21
515
+ ==================
516
+
517
+ * feat: premature sharding key validation
518
+ * fix: output complete SQL instead of parameterized query with values.
519
+ * fix: both `connect({ model })` and `connect({ models })` are allowed.
520
+ * doc: no more `.findOrCreate()`, just `.upsert()`
521
+ * doc: table of contents with kramdown's `{:toc}`
522
+ * chore: droped experimental sqlite3 support
523
+
524
+ 0.4.0 / 2018-11-05
525
+ ==================
526
+
527
+ * feat: PostgreSQL support
528
+ * feat: Transaction support
529
+ * upgrade: (forked) SQLite client updated to SQLite 3.24
530
+
531
+
532
+ 0.3.0 / 2018-10-31
533
+ ==================
534
+
535
+ * feat: SQLite support with a [forked sqlite3](https://github.com/cyjake/node-sqlite3)
536
+ * feat: mysql2 support (which is trivial since both mysql and mysql2 share the same API)
537
+ * refactor: Spell now formats SQL with the literals separated, which gets escaped by the corresponding client itself later on.
538
+
539
+ 0.2.0 / 2018-01-03
540
+ ==================
541
+
542
+ * breaking: renaming
543
+
544
+ 0.1.8 / 2017-12-31
545
+ ==================
546
+
547
+ * fix: implement `query.batch()` as async iterator
548
+ * fix: `NOT (expr)`
549
+ * fix: `IFNULL(foo, default)`
550
+ * fix: support `.select(name[])`, `.select(name => {})`, and `.select("...name")`
551
+ * doc: `Model => className` in association options
552
+ * doc: use [jsdoc](http://usejsdoc.org) to generate docs/api
553
+ * doc: `.include()`
554
+
555
+ 0.1.7 / 2017-12-22
556
+ ==================
557
+
558
+ * refactor: `{ type: 'op', name: 'as' }` renamed to `{ type: 'alias' }`
559
+ * feat: `{ type: 'mod' }` for modifier, currently only `DISTINCT` is recognized
560
+ * feat: unary operators like `!` and `NOT`
561
+ * feat: `IS` and `IS NOT`
562
+ * fix: logic operator precendences
563
+ * fix: polymorphic hasMany({ through }) relations
564
+ * fix: dispatching multiple results with joins correctly
565
+
566
+ 0.1.6 / 2017-12-21
567
+ ==================
568
+
569
+ * feat: proper `.first`, `.last`, `.all`, and `.get(index)`
570
+ * fix: accept `Date`, `boolean`, and `Set` values
571
+ * fix: `Model.unscoped`
572
+ * fix: `Model.remove({}, true)` should be unscoped
573
+
574
+ 0.1.5 / 2017-12-20
575
+ ==================
576
+
577
+ * refactor: encapsulate column names. Keep them from the users even if the query results can not be dispatched.
578
+ * fix: complicated groups with joins should discard the use of subquery.
579
+ * fix: camelCase should replace globally
580
+ * fix: avoid missing attribtue exception when toJSON/toObject
581
+
582
+ 0.1.4 / 2017-12-18
583
+ ==================
584
+
585
+ * fix: should format condition arrays by hand instead of hand it over to formatExpr
586
+ * fix: whereConditions of subquery should retain the order of the whereConditions in major query
587
+ * fix: calculated columns should be kept in the final columns when sorting out the attributes
588
+ * fix: doesn't depend on co anymore
589
+
590
+ 0.1.3 / 2017-12-17
591
+ ==================
592
+
593
+ * fix: `select distict foo from table`;
594
+ * fix: `where (a = 1 or a = 2) and b = 3`;
595
+ * doc: a syntax table to provide a better glance over the querying ability.
596
+
597
+ 0.1.2 / 2017-12-14
598
+ ==================
599
+
600
+ * fix: copy left table's orders into subquery to make order/limit work when combined.
601
+ * fix: errors should be thrown when accessing attributes that weren't selected at the first place.
602
+
603
+ 0.1.1 / 2017-12-13
604
+ ==================
605
+
606
+ * refactor: automatic versioning on spells. When client calls query methods with chaining, new versions of spell gets duplicated. Makes reuse of spells possible.
607
+ * doc: english verion is almost complete <http://cyj.me/leoric>.
608
+
609
+ 0.1.0 / 2017-12-09
610
+ ==================
611
+
612
+ * Initial version, covers basic usage such as model authoring, database connection, query interface, and association.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leoric",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "JavaScript Object-relational mapping alchemy",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -508,11 +508,11 @@ module.exports = Bone => {
508
508
  // get isNewRecord() {}
509
509
 
510
510
  async update(values = {}, options = {}) {
511
- const { fields } = options;
511
+ const { fields = [] } = options;
512
512
  const changeValues = {};
513
513
  const originalValues = Object.assign({}, this.getRaw());
514
514
  for (const name in values) {
515
- if (values[name] !== undefined && this.hasAttribute(name)) {
515
+ if (values[name] !== undefined && this.hasAttribute(name) && (!fields.length || fields.includes(name))) {
516
516
  // exec custom setters in case it exist
517
517
  this[name] = values[name];
518
518
  changeValues[name] = this.attribute(name);
package/src/bone.js CHANGED
@@ -183,7 +183,6 @@ class Bone {
183
183
  }
184
184
 
185
185
  if (args.length > 1) {
186
- // execute validators
187
186
  this.#raw[name] = value instanceof Raw ? value : attribute.cast(value);
188
187
  this.#rawUnset.delete(name);
189
188
  return this;
@@ -619,9 +618,10 @@ class Bone {
619
618
  async update(values, options = {}) {
620
619
  const changes = {};
621
620
  const originalValues = Object.assign({}, this.#raw);
621
+ const { fields = [] } = options;
622
622
  if (typeof values === 'object') {
623
623
  for (const name in values) {
624
- if (values[name] !== undefined && this.hasAttribute(name)) {
624
+ if (values[name] !== undefined && this.hasAttribute(name) && (!fields.length || fields.includes(name))) {
625
625
  // exec custom setters in case it exist
626
626
  this[name] = values[name];
627
627
  changes[name] = this.attribute(name);
@@ -123,7 +123,8 @@ class Attribute {
123
123
  }
124
124
 
125
125
  cast(value) {
126
- return this.type.cast(value);
126
+ const castedValue = this.type.cast(value);
127
+ return castedValue == null? null : castedValue;
127
128
  }
128
129
 
129
130
  uncast(value, strict = true) {
@@ -356,15 +356,14 @@ function formatInsert(spell) {
356
356
  }
357
357
  } else {
358
358
  for (const name in involved) {
359
- // upsert should not update createdAt
360
- if (updateOnDuplicate && createdAt && name === createdAt) continue;
361
359
  attributes.push(Model.attributes[name]);
362
360
  }
363
361
  }
364
362
 
365
363
  for (const entry of attributes) {
366
364
  columns.push(entry.columnName);
367
- if (updateOnDuplicate && createdAt && entry.name === createdAt) continue;
365
+ if (updateOnDuplicate && createdAt && entry.name === createdAt
366
+ && !(Array.isArray(updateOnDuplicate) && updateOnDuplicate.includes(createdAt))) continue;
368
367
  updateOnDuplicateColumns.push(entry.columnName);
369
368
  }
370
369
 
@@ -385,7 +384,6 @@ function formatInsert(spell) {
385
384
  }
386
385
  for (const name in sets) {
387
386
  const value = sets[name];
388
- // upsert should not update createdAt
389
387
  columns.push(Model.unalias(name));
390
388
  if (value instanceof Raw) {
391
389
  values.push(SqlString.raw(value.value));
@@ -49,7 +49,10 @@ module.exports = {
49
49
  const sets = [];
50
50
  // Make sure the correct LAST_INSERT_ID is returned.
51
51
  // - https://stackoverflow.com/questions/778534/mysql-on-duplicate-key-last-insert-id
52
- sets.push(`${escapeId(primaryColumn)} = LAST_INSERT_ID(${escapeId(primaryColumn)})`);
52
+ // if insert attributes include primary column, `primaryKey = LAST_INSERT_ID(primaryKey)` is not need any more
53
+ if (!columns.includes(primaryColumn)) {
54
+ sets.push(`${escapeId(primaryColumn)} = LAST_INSERT_ID(${escapeId(primaryColumn)})`);
55
+ }
53
56
  sets.push(...columns.map(column => `${escapeId(column)}=VALUES(${escapeId(column)})`));
54
57
 
55
58
  return `ON DUPLICATE KEY UPDATE ${sets.join(', ')}`;
package/types/index.d.ts CHANGED
@@ -593,13 +593,15 @@ export class Bone {
593
593
  toObject(): InstanceValues<this>;
594
594
  }
595
595
 
596
- interface ConnectOptions {
596
+ export interface ConnectOptions {
597
597
  client?: 'mysql' | 'mysql2' | 'pg' | 'sqlite3' | '@journeyapps/sqlcipher';
598
598
  dialect?: 'mysql' | 'postgres' | 'sqlite';
599
599
  host?: string;
600
+ port?: number | string;
600
601
  user?: string;
601
602
  database: string;
602
603
  models?: string | (typeof Bone)[];
604
+ subclass?: boolean;
603
605
  }
604
606
 
605
607
  interface InitOptions {
@@ -612,6 +614,11 @@ interface InitOptions {
612
614
  };
613
615
  }
614
616
 
617
+ interface SyncOptions {
618
+ force?: boolean;
619
+ alter?: boolean;
620
+ }
621
+
615
622
  type RawSql = {
616
623
  __raw: true,
617
624
  value: string,
@@ -626,6 +633,7 @@ interface RawQueryOptions {
626
633
 
627
634
  export default class Realm {
628
635
  Bone: typeof Bone;
636
+ DataTypes: typeof DataType;
629
637
  driver: Driver;
630
638
  models: Record<string, Bone>;
631
639
 
@@ -633,9 +641,9 @@ export default class Realm {
633
641
 
634
642
  define(
635
643
  name: string,
636
- attributes: Record<string, AttributeMeta>,
637
- options: InitOptions,
638
- descriptors: Record<string, Function>,
644
+ attributes: Record<string, DataTypes<DataType> | AttributeMeta>,
645
+ options?: InitOptions,
646
+ descriptors?: Record<string, Function>,
639
647
  ): Bone;
640
648
 
641
649
  raw(sql: string): RawSql;
@@ -646,6 +654,8 @@ export default class Realm {
646
654
 
647
655
  transaction(callback: GeneratorFunction): Promise<void>;
648
656
  transaction(callback: (connection: Connection) => Promise<void>): Promise<void>;
657
+
658
+ sync(options?: SyncOptions): Promise<void>;
649
659
  }
650
660
 
651
661
  /**