leoric 2.0.3 → 2.0.4
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 +12 -2
- package/package.json +1 -1
- package/src/bone.js +0 -1
- package/src/drivers/postgres/schema.js +6 -1
- package/src/drivers/sqlite/schema.js +5 -3
- package/src/realm.js +1 -2
package/History.md
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
2.0.
|
|
1
|
+
2.0.4 / 2022-02-16
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
## What's Changed
|
|
5
|
+
* fix: fix unit test error by @LB4027221 in https://github.com/cyjake/leoric/pull/269
|
|
6
|
+
* fix: attribute.defaultValue should be set when init attributes by @cyjake in https://github.com/cyjake/leoric/pull/271
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
**Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.3...v2.0.4
|
|
10
|
+
|
|
11
|
+
2.0.3 / 2022-02-11
|
|
2
12
|
==================
|
|
3
13
|
|
|
4
14
|
## What's Changed
|
|
@@ -9,7 +19,7 @@
|
|
|
9
19
|
|
|
10
20
|
**Full Changelog**: https://github.com/cyjake/leoric/compare/v2.0.2...v2.0.3
|
|
11
21
|
|
|
12
|
-
2.0.2 /
|
|
22
|
+
2.0.2 / 2022-02-10
|
|
13
23
|
==================
|
|
14
24
|
|
|
15
25
|
## What's Changed
|
package/package.json
CHANGED
package/src/bone.js
CHANGED
|
@@ -57,13 +57,18 @@ module.exports = {
|
|
|
57
57
|
|
|
58
58
|
if (dataType === 'character varying') dataType = 'varchar';
|
|
59
59
|
if (dataType === 'timestamp without time zone') dataType = 'timestamp';
|
|
60
|
+
|
|
61
|
+
let columnDefault = row.column_default;
|
|
62
|
+
if (/^NULL::/i.test(columnDefault)) columnDefault = null;
|
|
63
|
+
if (dataType === 'boolean') columnDefault = columnDefault === 'true';
|
|
64
|
+
|
|
60
65
|
const primaryKey = row.constraint_type === 'PRIMARY KEY';
|
|
61
66
|
const precision = row.datetime_precision;
|
|
62
67
|
|
|
63
68
|
columns.push({
|
|
64
69
|
columnName: row.column_name,
|
|
65
70
|
columnType: length > 0 ? `${dataType}(${length})` : dataType,
|
|
66
|
-
defaultValue: primaryKey ? null :
|
|
71
|
+
defaultValue: primaryKey ? null : columnDefault,
|
|
67
72
|
dataType,
|
|
68
73
|
allowNull: row.is_nullable !== 'NO',
|
|
69
74
|
// https://www.postgresql.org/docs/9.5/infoschema-table-constraints.html
|
|
@@ -75,8 +75,9 @@ async function alterTableWithChangeColumn(driver, table, changes) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// eslint-disable-next-line no-unused-vars
|
|
78
|
-
function parseDefaultValue(text) {
|
|
78
|
+
function parseDefaultValue(text, type) {
|
|
79
79
|
if (typeof text !== 'string') return text;
|
|
80
|
+
if (type === 'boolean') return text === 'true';
|
|
80
81
|
|
|
81
82
|
try {
|
|
82
83
|
const ast = parseExpr(text);
|
|
@@ -84,7 +85,7 @@ function parseDefaultValue(text) {
|
|
|
84
85
|
return ast.value;
|
|
85
86
|
}
|
|
86
87
|
} catch (err) {
|
|
87
|
-
debug('[parseDefaultValue] [%s] %s', text, err
|
|
88
|
+
debug('[parseDefaultValue] [%s] %s', text, err);
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
return text;
|
|
@@ -111,10 +112,11 @@ module.exports = {
|
|
|
111
112
|
const columnType = type.toLowerCase();
|
|
112
113
|
const [, dataType, precision ] = columnType.match(rColumnType);
|
|
113
114
|
const primaryKey = pk === 1;
|
|
115
|
+
|
|
114
116
|
const result = {
|
|
115
117
|
columnName: name,
|
|
116
118
|
columnType,
|
|
117
|
-
defaultValue: parseDefaultValue(dflt_value),
|
|
119
|
+
defaultValue: parseDefaultValue(dflt_value, type),
|
|
118
120
|
dataType: dataType,
|
|
119
121
|
allowNull: primaryKey ? false : notnull == 0,
|
|
120
122
|
primaryKey,
|
package/src/realm.js
CHANGED
|
@@ -49,9 +49,8 @@ function initAttributes(model, columns) {
|
|
|
49
49
|
const attributes = {};
|
|
50
50
|
|
|
51
51
|
for (const columnInfo of columns) {
|
|
52
|
-
const { columnName, columnType,
|
|
52
|
+
const { columnName, columnType, ...restInfo } = columnInfo;
|
|
53
53
|
const name = columnName === '_id' ? columnName : camelCase(columnName);
|
|
54
|
-
// leave out defaultValue to let database take over the default
|
|
55
54
|
attributes[name] = {
|
|
56
55
|
...restInfo,
|
|
57
56
|
columnName,
|