mythix-orm-postgresql 1.5.1 → 1.6.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.
@@ -4,7 +4,7 @@
4
4
  'use strict';
5
5
 
6
6
  const Nife = require('nife');
7
- const moment = require('moment');
7
+ const { DateTime } = require('luxon');
8
8
  const PG = require('pg');
9
9
  const PGFormat = require('pg-format');
10
10
  const { Literals } = require('mythix-orm');
@@ -99,15 +99,15 @@ class PostgreSQLConnection extends SQLConnectionBase {
99
99
  // This will get discarded by createTable...
100
100
  // but we need the value later to select the
101
101
  // proper column data type
102
- return new Literals.Literal('@@@AUTOINCREMENT@@@', { noDefaultStatementOnCreateTable: true, remote: true });
102
+ return new Literals.Literal('AUTOINCREMENT', { noDefaultStatementOnCreateTable: true, remote: true });
103
103
  case 'DATETIME_NOW':
104
- return new Literals.Literal('(NOW() AT TIME ZONE(\'UTC\'))', { escape: false, remote: true });
104
+ return new Literals.Literal('(FLOOR(EXTRACT(EPOCH FROM NOW()) * 1000))', { escape: false, remote: true });
105
105
  case 'DATE_NOW':
106
- return new Literals.Literal('(NOW() AT TIME ZONE(\'UTC\'))', { escape: false, remote: true });
106
+ return new Literals.Literal('(FLOOR(EXTRACT(EPOCH FROM NOW()) * 1000))', { escape: false, remote: true });
107
107
  case 'DATETIME_NOW_LOCAL':
108
- return moment().toDate();
108
+ return DateTime.now().toMillis();
109
109
  case 'DATE_NOW_LOCAL':
110
- return moment().startOf('day').toDate();
110
+ return DateTime.now().startOf('day').toMillis();
111
111
  default:
112
112
  return type;
113
113
  }
@@ -279,7 +279,7 @@ class PostgreSQLConnection extends SQLConnectionBase {
279
279
  _bigintTypeToString(type, _options) {
280
280
  let options = _options || {};
281
281
 
282
- if (options.createTable && options.defaultValue === '@@@AUTOINCREMENT@@@')
282
+ if (options.createTable && options.defaultValue === 'AUTOINCREMENT')
283
283
  return this._intTypeToSerial(type);
284
284
 
285
285
  return 'BIGINT';
@@ -288,7 +288,7 @@ class PostgreSQLConnection extends SQLConnectionBase {
288
288
  _integerTypeToString(type, _options) {
289
289
  let options = _options || {};
290
290
 
291
- if (options.createTable && options.defaultValue === '@@@AUTOINCREMENT@@@')
291
+ if (options.createTable && options.defaultValue === 'AUTOINCREMENT')
292
292
  return this._intTypeToSerial(type);
293
293
 
294
294
  return 'INTEGER';
@@ -298,8 +298,14 @@ class PostgreSQLConnection extends SQLConnectionBase {
298
298
  return 'BYTEA';
299
299
  }
300
300
 
301
+ // eslint-disable-next-line no-unused-vars
302
+ _dateTypeToString(type) {
303
+ return 'BIGINT';
304
+ }
305
+
306
+ // eslint-disable-next-line no-unused-vars
301
307
  _datetimeTypeToString(type) {
302
- return 'TIMESTAMP';
308
+ return 'BIGINT';
303
309
  }
304
310
 
305
311
  // eslint-disable-next-line no-unused-vars
@@ -359,15 +365,6 @@ class PostgreSQLConnection extends SQLConnectionBase {
359
365
 
360
366
  return result;
361
367
  }
362
-
363
- convertDateToDBTime(value) {
364
- if (value instanceof Date || (value && value.constructor && value.constructor.name === 'Date'))
365
- return moment(value).utc(true).toDate();
366
- else if (moment.isMoment(value))
367
- return value.utc(true).toDate();
368
-
369
- return value;
370
- }
371
368
  }
372
369
 
373
370
  module.exports = PostgreSQLConnection;
@@ -84,59 +84,9 @@ class PostgreSQLQueryGenerator extends SQLQueryGeneratorBase {
84
84
  return this._collectReturningFields(Model, model, options, context);
85
85
  }
86
86
 
87
- generateCreateTableStatement(Model, _options) {
87
+ generateColumnDeclarationStatement(Model, field, _options) {
88
88
  let options = _options || {};
89
- let fieldParts = [];
90
-
91
- Model.iterateFields(({ field, fieldName }) => {
92
- if (field.type.isVirtual())
93
- return;
94
-
95
- let columnName = field.columnName || fieldName;
96
- let constraintParts = [];
97
-
98
- let defaultValue = this.getFieldDefaultValue(field, fieldName, { remoteOnly: true });
99
-
100
- if (field.primaryKey) {
101
- if (field.primaryKey instanceof LiteralBase)
102
- constraintParts.push(field.primaryKey.toString(this.connection));
103
- else
104
- constraintParts.push('PRIMARY KEY');
105
-
106
- if (defaultValue !== '@@@AUTOINCREMENT@@@')
107
- constraintParts.push('NOT NULL');
108
- } else {
109
- if (field.unique) {
110
- if (field.unique instanceof LiteralBase)
111
- constraintParts.push(field.unique.toString(this.connection));
112
- else
113
- constraintParts.push('UNIQUE');
114
- }
115
-
116
- if (field.allowNull === false)
117
- constraintParts.push('NOT NULL');
118
- }
119
-
120
- if (defaultValue !== undefined && defaultValue !== '@@@AUTOINCREMENT@@@')
121
- constraintParts.push(defaultValue);
122
-
123
- constraintParts = constraintParts.join(' ');
124
- if (Nife.isNotEmpty(constraintParts))
125
- constraintParts = ` ${constraintParts}`;
126
-
127
- fieldParts.push(` ${this.escapeID(columnName)} ${field.type.toConnectionType(this.connection, { createTable: true, defaultValue })}${constraintParts}`);
128
- });
129
-
130
- let ifNotExists = 'IF NOT EXISTS ';
131
- if (options.ifNotExists === false)
132
- ifNotExists = '';
133
-
134
- let trailingParts = Nife.toArray(this.generateCreateTableStatementInnerTail(Model, options)).filter(Boolean);
135
- if (Nife.isNotEmpty(trailingParts))
136
- fieldParts = fieldParts.concat(trailingParts.map((part) => ` ${part.trim()}`));
137
-
138
- let finalStatement = `CREATE TABLE ${ifNotExists}${this.escapeID(Model.getTableName(this.connection))} (${fieldParts.join(',\n')}\n);`;
139
- return finalStatement;
89
+ return super.generateColumnDeclarationStatement(Model, field, { ...options, noAutoIncrementDefault: true });
140
90
  }
141
91
 
142
92
  generateTruncateTableStatement(Model, _options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm-postgresql",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "PostgreSQL driver for Mythix ORM",
5
5
  "main": "lib/index.js",
6
6
  "type": "commonjs",
@@ -33,10 +33,11 @@
33
33
  },
34
34
  "homepage": "https://github.com/th317erd/mythix-orm-postgresql#readme",
35
35
  "peerDependencies": {
36
- "mythix-orm": "^1.6.3",
37
- "mythix-orm-sql-base": "^1.5.2"
36
+ "mythix-orm": "^1.7.0",
37
+ "mythix-orm-sql-base": "^1.6.0"
38
38
  },
39
39
  "dependencies": {
40
+ "luxon": "^3.0.4",
40
41
  "nife": "^1.12.1",
41
42
  "pg": "^8.8.0",
42
43
  "pg-format": "^1.0.4",
@@ -46,7 +47,6 @@
46
47
  "@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
47
48
  "eslint": "^8.23.1",
48
49
  "jasmine": "^4.4.0",
49
- "moment": "^2.29.4",
50
50
  "nyc": "^15.1.0"
51
51
  },
52
52
  "nyc": {