sedentary-pg 0.0.52 → 0.0.54

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/dist/cjs/pgdb.js CHANGED
@@ -7,12 +7,15 @@ exports.TransactionPG = exports.PGDB = void 0;
7
7
  const pg_1 = require("pg");
8
8
  const pg_format_1 = __importDefault(require("pg-format"));
9
9
  const sedentary_1 = require("sedentary");
10
- const adsrc_1 = require("./adsrc");
11
10
  const needDrop = [
11
+ ["DATETIME", "float4"],
12
+ ["DATETIME", "float8"],
12
13
  ["DATETIME", "int2"],
13
14
  ["DATETIME", "int4"],
14
15
  ["DATETIME", "int8"],
15
16
  ["DATETIME", "numeric"],
17
+ ["FLOAT", "json"],
18
+ ["FLOAT", "timestamptz"],
16
19
  ["INT", "json"],
17
20
  ["INT", "timestamptz"],
18
21
  ["INT8", "json"],
@@ -32,7 +35,7 @@ const needUsing = [
32
35
  ["JSON", "varchar"],
33
36
  ["NUMBER", "varchar"]
34
37
  ];
35
- const types = { bool: "BOOL", int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", json: "JSON", numeric: "NUMERIC", timestamptz: "DATETIME", varchar: "VARCHAR" };
38
+ const types = { bool: "BOOL", float4: "FLOAT4", float8: "FLOAT8", int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", json: "JSON", numeric: "NUMERIC", timestamptz: "DATETIME", varchar: "VARCHAR" };
36
39
  const actions = { cascade: "c", "no action": "a", restrict: "r", "set default": "d", "set null": "n" };
37
40
  function parseInt8(value) {
38
41
  return BigInt(value);
@@ -80,7 +83,7 @@ class PGDB extends sedentary_1.DB {
80
83
  try {
81
84
  const query = `DELETE FROM ${tableName}${where ? ` WHERE ${where}` : ""}`;
82
85
  this.log(query);
83
- ({ rowCount } = await client.query(query));
86
+ ({ rowCount } = (await client.query(query)));
84
87
  }
85
88
  finally {
86
89
  if (!tx)
@@ -336,6 +339,9 @@ class PGDB extends sedentary_1.DB {
336
339
  return ["BOOL", "BOOL"];
337
340
  case "DATETIME":
338
341
  return ["DATETIME", "TIMESTAMP (3) WITH TIME ZONE"];
342
+ case "FLOAT":
343
+ ret = _size === 4 ? "FLOAT4" : "FLOAT8";
344
+ return [ret, ret];
339
345
  case "INT":
340
346
  ret = _size === 2 ? "SMALLINT" : "INTEGER";
341
347
  return [ret, ret];
@@ -359,7 +365,7 @@ class PGDB extends sedentary_1.DB {
359
365
  const defaultValue = attribute.defaultValue === undefined ? (autoIncrement && fieldName === "id" ? `nextval('${tableName}_id_seq'::regclass)` : undefined) : this.escape(attribute.defaultValue);
360
366
  const [base, type] = this.fieldType(attribute);
361
367
  const where = "attrelid = $1 AND attnum > 0 AND atttypid = pg_type.oid AND attislocal = 't' AND attname = $2";
362
- const res = await this._client.query(`SELECT attnotnull, atttypmod, typname, ${(0, adsrc_1.adsrc)(this.version)} FROM pg_type, pg_attribute LEFT JOIN pg_attrdef ON adrelid = attrelid AND adnum = attnum WHERE ${where}`, [oid, fieldName]);
368
+ const res = await this._client.query(`SELECT attnotnull, atttypmod, typname, pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid) AS adsrc FROM pg_type, pg_attribute LEFT JOIN pg_attrdef ON adrelid = attrelid AND adnum = attnum WHERE ${where}`, [oid, fieldName]);
363
369
  const addField = async () => {
364
370
  const statement = `ALTER TABLE ${tableName} ADD COLUMN ${fieldName} ${type}`;
365
371
  this.syncLog(statement);
package/dist/es/pgdb.js CHANGED
@@ -1,12 +1,15 @@
1
1
  import { DatabaseError, Pool, types as PGtypes } from "pg";
2
2
  import format from "pg-format";
3
3
  import { base, DB, deepCopy, deepDiff, loaded, size, Transaction, transaction } from "sedentary";
4
- import { adsrc } from "./adsrc";
5
4
  const needDrop = [
5
+ ["DATETIME", "float4"],
6
+ ["DATETIME", "float8"],
6
7
  ["DATETIME", "int2"],
7
8
  ["DATETIME", "int4"],
8
9
  ["DATETIME", "int8"],
9
10
  ["DATETIME", "numeric"],
11
+ ["FLOAT", "json"],
12
+ ["FLOAT", "timestamptz"],
10
13
  ["INT", "json"],
11
14
  ["INT", "timestamptz"],
12
15
  ["INT8", "json"],
@@ -26,7 +29,7 @@ const needUsing = [
26
29
  ["JSON", "varchar"],
27
30
  ["NUMBER", "varchar"]
28
31
  ];
29
- const types = { bool: "BOOL", int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", json: "JSON", numeric: "NUMERIC", timestamptz: "DATETIME", varchar: "VARCHAR" };
32
+ const types = { bool: "BOOL", float4: "FLOAT4", float8: "FLOAT8", int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", json: "JSON", numeric: "NUMERIC", timestamptz: "DATETIME", varchar: "VARCHAR" };
30
33
  const actions = { cascade: "c", "no action": "a", restrict: "r", "set default": "d", "set null": "n" };
31
34
  function parseInt8(value) {
32
35
  return BigInt(value);
@@ -75,7 +78,7 @@ export class PGDB extends DB {
75
78
  try {
76
79
  const query = `DELETE FROM ${tableName}${where ? ` WHERE ${where}` : ""}`;
77
80
  this.log(query);
78
- ({ rowCount } = await client.query(query));
81
+ ({ rowCount } = (await client.query(query)));
79
82
  }
80
83
  finally {
81
84
  if (!tx)
@@ -331,6 +334,9 @@ export class PGDB extends DB {
331
334
  return ["BOOL", "BOOL"];
332
335
  case "DATETIME":
333
336
  return ["DATETIME", "TIMESTAMP (3) WITH TIME ZONE"];
337
+ case "FLOAT":
338
+ ret = _size === 4 ? "FLOAT4" : "FLOAT8";
339
+ return [ret, ret];
334
340
  case "INT":
335
341
  ret = _size === 2 ? "SMALLINT" : "INTEGER";
336
342
  return [ret, ret];
@@ -354,7 +360,7 @@ export class PGDB extends DB {
354
360
  const defaultValue = attribute.defaultValue === undefined ? (autoIncrement && fieldName === "id" ? `nextval('${tableName}_id_seq'::regclass)` : undefined) : this.escape(attribute.defaultValue);
355
361
  const [base, type] = this.fieldType(attribute);
356
362
  const where = "attrelid = $1 AND attnum > 0 AND atttypid = pg_type.oid AND attislocal = 't' AND attname = $2";
357
- const res = await this._client.query(`SELECT attnotnull, atttypmod, typname, ${adsrc(this.version)} FROM pg_type, pg_attribute LEFT JOIN pg_attrdef ON adrelid = attrelid AND adnum = attnum WHERE ${where}`, [oid, fieldName]);
363
+ const res = await this._client.query(`SELECT attnotnull, atttypmod, typname, pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid) AS adsrc FROM pg_type, pg_attribute LEFT JOIN pg_attrdef ON adrelid = attrelid AND adnum = attnum WHERE ${where}`, [oid, fieldName]);
358
364
  const addField = async () => {
359
365
  const statement = `ALTER TABLE ${tableName} ADD COLUMN ${fieldName} ${type}`;
360
366
  this.syncLog(statement);
package/package.json CHANGED
@@ -6,14 +6,14 @@
6
6
  "yossarian <sergiybiluk@gmail.com> (https://github.com/captain-yossarian)"
7
7
  ],
8
8
  "dependencies": {
9
- "@types/pg": "8.6.5",
10
- "pg": "8.8.0",
11
- "pg-format": "1.0.4",
12
- "sedentary": "0.0.52"
9
+ "@types/pg": "^8.11.4",
10
+ "pg": "^8.11.4",
11
+ "pg-format": "^1.0.4",
12
+ "sedentary": "0.0.54"
13
13
  },
14
14
  "description": "The ORM which never needs to migrate - PostgreSQL",
15
15
  "engines": {
16
- "node": ">=14.0"
16
+ "node": ">=18.0"
17
17
  },
18
18
  "funding": {
19
19
  "url": "https://blockchain.info/address/1Md9WFAHrXTb3yPBwQWmUfv2RmzrtbHioB"
@@ -33,10 +33,13 @@
33
33
  "module": "./dist/es/index.js",
34
34
  "name": "sedentary-pg",
35
35
  "optionalDependencies": {
36
- "fsevents": "2.3.2"
36
+ "fsevents": "^2.3.3"
37
37
  },
38
38
  "readmeFilename": "README.md",
39
- "repository": "https://github.com/iccicci/sedentary",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/iccicci/sedentary.git"
42
+ },
40
43
  "scripts": {
41
44
  "build": "make build",
42
45
  "coverage": "jest --coverage --no-cache --runInBand",
@@ -47,5 +50,5 @@
47
50
  "test": "jest --no-cache --runInBand"
48
51
  },
49
52
  "types": "./dist/types/index.d.ts",
50
- "version": "0.0.52"
53
+ "version": "0.0.54"
51
54
  }
package/dist/cjs/adsrc.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.adsrc = void 0;
4
- // cspell: disable-next-line
5
- function adsrc(version) {
6
- // cspell: disable-next-line
7
- return version >= 12 ? "pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid) AS adsrc" : "adsrc";
8
- }
9
- exports.adsrc = adsrc;
package/dist/es/adsrc.js DELETED
@@ -1,5 +0,0 @@
1
- // cspell: disable-next-line
2
- export function adsrc(version) {
3
- // cspell: disable-next-line
4
- return version >= 12 ? "pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid) AS adsrc" : "adsrc";
5
- }
@@ -1 +0,0 @@
1
- export declare function adsrc(version: number): "pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid) AS adsrc" | "adsrc";