nodecommons-esm-database 0.0.11 → 0.0.12
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.
|
@@ -2,10 +2,10 @@ import { CommonsFixedDate } from 'tscommons-esm-core';
|
|
|
2
2
|
import { TCommonsDatabaseInternalPostgresInterval } from '../types/tcommons-database-postgres-interval.mjs';
|
|
3
3
|
import { ECommonsDatabaseEngine } from '../enums/ecommons-database-engine.mjs';
|
|
4
4
|
import { CommonsDatabaseType } from './commons-database-type.mjs';
|
|
5
|
-
export declare class CommonsDatabaseTypeFixedTime extends CommonsDatabaseType<CommonsFixedDate, Date | TCommonsDatabaseInternalPostgresInterval | number> {
|
|
5
|
+
export declare class CommonsDatabaseTypeFixedTime extends CommonsDatabaseType<CommonsFixedDate, Date | TCommonsDatabaseInternalPostgresInterval | number | string> {
|
|
6
6
|
protected renderEngineType(engine: ECommonsDatabaseEngine): string;
|
|
7
7
|
assertValue(value: CommonsFixedDate | undefined): void | never;
|
|
8
|
-
assertDbValue(value: Date | number | null | undefined, engine: ECommonsDatabaseEngine): void | never;
|
|
9
|
-
protected encode(value: CommonsFixedDate,
|
|
10
|
-
protected decode(value: Date | TCommonsDatabaseInternalPostgresInterval | number, engine: ECommonsDatabaseEngine): CommonsFixedDate;
|
|
8
|
+
assertDbValue(value: Date | number | string | null | undefined, engine: ECommonsDatabaseEngine): void | never;
|
|
9
|
+
protected encode(value: CommonsFixedDate, engine: ECommonsDatabaseEngine): Date | string | number;
|
|
10
|
+
protected decode(value: Date | TCommonsDatabaseInternalPostgresInterval | string | number, engine: ECommonsDatabaseEngine): CommonsFixedDate;
|
|
11
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonsFixedDate, commonsTypeAssertDate, commonsTypeAssertNumber, commonsTypeHasPropertyNumber } from 'tscommons-esm-core';
|
|
1
|
+
import { CommonsFixedDate, commonsTypeAssertDate, commonsTypeAssertNumber, commonsTypeHasPropertyNumber, commonsTypeIsString } from 'tscommons-esm-core';
|
|
2
2
|
import { isTCommonsDatabaseInternalPostgresInterval } from '../types/tcommons-database-postgres-interval.mjs';
|
|
3
3
|
import { ECommonsDatabaseEngine } from '../enums/ecommons-database-engine.mjs';
|
|
4
4
|
import { CommonsDatabaseType } from './commons-database-type.mjs';
|
|
@@ -24,8 +24,13 @@ export class CommonsDatabaseTypeFixedTime extends CommonsDatabaseType {
|
|
|
24
24
|
super.assertDbValue(value, engine);
|
|
25
25
|
if (value === undefined || value === null)
|
|
26
26
|
return;
|
|
27
|
-
if (engine === ECommonsDatabaseEngine.POSTGRES
|
|
28
|
-
|
|
27
|
+
if (engine === ECommonsDatabaseEngine.POSTGRES) {
|
|
28
|
+
if (isTCommonsDatabaseInternalPostgresInterval(value))
|
|
29
|
+
return;
|
|
30
|
+
// node-postgres seems to store send times as strings, and the [date]T[time] format isn't accepted by postgres itself
|
|
31
|
+
if (commonsTypeIsString(value))
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
29
34
|
if (engine === ECommonsDatabaseEngine.SQLITE) {
|
|
30
35
|
// SQLite stores its timestamps as longs
|
|
31
36
|
commonsTypeAssertNumber(value);
|
|
@@ -33,25 +38,36 @@ export class CommonsDatabaseTypeFixedTime extends CommonsDatabaseType {
|
|
|
33
38
|
}
|
|
34
39
|
commonsTypeAssertDate(value);
|
|
35
40
|
}
|
|
36
|
-
encode(value,
|
|
41
|
+
encode(value, engine) {
|
|
37
42
|
// No need to convert to number for SQLLITE; it seems to do it itself
|
|
38
43
|
const timeOnly = value.clone;
|
|
39
44
|
timeOnly.Ymd = '1970-01-01';
|
|
45
|
+
if (engine === ECommonsDatabaseEngine.POSTGRES) {
|
|
46
|
+
// node-postgres seems to store send times as strings, and the [date]T[time] format isn't accepted by postgres itself
|
|
47
|
+
return timeOnly.His;
|
|
48
|
+
}
|
|
40
49
|
return timeOnly.UTCDate;
|
|
41
50
|
}
|
|
42
51
|
decode(value, engine) {
|
|
43
|
-
if (engine === ECommonsDatabaseEngine.POSTGRES
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
if (engine === ECommonsDatabaseEngine.POSTGRES) {
|
|
53
|
+
if (isTCommonsDatabaseInternalPostgresInterval(value)) {
|
|
54
|
+
const time = new Date(0);
|
|
55
|
+
// ignore the date components
|
|
56
|
+
if (commonsTypeHasPropertyNumber(value, 'milliseconds'))
|
|
57
|
+
time.setMilliseconds(value.milliseconds);
|
|
58
|
+
if (commonsTypeHasPropertyNumber(value, 'seconds'))
|
|
59
|
+
time.setSeconds(value.seconds);
|
|
60
|
+
if (commonsTypeHasPropertyNumber(value, 'minutes'))
|
|
61
|
+
time.setMinutes(value.minutes);
|
|
62
|
+
if (commonsTypeHasPropertyNumber(value, 'hours'))
|
|
63
|
+
time.setHours(value.hours);
|
|
64
|
+
return CommonsFixedDate.fromUTCDate(time);
|
|
65
|
+
}
|
|
66
|
+
// node-postgres seems to store send times as strings, and the [date]T[time] format isn't accepted by postgres itself
|
|
67
|
+
if (commonsTypeIsString(value)) {
|
|
68
|
+
const timeOnly = CommonsFixedDate.fromHis(value);
|
|
69
|
+
return timeOnly;
|
|
70
|
+
}
|
|
55
71
|
}
|
|
56
72
|
if (engine === ECommonsDatabaseEngine.SQLITE) {
|
|
57
73
|
commonsTypeAssertNumber(value);
|
|
@@ -59,9 +75,11 @@ export class CommonsDatabaseTypeFixedTime extends CommonsDatabaseType {
|
|
|
59
75
|
return CommonsFixedDate.fromUTCDate(new Date(value));
|
|
60
76
|
}
|
|
61
77
|
commonsTypeAssertDate(value);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
{ // scope
|
|
79
|
+
const timeOnly = CommonsFixedDate.fromUTCDate(value);
|
|
80
|
+
timeOnly.Ymd = '1970-01-01';
|
|
81
|
+
return timeOnly;
|
|
82
|
+
}
|
|
65
83
|
}
|
|
66
84
|
}
|
|
67
85
|
//# sourceMappingURL=commons-database-type-fixed-time.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commons-database-type-fixed-time.mjs","sourceRoot":"","sources":["../../src/classes/commons-database-type-fixed-time.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"commons-database-type-fixed-time.mjs","sourceRoot":"","sources":["../../src/classes/commons-database-type-fixed-time.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzJ,OAAO,EAAE,0CAA0C,EAA4C,MAAM,kDAAkD,CAAC;AAExJ,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,OAAO,4BAA6B,SAAQ,mBAAkG;IACzI,gBAAgB,CAAC,MAA8B;QACxD,QAAQ,MAAM,EAAE,CAAC;YAChB,KAAK,sBAAsB,CAAC,KAAK;gBAChC,OAAO,MAAM,CAAC;YACf,KAAK,sBAAsB,CAAC,QAAQ;gBACnC,OAAO,wBAAwB,CAAC;YACjC;gBACC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;IACF,CAAC;IAEe,WAAW,CAAC,KAAiC;QAC5D,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO;QAEhC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjH,CAAC;IAEe,aAA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