sedentary-pg 0.0.41 → 0.0.44
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/README.md +4 -4
- package/dist/cjs/adsrc.js +2 -0
- package/dist/cjs/index.js +6 -7
- package/dist/cjs/pgdb.js +31 -20
- package/dist/es/adsrc.js +2 -0
- package/dist/es/index.js +5 -6
- package/dist/es/pgdb.js +31 -20
- package/dist/types/index.d.ts +2 -3
- package/dist/types/pgdb.d.ts +8 -8
- package/package.json +12 -53
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
# Description
|
|
33
33
|
|
|
34
|
-
The **PostgreSQL**
|
|
34
|
+
The **PostgreSQL** specialized package of [Sedentary](https://www.npmjs.com/package/sedentary).
|
|
35
35
|
|
|
36
36
|
# Usage
|
|
37
37
|
|
|
@@ -42,7 +42,7 @@ const db = new SedentaryPG(/* PG connection */);
|
|
|
42
42
|
|
|
43
43
|
class Items extends db.model("Item", {
|
|
44
44
|
num: db.INT,
|
|
45
|
-
str: db.
|
|
45
|
+
str: db.VarChar(30)
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
(async function () {
|
|
@@ -91,9 +91,9 @@ To work with the package under Windows, be sure to configure `bash.exe` as your
|
|
|
91
91
|
> npm config set script-shell bash.exe
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
#
|
|
94
|
+
# License
|
|
95
95
|
|
|
96
|
-
[MIT
|
|
96
|
+
[MIT License](https://github.com/iccicci/sedentary-pg/blob/master/LICENSE)
|
|
97
97
|
|
|
98
98
|
# Bugs
|
|
99
99
|
|
package/dist/cjs/adsrc.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.adsrc = void 0;
|
|
4
|
+
// cspell: disable-next-line
|
|
4
5
|
function adsrc(version) {
|
|
6
|
+
// cspell: disable-next-line
|
|
5
7
|
return version >= 12 ? "pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid) AS adsrc" : "adsrc";
|
|
6
8
|
}
|
|
7
9
|
exports.adsrc = adsrc;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SedentaryPG = exports.TransactionPG = exports.Type = exports.EntryBase = void 0;
|
|
4
4
|
const sedentary_1 = require("sedentary");
|
|
5
5
|
const pgdb_1 = require("./pgdb");
|
|
6
6
|
var sedentary_2 = require("sedentary");
|
|
@@ -15,18 +15,17 @@ class SedentaryPG extends sedentary_1.Sedentary {
|
|
|
15
15
|
throw new Error("SedentaryPG.constructor: 'connection' argument: Wrong type, expected 'Object'");
|
|
16
16
|
this.db = new pgdb_1.PGDB(connection, this.log);
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
FKey(attribute, options) {
|
|
19
19
|
const { attributeName, modelName, unique } = attribute;
|
|
20
20
|
if (!unique)
|
|
21
|
-
throw new Error(`
|
|
22
|
-
return super.
|
|
21
|
+
throw new Error(`SedentaryPG.FKey: '${modelName}' model: '${attributeName}' attribute: is not unique: can't be used as FKey target`);
|
|
22
|
+
return super.FKey(attribute, options);
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
begin() {
|
|
25
25
|
return this.db.begin();
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
client() {
|
|
28
28
|
return this.db.client();
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
exports.SedentaryPG = SedentaryPG;
|
|
32
|
-
exports.Package = SedentaryPG;
|
package/dist/cjs/pgdb.js
CHANGED
|
@@ -12,17 +12,27 @@ const needDrop = [
|
|
|
12
12
|
["DATETIME", "int2"],
|
|
13
13
|
["DATETIME", "int4"],
|
|
14
14
|
["DATETIME", "int8"],
|
|
15
|
+
["DATETIME", "numeric"],
|
|
16
|
+
["INT", "json"],
|
|
15
17
|
["INT", "timestamptz"],
|
|
16
|
-
["INT8", "
|
|
18
|
+
["INT8", "json"],
|
|
19
|
+
["INT8", "timestamptz"],
|
|
20
|
+
["JSON", "int2"],
|
|
21
|
+
["JSON", "int4"],
|
|
22
|
+
["JSON", "int8"],
|
|
23
|
+
["JSON", "numeric"],
|
|
24
|
+
["NUMBER", "json"],
|
|
25
|
+
["NUMBER", "timestamptz"]
|
|
17
26
|
];
|
|
18
27
|
const needUsing = [
|
|
19
28
|
["BOOLEAN", "varchar"],
|
|
20
29
|
["DATETIME", "varchar"],
|
|
21
30
|
["INT", "varchar"],
|
|
22
31
|
["INT8", "varchar"],
|
|
32
|
+
["JSON", "varchar"],
|
|
23
33
|
["NUMBER", "varchar"]
|
|
24
34
|
];
|
|
25
|
-
const types = { bool: "BOOL", int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", numeric: "NUMERIC", timestamptz: "DATETIME", varchar: "VARCHAR" };
|
|
35
|
+
const types = { bool: "BOOL", int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", json: "JSON", numeric: "NUMERIC", timestamptz: "DATETIME", varchar: "VARCHAR" };
|
|
26
36
|
const actions = { cascade: "c", "no action": "a", restrict: "r", "set default": "d", "set null": "n" };
|
|
27
37
|
function parseInt8(value) {
|
|
28
38
|
return BigInt(value);
|
|
@@ -69,10 +79,9 @@ class PGDB extends sedentary_1.DB {
|
|
|
69
79
|
escape(value) {
|
|
70
80
|
if (value === null || value === undefined)
|
|
71
81
|
throw new Error("SedentaryPG: Can't escape null nor undefined values; use the 'IS NULL' operator instead");
|
|
72
|
-
|
|
73
|
-
if (type === "number" || type === "boolean")
|
|
82
|
+
if (typeof value === "boolean" || typeof value === "number")
|
|
74
83
|
return value.toString();
|
|
75
|
-
if (
|
|
84
|
+
if (typeof value === "string")
|
|
76
85
|
return (0, pg_format_1.default)("%L", value);
|
|
77
86
|
//if(value instanceof Date)
|
|
78
87
|
return (0, pg_format_1.default)("%L", value).replace(/\.\d\d\d\+/, "+");
|
|
@@ -132,13 +141,13 @@ class PGDB extends sedentary_1.DB {
|
|
|
132
141
|
remove(tableName, pk) {
|
|
133
142
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
134
143
|
const self = this;
|
|
135
|
-
const
|
|
144
|
+
const pkAttrName = pk.attributeName;
|
|
136
145
|
const pkFldName = pk.fieldName;
|
|
137
146
|
return async function () {
|
|
138
147
|
const client = this.tx ? this.tx._client : await self.pool.connect();
|
|
139
148
|
let removed = false;
|
|
140
149
|
try {
|
|
141
|
-
const query = `DELETE FROM ${tableName} WHERE ${pkFldName} = ${self.escape(this[
|
|
150
|
+
const query = `DELETE FROM ${tableName} WHERE ${pkFldName} = ${self.escape(this[pkAttrName])}`;
|
|
142
151
|
self.log(query);
|
|
143
152
|
removed = (await client.query(query)).rowCount === 1;
|
|
144
153
|
}
|
|
@@ -152,7 +161,7 @@ class PGDB extends sedentary_1.DB {
|
|
|
152
161
|
save(tableName, attributes, pk) {
|
|
153
162
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
154
163
|
const self = this;
|
|
155
|
-
const
|
|
164
|
+
const pkAttrName = pk.attributeName;
|
|
156
165
|
const pkFldName = pk.fieldName;
|
|
157
166
|
return async function () {
|
|
158
167
|
const client = this.tx ? this.tx._client : await self.pool.connect();
|
|
@@ -167,7 +176,7 @@ class PGDB extends sedentary_1.DB {
|
|
|
167
176
|
actions.push(`${attributes[attribute]} = ${self.escape(value)}`);
|
|
168
177
|
}
|
|
169
178
|
if (actions.length) {
|
|
170
|
-
const query = `UPDATE ${tableName} SET ${actions.join(", ")} WHERE ${pkFldName} = ${self.escape(this[
|
|
179
|
+
const query = `UPDATE ${tableName} SET ${actions.join(", ")} WHERE ${pkFldName} = ${self.escape(this[pkAttrName])}`;
|
|
171
180
|
self.log(query);
|
|
172
181
|
self.fill(attributes, (await client.query(query + " RETURNING *")).rows[0], this);
|
|
173
182
|
changed = true;
|
|
@@ -234,26 +243,26 @@ class PGDB extends sedentary_1.DB {
|
|
|
234
243
|
}
|
|
235
244
|
async dropIndexes(table, constraintIndexes) {
|
|
236
245
|
const { indexes, oid } = table;
|
|
237
|
-
const
|
|
246
|
+
const iObject = {};
|
|
238
247
|
const res = await this._client.query("SELECT amname, attname, indexrelid, indisunique, relname FROM pg_class, pg_index, pg_attribute, pg_am WHERE indrelid = $1 AND indexrelid = pg_class.oid AND attrelid = pg_class.oid AND relam = pg_am.oid ORDER BY attnum", [oid]);
|
|
239
248
|
for (const row of res.rows) {
|
|
240
249
|
const { amname, attname, indexrelid, indisunique, relname } = row;
|
|
241
250
|
if (!constraintIndexes.includes(indexrelid)) {
|
|
242
|
-
if (
|
|
243
|
-
|
|
251
|
+
if (iObject[relname])
|
|
252
|
+
iObject[relname].fields.push(attname);
|
|
244
253
|
else
|
|
245
|
-
|
|
254
|
+
iObject[relname] = { fields: [attname], indexName: relname, type: amname, unique: indisunique };
|
|
246
255
|
}
|
|
247
256
|
}
|
|
248
257
|
this.indexes = [];
|
|
249
258
|
for (const index of indexes) {
|
|
250
259
|
const { indexName } = index;
|
|
251
|
-
if (
|
|
260
|
+
if (iObject[indexName] && this.indexesEq(index, iObject[indexName])) {
|
|
252
261
|
this.indexes.push(indexName);
|
|
253
|
-
delete
|
|
262
|
+
delete iObject[indexName];
|
|
254
263
|
}
|
|
255
264
|
}
|
|
256
|
-
for (const index of Object.keys(
|
|
265
|
+
for (const index of Object.keys(iObject).sort()) {
|
|
257
266
|
const statement = `DROP INDEX ${index}`;
|
|
258
267
|
this.syncLog(statement);
|
|
259
268
|
if (this.sync)
|
|
@@ -306,13 +315,15 @@ class PGDB extends sedentary_1.DB {
|
|
|
306
315
|
return ["BOOL", "BOOL"];
|
|
307
316
|
case "DATETIME":
|
|
308
317
|
return ["DATETIME", "TIMESTAMP (3) WITH TIME ZONE"];
|
|
309
|
-
case "NUMBER":
|
|
310
|
-
return ["NUMERIC", "NUMERIC"];
|
|
311
318
|
case "INT":
|
|
312
319
|
ret = size === 2 ? "SMALLINT" : "INTEGER";
|
|
313
320
|
return [ret, ret];
|
|
314
321
|
case "INT8":
|
|
315
322
|
return ["BIGINT", "BIGINT"];
|
|
323
|
+
case "JSON":
|
|
324
|
+
return ["JSON", "JSON"];
|
|
325
|
+
case "NUMBER":
|
|
326
|
+
return ["NUMERIC", "NUMERIC"];
|
|
316
327
|
case "VARCHAR":
|
|
317
328
|
return ["VARCHAR", "VARCHAR" + (size ? `(${size})` : "")];
|
|
318
329
|
}
|
|
@@ -368,7 +379,7 @@ class PGDB extends sedentary_1.DB {
|
|
|
368
379
|
else {
|
|
369
380
|
const { adsrc, attnotnull, atttypmod, typname } = res.rows[0];
|
|
370
381
|
if (types[typname] !== base || (base === "VARCHAR" && (size ? size + 4 !== atttypmod : atttypmod !== -1))) {
|
|
371
|
-
if (needDrop.
|
|
382
|
+
if (needDrop.some(([type, name]) => attribute.type === type && typname === name)) {
|
|
372
383
|
await this.dropField(tableName, fieldName);
|
|
373
384
|
await addField();
|
|
374
385
|
await setDefault(false);
|
|
@@ -376,7 +387,7 @@ class PGDB extends sedentary_1.DB {
|
|
|
376
387
|
else {
|
|
377
388
|
if (adsrc)
|
|
378
389
|
dropDefault();
|
|
379
|
-
const using = needUsing.
|
|
390
|
+
const using = needUsing.some(([type, name]) => attribute.type === type && typname === name) ? " USING " + fieldName + "::" + type : "";
|
|
380
391
|
const statement = `ALTER TABLE ${tableName} ALTER COLUMN ${fieldName} TYPE ${type}${using}`;
|
|
381
392
|
this.syncLog(statement);
|
|
382
393
|
if (this.sync)
|
package/dist/es/adsrc.js
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -9,17 +9,16 @@ export class SedentaryPG extends Sedentary {
|
|
|
9
9
|
throw new Error("SedentaryPG.constructor: 'connection' argument: Wrong type, expected 'Object'");
|
|
10
10
|
this.db = new PGDB(connection, this.log);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
FKey(attribute, options) {
|
|
13
13
|
const { attributeName, modelName, unique } = attribute;
|
|
14
14
|
if (!unique)
|
|
15
|
-
throw new Error(`
|
|
16
|
-
return super.
|
|
15
|
+
throw new Error(`SedentaryPG.FKey: '${modelName}' model: '${attributeName}' attribute: is not unique: can't be used as FKey target`);
|
|
16
|
+
return super.FKey(attribute, options);
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
begin() {
|
|
19
19
|
return this.db.begin();
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
client() {
|
|
22
22
|
return this.db.client();
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
export const Package = SedentaryPG;
|
package/dist/es/pgdb.js
CHANGED
|
@@ -6,17 +6,27 @@ const needDrop = [
|
|
|
6
6
|
["DATETIME", "int2"],
|
|
7
7
|
["DATETIME", "int4"],
|
|
8
8
|
["DATETIME", "int8"],
|
|
9
|
+
["DATETIME", "numeric"],
|
|
10
|
+
["INT", "json"],
|
|
9
11
|
["INT", "timestamptz"],
|
|
10
|
-
["INT8", "
|
|
12
|
+
["INT8", "json"],
|
|
13
|
+
["INT8", "timestamptz"],
|
|
14
|
+
["JSON", "int2"],
|
|
15
|
+
["JSON", "int4"],
|
|
16
|
+
["JSON", "int8"],
|
|
17
|
+
["JSON", "numeric"],
|
|
18
|
+
["NUMBER", "json"],
|
|
19
|
+
["NUMBER", "timestamptz"]
|
|
11
20
|
];
|
|
12
21
|
const needUsing = [
|
|
13
22
|
["BOOLEAN", "varchar"],
|
|
14
23
|
["DATETIME", "varchar"],
|
|
15
24
|
["INT", "varchar"],
|
|
16
25
|
["INT8", "varchar"],
|
|
26
|
+
["JSON", "varchar"],
|
|
17
27
|
["NUMBER", "varchar"]
|
|
18
28
|
];
|
|
19
|
-
const types = { bool: "BOOL", int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", numeric: "NUMERIC", timestamptz: "DATETIME", varchar: "VARCHAR" };
|
|
29
|
+
const types = { bool: "BOOL", int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", json: "JSON", numeric: "NUMERIC", timestamptz: "DATETIME", varchar: "VARCHAR" };
|
|
20
30
|
const actions = { cascade: "c", "no action": "a", restrict: "r", "set default": "d", "set null": "n" };
|
|
21
31
|
function parseInt8(value) {
|
|
22
32
|
return BigInt(value);
|
|
@@ -64,10 +74,9 @@ export class PGDB extends DB {
|
|
|
64
74
|
escape(value) {
|
|
65
75
|
if (value === null || value === undefined)
|
|
66
76
|
throw new Error("SedentaryPG: Can't escape null nor undefined values; use the 'IS NULL' operator instead");
|
|
67
|
-
|
|
68
|
-
if (type === "number" || type === "boolean")
|
|
77
|
+
if (typeof value === "boolean" || typeof value === "number")
|
|
69
78
|
return value.toString();
|
|
70
|
-
if (
|
|
79
|
+
if (typeof value === "string")
|
|
71
80
|
return format("%L", value);
|
|
72
81
|
//if(value instanceof Date)
|
|
73
82
|
return format("%L", value).replace(/\.\d\d\d\+/, "+");
|
|
@@ -127,13 +136,13 @@ export class PGDB extends DB {
|
|
|
127
136
|
remove(tableName, pk) {
|
|
128
137
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
129
138
|
const self = this;
|
|
130
|
-
const
|
|
139
|
+
const pkAttrName = pk.attributeName;
|
|
131
140
|
const pkFldName = pk.fieldName;
|
|
132
141
|
return async function () {
|
|
133
142
|
const client = this.tx ? this.tx._client : await self.pool.connect();
|
|
134
143
|
let removed = false;
|
|
135
144
|
try {
|
|
136
|
-
const query = `DELETE FROM ${tableName} WHERE ${pkFldName} = ${self.escape(this[
|
|
145
|
+
const query = `DELETE FROM ${tableName} WHERE ${pkFldName} = ${self.escape(this[pkAttrName])}`;
|
|
137
146
|
self.log(query);
|
|
138
147
|
removed = (await client.query(query)).rowCount === 1;
|
|
139
148
|
}
|
|
@@ -147,7 +156,7 @@ export class PGDB extends DB {
|
|
|
147
156
|
save(tableName, attributes, pk) {
|
|
148
157
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
149
158
|
const self = this;
|
|
150
|
-
const
|
|
159
|
+
const pkAttrName = pk.attributeName;
|
|
151
160
|
const pkFldName = pk.fieldName;
|
|
152
161
|
return async function () {
|
|
153
162
|
const client = this.tx ? this.tx._client : await self.pool.connect();
|
|
@@ -162,7 +171,7 @@ export class PGDB extends DB {
|
|
|
162
171
|
actions.push(`${attributes[attribute]} = ${self.escape(value)}`);
|
|
163
172
|
}
|
|
164
173
|
if (actions.length) {
|
|
165
|
-
const query = `UPDATE ${tableName} SET ${actions.join(", ")} WHERE ${pkFldName} = ${self.escape(this[
|
|
174
|
+
const query = `UPDATE ${tableName} SET ${actions.join(", ")} WHERE ${pkFldName} = ${self.escape(this[pkAttrName])}`;
|
|
166
175
|
self.log(query);
|
|
167
176
|
self.fill(attributes, (await client.query(query + " RETURNING *")).rows[0], this);
|
|
168
177
|
changed = true;
|
|
@@ -229,26 +238,26 @@ export class PGDB extends DB {
|
|
|
229
238
|
}
|
|
230
239
|
async dropIndexes(table, constraintIndexes) {
|
|
231
240
|
const { indexes, oid } = table;
|
|
232
|
-
const
|
|
241
|
+
const iObject = {};
|
|
233
242
|
const res = await this._client.query("SELECT amname, attname, indexrelid, indisunique, relname FROM pg_class, pg_index, pg_attribute, pg_am WHERE indrelid = $1 AND indexrelid = pg_class.oid AND attrelid = pg_class.oid AND relam = pg_am.oid ORDER BY attnum", [oid]);
|
|
234
243
|
for (const row of res.rows) {
|
|
235
244
|
const { amname, attname, indexrelid, indisunique, relname } = row;
|
|
236
245
|
if (!constraintIndexes.includes(indexrelid)) {
|
|
237
|
-
if (
|
|
238
|
-
|
|
246
|
+
if (iObject[relname])
|
|
247
|
+
iObject[relname].fields.push(attname);
|
|
239
248
|
else
|
|
240
|
-
|
|
249
|
+
iObject[relname] = { fields: [attname], indexName: relname, type: amname, unique: indisunique };
|
|
241
250
|
}
|
|
242
251
|
}
|
|
243
252
|
this.indexes = [];
|
|
244
253
|
for (const index of indexes) {
|
|
245
254
|
const { indexName } = index;
|
|
246
|
-
if (
|
|
255
|
+
if (iObject[indexName] && this.indexesEq(index, iObject[indexName])) {
|
|
247
256
|
this.indexes.push(indexName);
|
|
248
|
-
delete
|
|
257
|
+
delete iObject[indexName];
|
|
249
258
|
}
|
|
250
259
|
}
|
|
251
|
-
for (const index of Object.keys(
|
|
260
|
+
for (const index of Object.keys(iObject).sort()) {
|
|
252
261
|
const statement = `DROP INDEX ${index}`;
|
|
253
262
|
this.syncLog(statement);
|
|
254
263
|
if (this.sync)
|
|
@@ -301,13 +310,15 @@ export class PGDB extends DB {
|
|
|
301
310
|
return ["BOOL", "BOOL"];
|
|
302
311
|
case "DATETIME":
|
|
303
312
|
return ["DATETIME", "TIMESTAMP (3) WITH TIME ZONE"];
|
|
304
|
-
case "NUMBER":
|
|
305
|
-
return ["NUMERIC", "NUMERIC"];
|
|
306
313
|
case "INT":
|
|
307
314
|
ret = size === 2 ? "SMALLINT" : "INTEGER";
|
|
308
315
|
return [ret, ret];
|
|
309
316
|
case "INT8":
|
|
310
317
|
return ["BIGINT", "BIGINT"];
|
|
318
|
+
case "JSON":
|
|
319
|
+
return ["JSON", "JSON"];
|
|
320
|
+
case "NUMBER":
|
|
321
|
+
return ["NUMERIC", "NUMERIC"];
|
|
311
322
|
case "VARCHAR":
|
|
312
323
|
return ["VARCHAR", "VARCHAR" + (size ? `(${size})` : "")];
|
|
313
324
|
}
|
|
@@ -363,7 +374,7 @@ export class PGDB extends DB {
|
|
|
363
374
|
else {
|
|
364
375
|
const { adsrc, attnotnull, atttypmod, typname } = res.rows[0];
|
|
365
376
|
if (types[typname] !== base || (base === "VARCHAR" && (size ? size + 4 !== atttypmod : atttypmod !== -1))) {
|
|
366
|
-
if (needDrop.
|
|
377
|
+
if (needDrop.some(([type, name]) => attribute.type === type && typname === name)) {
|
|
367
378
|
await this.dropField(tableName, fieldName);
|
|
368
379
|
await addField();
|
|
369
380
|
await setDefault(false);
|
|
@@ -371,7 +382,7 @@ export class PGDB extends DB {
|
|
|
371
382
|
else {
|
|
372
383
|
if (adsrc)
|
|
373
384
|
dropDefault();
|
|
374
|
-
const using = needUsing.
|
|
385
|
+
const using = needUsing.some(([type, name]) => attribute.type === type && typname === name) ? " USING " + fieldName + "::" + type : "";
|
|
375
386
|
const statement = `ALTER TABLE ${tableName} ALTER COLUMN ${fieldName} TYPE ${type}${using}`;
|
|
376
387
|
this.syncLog(statement);
|
|
377
388
|
if (this.sync)
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Attribute, EntryBase, ForeignKeyOptions,
|
|
1
|
+
import { Attribute, EntryBase, ForeignKeyOptions, Sedentary, SedentaryOptions, Type } from "sedentary";
|
|
2
2
|
import { PoolConfig } from "pg";
|
|
3
3
|
import { PGDB, TransactionPG } from "./pgdb";
|
|
4
4
|
export { Entry, EntryBase, SedentaryOptions, Type } from "sedentary";
|
|
5
5
|
export { TransactionPG } from "./pgdb";
|
|
6
6
|
export declare class SedentaryPG extends Sedentary<PGDB, TransactionPG> {
|
|
7
7
|
constructor(connection: PoolConfig, options?: SedentaryOptions);
|
|
8
|
-
|
|
8
|
+
FKey<T, E extends EntryBase>(attribute: Attribute<T, E>, options?: ForeignKeyOptions): Type<T, E>;
|
|
9
9
|
begin(): Promise<TransactionPG>;
|
|
10
10
|
client(): Promise<import("pg").PoolClient>;
|
|
11
11
|
}
|
|
12
|
-
export declare const Package: typeof SedentaryPG;
|
package/dist/types/pgdb.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PoolClient, PoolConfig } from "pg";
|
|
2
|
-
import { Attribute, DB, EntryBase,
|
|
2
|
+
import { Attribute, DB, EntryBase, Table, Transaction } from "sedentary";
|
|
3
3
|
export declare class PGDB extends DB<TransactionPG> {
|
|
4
4
|
private _client;
|
|
5
5
|
private indexes;
|
|
@@ -10,16 +10,16 @@ export declare class PGDB extends DB<TransactionPG> {
|
|
|
10
10
|
constructor(connection: PoolConfig, log: (message: string) => void);
|
|
11
11
|
connect(): Promise<void>;
|
|
12
12
|
end(): Promise<void>;
|
|
13
|
-
defaultNeq(src: string, value:
|
|
13
|
+
defaultNeq(src: string, value: unknown): boolean;
|
|
14
14
|
begin(): Promise<TransactionPG>;
|
|
15
15
|
client(): Promise<PoolClient>;
|
|
16
|
-
escape(value:
|
|
17
|
-
fill(attributes: Record<string, string>, row: Record<string,
|
|
18
|
-
load(tableName: string, attributes: Record<string, string>, pk: Attribute<
|
|
19
|
-
remove(tableName: string, pk: Attribute<
|
|
16
|
+
escape(value: unknown): string;
|
|
17
|
+
fill(attributes: Record<string, string>, row: Record<string, unknown>, entry: Record<string, unknown>): void;
|
|
18
|
+
load(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>, model: new (from: "load") => EntryBase, table: Table): (where: string, order?: string | string[], limit?: number, tx?: Transaction) => Promise<EntryBase[]>;
|
|
19
|
+
remove(tableName: string, pk: Attribute<unknown, unknown>): (this: Record<string, unknown> & {
|
|
20
20
|
tx?: TransactionPG;
|
|
21
21
|
}) => Promise<boolean>;
|
|
22
|
-
save(tableName: string, attributes: Record<string, string>, pk: Attribute<
|
|
22
|
+
save(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>): (this: Record<string, unknown> & {
|
|
23
23
|
loaded?: Record<string, unknown>;
|
|
24
24
|
tx?: TransactionPG;
|
|
25
25
|
}) => Promise<boolean>;
|
|
@@ -29,7 +29,7 @@ export declare class PGDB extends DB<TransactionPG> {
|
|
|
29
29
|
dropIndexes(table: Table, constraintIndexes: number[]): Promise<void>;
|
|
30
30
|
syncConstraints(table: Table): Promise<void>;
|
|
31
31
|
syncDataBase(): Promise<void>;
|
|
32
|
-
fieldType(attribute: Attribute<
|
|
32
|
+
fieldType(attribute: Attribute<unknown, unknown>): string[];
|
|
33
33
|
syncFields(table: Table): Promise<void>;
|
|
34
34
|
syncIndexes(table: Table): Promise<void>;
|
|
35
35
|
syncSequence(table: Table): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Daniele Ricci <daniele.icc@gmail.com> (https://github.com/iccicci)",
|
|
3
|
-
"bugs": "https://github.com/iccicci/sedentary
|
|
3
|
+
"bugs": "https://github.com/iccicci/sedentary/issues",
|
|
4
4
|
"contributors": [
|
|
5
5
|
"Daniele Ricci <daniele.icc@gmail.com> (https://github.com/iccicci)",
|
|
6
6
|
"yossarian <sergiybiluk@gmail.com> (https://github.com/captain-yossarian)"
|
|
@@ -9,32 +9,16 @@
|
|
|
9
9
|
"@types/pg": "8.6.5",
|
|
10
10
|
"pg": "8.7.3",
|
|
11
11
|
"pg-format": "1.0.4",
|
|
12
|
-
"sedentary": "0.0.
|
|
12
|
+
"sedentary": "0.0.44"
|
|
13
13
|
},
|
|
14
14
|
"description": "The ORM which never needs to migrate - PostgreSQL",
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"@types/jest": "28.1.3",
|
|
17
|
-
"@types/node": "18.0.0",
|
|
18
|
-
"@types/pg-format": "1.0.2",
|
|
19
|
-
"@types/yamljs": "0.2.31",
|
|
20
|
-
"@typescript-eslint/eslint-plugin": "5.30.0",
|
|
21
|
-
"@typescript-eslint/parser": "5.30.0",
|
|
22
|
-
"eslint": "8.18.0",
|
|
23
|
-
"jest": "28.1.1",
|
|
24
|
-
"jest-environment-node-single-context": "28.0.0",
|
|
25
|
-
"prettier": "2.7.1",
|
|
26
|
-
"ts-jest": "28.0.5",
|
|
27
|
-
"ts-node": "10.8.1",
|
|
28
|
-
"typescript": "4.7.4",
|
|
29
|
-
"yamljs": "0.3.0"
|
|
30
|
-
},
|
|
31
15
|
"engines": {
|
|
32
16
|
"node": ">=14.0"
|
|
33
17
|
},
|
|
34
18
|
"funding": {
|
|
35
19
|
"url": "https://blockchain.info/address/1Md9WFAHrXTb3yPBwQWmUfv2RmzrtbHioB"
|
|
36
20
|
},
|
|
37
|
-
"homepage": "https://github.com/iccicci/sedentary-pg#readme",
|
|
21
|
+
"homepage": "https://github.com/iccicci/sedentary/packages/sedentary-pg#readme",
|
|
38
22
|
"keywords": [
|
|
39
23
|
"DB",
|
|
40
24
|
"ORM",
|
|
@@ -51,42 +35,17 @@
|
|
|
51
35
|
"optionalDependencies": {
|
|
52
36
|
"fsevents": "2.3.2"
|
|
53
37
|
},
|
|
54
|
-
"prettier": {
|
|
55
|
-
"arrowParens": "avoid",
|
|
56
|
-
"endOfLine": "lf",
|
|
57
|
-
"jsxBracketSameLine": true,
|
|
58
|
-
"printWidth": 200,
|
|
59
|
-
"trailingComma": "none",
|
|
60
|
-
"useTabs": false
|
|
61
|
-
},
|
|
62
38
|
"readmeFilename": "README.md",
|
|
63
|
-
"repository": "https://github.com/iccicci/sedentary
|
|
39
|
+
"repository": "https://github.com/iccicci/sedentary",
|
|
64
40
|
"scripts": {
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"version": "node -r ts-node/register utils.ts version"
|
|
73
|
-
},
|
|
74
|
-
"tsd": {
|
|
75
|
-
"compilerOptions": {
|
|
76
|
-
"alwaysStrict": true,
|
|
77
|
-
"esModuleInterop": true,
|
|
78
|
-
"moduleResolution": "Node",
|
|
79
|
-
"noImplicitAny": true,
|
|
80
|
-
"noImplicitReturns": true,
|
|
81
|
-
"noImplicitThis": true,
|
|
82
|
-
"strict": true,
|
|
83
|
-
"strictBindCallApply": true,
|
|
84
|
-
"strictFunctionTypes": true,
|
|
85
|
-
"strictNullChecks": true,
|
|
86
|
-
"strictPropertyInitialization": true,
|
|
87
|
-
"target": "ESNext"
|
|
88
|
-
}
|
|
41
|
+
"build": "make build",
|
|
42
|
+
"coverage": "jest --coverage --no-cache --runInBand",
|
|
43
|
+
"deploy": "make deploy",
|
|
44
|
+
"precoverage": "make pretest",
|
|
45
|
+
"preinstall": "if [ -f Makefile ] ; then make ; fi",
|
|
46
|
+
"pretest": "make pretest",
|
|
47
|
+
"test": "jest --no-cache --runInBand"
|
|
89
48
|
},
|
|
90
49
|
"types": "./dist/types/index.d.ts",
|
|
91
|
-
"version": "0.0.
|
|
50
|
+
"version": "0.0.44"
|
|
92
51
|
}
|