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