@expressive/sql 0.7.0 → 0.8.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.
@@ -1,21 +0,0 @@
1
- import { str } from "@expressive/orm";
2
-
3
- //#region src/columns/Str.ts
4
- /** Column class behind `str()` on SQL - `text`, `varchar`, `char` or `uuid`. */
5
- var StringColumn = class extends str.Type {
6
- constructor(..._args) {
7
- super(..._args);
8
- this.type = "text";
9
- }
10
- get datatype() {
11
- let { type, length, collate } = this;
12
- if (type.endsWith("char") && length) type += `(${length})`;
13
- if (collate) type += ` COLLATE "${collate}"`;
14
- return type;
15
- }
16
- };
17
- str.Type = StringColumn;
18
-
19
- //#endregion
20
- export { StringColumn };
21
- //# sourceMappingURL=Str.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Str.js","names":[],"sources":["../../src/columns/Str.ts"],"sourcesContent":["import { str } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace str {\n interface Text extends StringColumn {\n type: \"text\";\n }\n\n interface VarChar extends StringColumn {\n type: \"varchar\";\n length: number;\n }\n\n interface Char extends StringColumn {\n type: \"char\";\n length: number;\n }\n\n interface UUID extends StringColumn {\n type: \"uuid\";\n }\n\n interface Types {\n default: Text;\n text: Text;\n varchar: VarChar;\n char: Char;\n uuid: UUID;\n }\n }\n}\n\n/** Column class behind `str()` on SQL - `text`, `varchar`, `char` or `uuid`. */\nexport class StringColumn extends str.Type {\n type: str.DataType = \"text\";\n\n get datatype() {\n let { type, length, collate } = this;\n\n if (type.endsWith(\"char\") && length)\n type += `(${length})`;\n\n if (collate)\n type += ` COLLATE \"${collate}\"`;\n\n return type;\n }\n}\n\nstr.Type = StringColumn;\n"],"mappings":";;;;AAiCA,IAAa,eAAb,cAAkC,IAAI,KAAK;;;cACpB;;CAErB,IAAI,WAAW;EACb,IAAI,EAAE,MAAM,QAAQ,YAAY;AAEhC,MAAI,KAAK,SAAS,OAAO,IAAI,OAC3B,SAAQ,IAAI,OAAO;AAErB,MAAI,QACF,SAAQ,aAAa,QAAQ;AAE/B,SAAO;;;AAIX,IAAI,OAAO"}
@@ -1,52 +0,0 @@
1
- import { date } from "@expressive/orm";
2
-
3
- //#region src/columns/Time.d.ts
4
- declare module '@expressive/orm' {
5
- namespace date {
6
- interface Timestamp extends TimeColumn {
7
- type: "timestamp";
8
- }
9
- interface Day extends TimeColumn {
10
- type: "date";
11
- }
12
- interface Time extends TimeColumn {
13
- type: "time";
14
- }
15
- interface Integer extends TimeColumn {
16
- type: "integer";
17
- }
18
- interface Text extends TimeColumn {
19
- type: "text";
20
- }
21
- interface Ms extends TimeColumn {
22
- type: "ms";
23
- }
24
- interface Seconds extends TimeColumn {
25
- type: "seconds";
26
- }
27
- interface Types {
28
- default: Timestamp;
29
- timestamp: Timestamp;
30
- date: Day;
31
- time: Time;
32
- integer: Integer;
33
- text: Text;
34
- ms: Ms;
35
- seconds: Seconds;
36
- }
37
- }
38
- }
39
- /**
40
- * Column class behind `date()` on SQL.
41
- *
42
- * Stores a Date as `timestamp`, `date`, `time`, `ms`, `seconds`, `integer` or `text`.
43
- */
44
- declare class TimeColumn extends date.Type {
45
- type: date.DataType;
46
- get datatype(): string;
47
- get(value: unknown): Date | undefined;
48
- set(value: unknown): string | number | undefined;
49
- }
50
- //#endregion
51
- export { TimeColumn };
52
- //# sourceMappingURL=Time.d.ts.map
@@ -1,45 +0,0 @@
1
- import { date } from "@expressive/orm";
2
-
3
- //#region src/columns/Time.ts
4
- /**
5
- * Column class behind `date()` on SQL.
6
- *
7
- * Stores a Date as `timestamp`, `date`, `time`, `ms`, `seconds`, `integer` or `text`.
8
- */
9
- var TimeColumn = class extends date.Type {
10
- constructor(..._args) {
11
- super(..._args);
12
- this.type = "timestamp";
13
- }
14
- get datatype() {
15
- const { type } = this;
16
- return type === "ms" ? "bigint" : type === "seconds" ? "integer" : super.datatype;
17
- }
18
- get(value) {
19
- if (value == null) return void 0;
20
- if (this.type === "ms") return new Date(Number(value));
21
- if (typeof value === "number") return /* @__PURE__ */ new Date(value * 1e3);
22
- if (typeof value === "string" && this.type === "date") {
23
- const [year, month, day] = value.split("-").map(Number);
24
- return new Date(year, month - 1, day);
25
- }
26
- if (typeof value === "string" && this.type === "time") return /* @__PURE__ */ new Date(`1970-01-01T${value}Z`);
27
- if (typeof value === "string" && /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d(\.\d+)?$/.test(value)) return /* @__PURE__ */ new Date(value.replace(" ", "T") + "Z");
28
- return new Date(value);
29
- }
30
- set(value) {
31
- const iso = super.set(value);
32
- if (iso === void 0) return iso;
33
- const date = new Date(iso);
34
- if (this.type === "ms") return date.getTime();
35
- if (this.type === "integer" || this.type === "seconds") return Math.floor(date.getTime() / 1e3);
36
- if (this.type === "date") return date.toISOString().slice(0, 10);
37
- if (this.type === "time") return date.toISOString().slice(11, 19);
38
- return iso;
39
- }
40
- };
41
- date.Type = TimeColumn;
42
-
43
- //#endregion
44
- export { TimeColumn };
45
- //# sourceMappingURL=Time.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Time.js","names":[],"sources":["../../src/columns/Time.ts"],"sourcesContent":["import { date } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace date {\n interface Timestamp extends TimeColumn {\n type: \"timestamp\";\n }\n\n interface Day extends TimeColumn {\n type: \"date\";\n }\n\n interface Time extends TimeColumn {\n type: \"time\";\n }\n\n interface Integer extends TimeColumn {\n type: \"integer\";\n }\n\n interface Text extends TimeColumn {\n type: \"text\";\n }\n\n interface Ms extends TimeColumn {\n type: \"ms\";\n }\n\n interface Seconds extends TimeColumn {\n type: \"seconds\";\n }\n\n interface Types {\n default: Timestamp;\n timestamp: Timestamp;\n date: Day;\n time: Time;\n integer: Integer;\n text: Text;\n ms: Ms;\n seconds: Seconds;\n }\n }\n}\n\n/**\n * Column class behind `date()` on SQL.\n *\n * Stores a Date as `timestamp`, `date`, `time`, `ms`, `seconds`, `integer` or `text`.\n */\nexport class TimeColumn extends date.Type {\n type: date.DataType = \"timestamp\";\n\n get datatype() {\n const { type } = this;\n\n return type === \"ms\" ? \"bigint\" : type === \"seconds\" ? \"integer\" : super.datatype;\n }\n\n get(value: unknown) {\n if (value == null)\n return undefined;\n\n if (this.type === \"ms\")\n return new Date(Number(value));\n\n if (typeof value === 'number')\n return new Date(value * 1000);\n\n if (typeof value === 'string' && this.type === \"date\") {\n const [year, month, day] = value.split('-').map(Number);\n return new Date(year, month - 1, day);\n }\n\n if (typeof value === 'string' && this.type === \"time\")\n return new Date(`1970-01-01T${value}Z`);\n\n if (typeof value === 'string' && /^\\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d(\\.\\d+)?$/.test(value))\n return new Date(value.replace(\" \", \"T\") + \"Z\");\n\n return new Date(value as string | Date);\n }\n\n set(value: unknown) {\n const iso = super.set(value);\n\n if (iso === undefined)\n return iso;\n\n const date = new Date(iso);\n\n if (this.type === \"ms\")\n return date.getTime();\n\n if (this.type === \"integer\" || this.type === \"seconds\")\n return Math.floor(date.getTime() / 1000);\n\n if (this.type === \"date\")\n return date.toISOString().slice(0, 10);\n\n if (this.type === \"time\")\n return date.toISOString().slice(11, 19);\n\n return iso;\n }\n}\n\ndate.Type = TimeColumn;\n"],"mappings":";;;;;;;;AAkDA,IAAa,aAAb,cAAgC,KAAK,KAAK;;;cAClB;;CAEtB,IAAI,WAAW;EACb,MAAM,EAAE,SAAS;AAEjB,SAAO,SAAS,OAAO,WAAW,SAAS,YAAY,YAAY,MAAM;;CAG3E,IAAI,OAAgB;AAClB,MAAI,SAAS,KACX,QAAO;AAET,MAAI,KAAK,SAAS,KAChB,QAAO,IAAI,KAAK,OAAO,MAAM,CAAC;AAEhC,MAAI,OAAO,UAAU,SACnB,wBAAO,IAAI,KAAK,QAAQ,IAAK;AAE/B,MAAI,OAAO,UAAU,YAAY,KAAK,SAAS,QAAQ;GACrD,MAAM,CAAC,MAAM,OAAO,OAAO,MAAM,MAAM,IAAI,CAAC,IAA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