leoric 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +10 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/data_types.js +61 -3
- package/src/drivers/abstract/attribute.js +8 -0
- package/src/drivers/postgres/data_types.js +10 -0
- package/src/realm.js +5 -0
- package/types/index.d.ts +2 -1
package/History.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2.2.0 / 2022-02-24
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
## What's Changed
|
|
5
|
+
* fix: add missing `password` field for `ConnectOptions` by @luckydrq in https://github.com/cyjake/leoric/pull/280
|
|
6
|
+
* feat: integer types (mostly mysql specific) by @cyjake in https://github.com/cyjake/leoric/pull/281
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
**Full Changelog**: https://github.com/cyjake/leoric/compare/v2.1.1...v2.2.0
|
|
10
|
+
|
|
1
11
|
2.1.1 / 2022-02-23
|
|
2
12
|
==================
|
|
3
13
|
|
package/index.js
CHANGED
package/package.json
CHANGED
package/src/data_types.js
CHANGED
|
@@ -14,7 +14,13 @@ const Raw = require('./raw');
|
|
|
14
14
|
|
|
15
15
|
class DataType {
|
|
16
16
|
static findType(columnType) {
|
|
17
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
STRING, TEXT,
|
|
19
|
+
DATE, DATEONLY,
|
|
20
|
+
TINYINT, SMALLINT, MEDIUMINT, INTEGER, BIGINT,
|
|
21
|
+
BOOLEAN,
|
|
22
|
+
BINARY, VARBINARY, BLOB,
|
|
23
|
+
} = this;
|
|
18
24
|
const [ , dataType, appendix ] = columnType.match(/(\w+)(?:\((\d+)\))?/);
|
|
19
25
|
const length = appendix && parseInt(appendix, 10);
|
|
20
26
|
|
|
@@ -39,10 +45,13 @@ class DataType {
|
|
|
39
45
|
case 'int':
|
|
40
46
|
case 'integer':
|
|
41
47
|
case 'numeric':
|
|
48
|
+
return new INTEGER(length);
|
|
42
49
|
case 'mediumint':
|
|
50
|
+
return new MEDIUMINT(length);
|
|
43
51
|
case 'smallint':
|
|
52
|
+
return new SMALLINT(length);
|
|
44
53
|
case 'tinyint':
|
|
45
|
-
return new
|
|
54
|
+
return new TINYINT(length);
|
|
46
55
|
case 'bigint':
|
|
47
56
|
return new BIGINT(length);
|
|
48
57
|
case 'boolean':
|
|
@@ -203,12 +212,58 @@ class INTEGER extends DataType {
|
|
|
203
212
|
}
|
|
204
213
|
}
|
|
205
214
|
|
|
215
|
+
/**
|
|
216
|
+
* 8 bit integer
|
|
217
|
+
* @example
|
|
218
|
+
* TINYINT
|
|
219
|
+
* TINYINT.UNSIGNED
|
|
220
|
+
* TINYINT(1)
|
|
221
|
+
* @param {number} length
|
|
222
|
+
*/
|
|
223
|
+
class TINYINT extends INTEGER {
|
|
224
|
+
constructor(length) {
|
|
225
|
+
super(length);
|
|
226
|
+
this.dataType = 'tinyint';
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 16 bit integer
|
|
232
|
+
* @example
|
|
233
|
+
* SMALLINT
|
|
234
|
+
* SMALLINT.UNSIGNED
|
|
235
|
+
* SMALLINT(2)
|
|
236
|
+
* @param {number} length
|
|
237
|
+
*/
|
|
238
|
+
class SMALLINT extends INTEGER {
|
|
239
|
+
constructor(length) {
|
|
240
|
+
super(length);
|
|
241
|
+
this.dataType = 'smallint';
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 24 bit integer
|
|
247
|
+
* @example
|
|
248
|
+
* MEDIUMINT
|
|
249
|
+
* MEDIUMINT.UNSIGNED
|
|
250
|
+
* MEDIUMINT(3)
|
|
251
|
+
* @param {number} length
|
|
252
|
+
*/
|
|
253
|
+
class MEDIUMINT extends INTEGER {
|
|
254
|
+
constructor(length) {
|
|
255
|
+
super(length);
|
|
256
|
+
this.dataType = 'mediumint';
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
206
261
|
/**
|
|
207
262
|
* 64 bit integer
|
|
208
263
|
* @example
|
|
209
264
|
* BIGINT
|
|
210
265
|
* BIGINT.UNSIGNED
|
|
211
|
-
* BIGINT(
|
|
266
|
+
* BIGINT(8)
|
|
212
267
|
* @param {number} length
|
|
213
268
|
*/
|
|
214
269
|
class BIGINT extends INTEGER {
|
|
@@ -422,6 +477,9 @@ class JSONB extends JSON {
|
|
|
422
477
|
|
|
423
478
|
const DataTypes = {
|
|
424
479
|
STRING,
|
|
480
|
+
TINYINT,
|
|
481
|
+
SMALLINT,
|
|
482
|
+
MEDIUMINT,
|
|
425
483
|
INTEGER,
|
|
426
484
|
BIGINT,
|
|
427
485
|
DATE,
|
|
@@ -65,6 +65,14 @@ function createType(DataTypes, params) {
|
|
|
65
65
|
switch (type.constructor.name) {
|
|
66
66
|
case 'DATE':
|
|
67
67
|
return new DataType(type.precision, type.timezone);
|
|
68
|
+
case 'TINYINT':
|
|
69
|
+
case 'SMALLINT':
|
|
70
|
+
case 'MEDIUMINT':
|
|
71
|
+
case 'INTEGER':
|
|
72
|
+
case 'BIGINT':
|
|
73
|
+
case 'BINARY':
|
|
74
|
+
case 'VARBINARY':
|
|
75
|
+
return new DataType(type.length);
|
|
68
76
|
default:
|
|
69
77
|
return new DataType();
|
|
70
78
|
}
|
|
@@ -61,12 +61,22 @@ class Postgres_BIGINT extends Postgres_INTEGER {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
class Postgres_SMALLINT extends Postgres_INTEGER {
|
|
65
|
+
constructor() {
|
|
66
|
+
super();
|
|
67
|
+
this.dataType = 'smallint';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
64
71
|
class Postgres_DataTypes extends DataTypes {
|
|
65
72
|
static DATE = Postgres_DATE;
|
|
66
73
|
static JSONB = Postgres_JSONB;
|
|
67
74
|
static BINARY = Postgres_BINARY;
|
|
68
75
|
static VARBINARY = Postgres_BINARY;
|
|
69
76
|
static BLOB = Postgres_BINARY;
|
|
77
|
+
static TINYINT = Postgres_SMALLINT;
|
|
78
|
+
static SMALLINT = Postgres_SMALLINT;
|
|
79
|
+
static MEDIUMINT = Postgres_INTEGER;
|
|
70
80
|
static INTEGER = Postgres_INTEGER;
|
|
71
81
|
static BIGINT = Postgres_BIGINT;
|
|
72
82
|
}
|
package/src/realm.js
CHANGED
|
@@ -129,6 +129,11 @@ class Realm {
|
|
|
129
129
|
this.options = Spine.options = options;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
get DataTypes() {
|
|
133
|
+
if (!this.driver) throw new Error('database not connected yet');
|
|
134
|
+
return this.driver.DataTypes;
|
|
135
|
+
}
|
|
136
|
+
|
|
132
137
|
define(name, attributes, opts = {}, descriptors = {}) {
|
|
133
138
|
const Model = class extends this.Bone {
|
|
134
139
|
static name = name;
|
package/types/index.d.ts
CHANGED
|
@@ -599,6 +599,7 @@ export interface ConnectOptions {
|
|
|
599
599
|
host?: string;
|
|
600
600
|
port?: number | string;
|
|
601
601
|
user?: string;
|
|
602
|
+
password?: string;
|
|
602
603
|
database: string;
|
|
603
604
|
models?: string | (typeof Bone)[];
|
|
604
605
|
subclass?: boolean;
|
|
@@ -644,7 +645,7 @@ export default class Realm {
|
|
|
644
645
|
attributes: Record<string, DataTypes<DataType> | AttributeMeta>,
|
|
645
646
|
options?: InitOptions,
|
|
646
647
|
descriptors?: Record<string, Function>,
|
|
647
|
-
): Bone;
|
|
648
|
+
): typeof Bone;
|
|
648
649
|
|
|
649
650
|
raw(sql: string): RawSql;
|
|
650
651
|
|