@devbro/neko-sql 0.1.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.
Files changed (96) hide show
  1. package/README.md +30 -0
  2. package/dist/Blueprint.d.mts +39 -0
  3. package/dist/Blueprint.d.ts +39 -0
  4. package/dist/Blueprint.js +127 -0
  5. package/dist/Blueprint.js.map +1 -0
  6. package/dist/Blueprint.mjs +102 -0
  7. package/dist/Blueprint.mjs.map +1 -0
  8. package/dist/Connection-DBxWn3YO.d.ts +101 -0
  9. package/dist/Connection-Z5qLWvdu.d.mts +101 -0
  10. package/dist/Connection.d.mts +4 -0
  11. package/dist/Connection.d.ts +4 -0
  12. package/dist/Connection.js +30 -0
  13. package/dist/Connection.js.map +1 -0
  14. package/dist/Connection.mjs +6 -0
  15. package/dist/Connection.mjs.map +1 -0
  16. package/dist/Expression.d.mts +1 -0
  17. package/dist/Expression.d.ts +1 -0
  18. package/dist/Expression.js +37 -0
  19. package/dist/Expression.js.map +1 -0
  20. package/dist/Expression.mjs +13 -0
  21. package/dist/Expression.mjs.map +1 -0
  22. package/dist/Migration.d.mts +11 -0
  23. package/dist/Migration.d.ts +11 -0
  24. package/dist/Migration.js +30 -0
  25. package/dist/Migration.js.map +1 -0
  26. package/dist/Migration.mjs +6 -0
  27. package/dist/Migration.mjs.map +1 -0
  28. package/dist/Query.d.mts +4 -0
  29. package/dist/Query.d.ts +4 -0
  30. package/dist/Query.js +163 -0
  31. package/dist/Query.js.map +1 -0
  32. package/dist/Query.mjs +139 -0
  33. package/dist/Query.mjs.map +1 -0
  34. package/dist/QueryGrammar.d.mts +4 -0
  35. package/dist/QueryGrammar.d.ts +4 -0
  36. package/dist/QueryGrammar.js +241 -0
  37. package/dist/QueryGrammar.js.map +1 -0
  38. package/dist/QueryGrammar.mjs +217 -0
  39. package/dist/QueryGrammar.mjs.map +1 -0
  40. package/dist/Schema.d.mts +4 -0
  41. package/dist/Schema.d.ts +4 -0
  42. package/dist/Schema.js +62 -0
  43. package/dist/Schema.js.map +1 -0
  44. package/dist/Schema.mjs +38 -0
  45. package/dist/Schema.mjs.map +1 -0
  46. package/dist/SchemaGrammar.d.mts +17 -0
  47. package/dist/SchemaGrammar.d.ts +17 -0
  48. package/dist/SchemaGrammar.js +138 -0
  49. package/dist/SchemaGrammar.js.map +1 -0
  50. package/dist/SchemaGrammar.mjs +114 -0
  51. package/dist/SchemaGrammar.mjs.map +1 -0
  52. package/dist/databases/index.d.mts +8 -0
  53. package/dist/databases/index.d.ts +8 -0
  54. package/dist/databases/index.js +23 -0
  55. package/dist/databases/index.js.map +1 -0
  56. package/dist/databases/index.mjs +2 -0
  57. package/dist/databases/index.mjs.map +1 -0
  58. package/dist/databases/postgresql/PostgresqlConnection.d.mts +24 -0
  59. package/dist/databases/postgresql/PostgresqlConnection.d.ts +24 -0
  60. package/dist/databases/postgresql/PostgresqlConnection.js +108 -0
  61. package/dist/databases/postgresql/PostgresqlConnection.js.map +1 -0
  62. package/dist/databases/postgresql/PostgresqlConnection.mjs +74 -0
  63. package/dist/databases/postgresql/PostgresqlConnection.mjs.map +1 -0
  64. package/dist/databases/postgresql/PostgresqlQueryGrammar.d.mts +20 -0
  65. package/dist/databases/postgresql/PostgresqlQueryGrammar.d.ts +20 -0
  66. package/dist/databases/postgresql/PostgresqlQueryGrammar.js +65 -0
  67. package/dist/databases/postgresql/PostgresqlQueryGrammar.js.map +1 -0
  68. package/dist/databases/postgresql/PostgresqlQueryGrammar.mjs +41 -0
  69. package/dist/databases/postgresql/PostgresqlQueryGrammar.mjs.map +1 -0
  70. package/dist/databases/postgresql/PostgresqlSchemaGrammar.d.mts +8 -0
  71. package/dist/databases/postgresql/PostgresqlSchemaGrammar.d.ts +8 -0
  72. package/dist/databases/postgresql/PostgresqlSchemaGrammar.js +31 -0
  73. package/dist/databases/postgresql/PostgresqlSchemaGrammar.js.map +1 -0
  74. package/dist/databases/postgresql/PostgresqlSchemaGrammar.mjs +7 -0
  75. package/dist/databases/postgresql/PostgresqlSchemaGrammar.mjs.map +1 -0
  76. package/dist/databases/postgresql/index.d.mts +8 -0
  77. package/dist/databases/postgresql/index.d.ts +8 -0
  78. package/dist/databases/postgresql/index.js +27 -0
  79. package/dist/databases/postgresql/index.js.map +1 -0
  80. package/dist/databases/postgresql/index.mjs +4 -0
  81. package/dist/databases/postgresql/index.mjs.map +1 -0
  82. package/dist/index.d.mts +9 -0
  83. package/dist/index.d.ts +9 -0
  84. package/dist/index.js +37 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/index.mjs +9 -0
  87. package/dist/index.mjs.map +1 -0
  88. package/dist/types-C_aDrXJN.d.mts +48 -0
  89. package/dist/types-C_aDrXJN.d.ts +48 -0
  90. package/dist/types.d.mts +1 -0
  91. package/dist/types.d.ts +1 -0
  92. package/dist/types.js +17 -0
  93. package/dist/types.js.map +1 -0
  94. package/dist/types.mjs +1 -0
  95. package/dist/types.mjs.map +1 -0
  96. package/package.json +70 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Expression.ts"],"sourcesContent":["import { CompiledSql } from './types';\n\nexport class Expression {\n constructor(\n private sql = '',\n private bindings = []\n ) {}\n\n toCompiledSql(): CompiledSql {\n return { sql: this.sql, bindings: this.bindings };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,WAAW;AAAA,EACtB,YACU,MAAM,IACN,WAAW,CAAC,GACpB;AAFQ;AACA;AAAA,EACP;AAAA,EAEH,gBAA6B;AAC3B,WAAO,EAAE,KAAK,KAAK,KAAK,UAAU,KAAK,SAAS;AAAA,EAClD;AACF;","names":[]}
@@ -0,0 +1,13 @@
1
+ class Expression {
2
+ constructor(sql = "", bindings = []) {
3
+ this.sql = sql;
4
+ this.bindings = bindings;
5
+ }
6
+ toCompiledSql() {
7
+ return { sql: this.sql, bindings: this.bindings };
8
+ }
9
+ }
10
+ export {
11
+ Expression
12
+ };
13
+ //# sourceMappingURL=Expression.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Expression.ts"],"sourcesContent":["import { CompiledSql } from './types';\n\nexport class Expression {\n constructor(\n private sql = '',\n private bindings = []\n ) {}\n\n toCompiledSql(): CompiledSql {\n return { sql: this.sql, bindings: this.bindings };\n }\n}\n"],"mappings":"AAEO,MAAM,WAAW;AAAA,EACtB,YACU,MAAM,IACN,WAAW,CAAC,GACpB;AAFQ;AACA;AAAA,EACP;AAAA,EAEH,gBAA6B;AAC3B,WAAO,EAAE,KAAK,KAAK,KAAK,UAAU,KAAK,SAAS;AAAA,EAClD;AACF;","names":[]}
@@ -0,0 +1,11 @@
1
+ import { S as Schema } from './Connection-Z5qLWvdu.mjs';
2
+ import './Blueprint.mjs';
3
+ import './types-C_aDrXJN.mjs';
4
+ import './SchemaGrammar.mjs';
5
+
6
+ declare abstract class Migration {
7
+ abstract up(schema: Schema): Promise<void>;
8
+ abstract down(schema: Schema): Promise<void>;
9
+ }
10
+
11
+ export { Migration };
@@ -0,0 +1,11 @@
1
+ import { S as Schema } from './Connection-DBxWn3YO.js';
2
+ import './Blueprint.js';
3
+ import './types-C_aDrXJN.js';
4
+ import './SchemaGrammar.js';
5
+
6
+ declare abstract class Migration {
7
+ abstract up(schema: Schema): Promise<void>;
8
+ abstract down(schema: Schema): Promise<void>;
9
+ }
10
+
11
+ export { Migration };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Migration_exports = {};
20
+ __export(Migration_exports, {
21
+ Migration: () => Migration
22
+ });
23
+ module.exports = __toCommonJS(Migration_exports);
24
+ class Migration {
25
+ }
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ Migration
29
+ });
30
+ //# sourceMappingURL=Migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Migration.ts"],"sourcesContent":["import { Schema } from './Schema';\n\nexport abstract class Migration {\n abstract up(schema: Schema): Promise<void>;\n abstract down(schema: Schema): Promise<void>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAe,UAAU;AAGhC;","names":[]}
@@ -0,0 +1,6 @@
1
+ class Migration {
2
+ }
3
+ export {
4
+ Migration
5
+ };
6
+ //# sourceMappingURL=Migration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Migration.ts"],"sourcesContent":["import { Schema } from './Schema';\n\nexport abstract class Migration {\n abstract up(schema: Schema): Promise<void>;\n abstract down(schema: Schema): Promise<void>;\n}\n"],"mappings":"AAEO,MAAe,UAAU;AAGhC;","names":[]}
@@ -0,0 +1,4 @@
1
+ export { a as Query, Q as QueryParts } from './Connection-Z5qLWvdu.mjs';
2
+ import './types-C_aDrXJN.mjs';
3
+ import './Blueprint.mjs';
4
+ import './SchemaGrammar.mjs';
@@ -0,0 +1,4 @@
1
+ export { a as Query, Q as QueryParts } from './Connection-DBxWn3YO.js';
2
+ import './types-C_aDrXJN.js';
3
+ import './Blueprint.js';
4
+ import './SchemaGrammar.js';
package/dist/Query.js ADDED
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Query_exports = {};
20
+ __export(Query_exports, {
21
+ Query: () => Query
22
+ });
23
+ module.exports = __toCommonJS(Query_exports);
24
+ class Query {
25
+ constructor(connection, grammar) {
26
+ this.connection = connection;
27
+ this.grammar = grammar;
28
+ }
29
+ allowedOperations = ["=", ">", "<", "!=", "like", "ilike"];
30
+ parts = {
31
+ select: ["*"],
32
+ table: "",
33
+ join: [],
34
+ where: [],
35
+ groupBy: [],
36
+ having: [],
37
+ orderBy: [],
38
+ limit: null,
39
+ offset: null
40
+ };
41
+ table(tableName) {
42
+ this.parts.table = tableName;
43
+ return this;
44
+ }
45
+ whereOp(column, operation, value, joinCondition = "and", negateCondition = false) {
46
+ this.parts.where.push({
47
+ type: "operation",
48
+ column,
49
+ operation,
50
+ value,
51
+ joinCondition,
52
+ negateCondition
53
+ });
54
+ return this;
55
+ }
56
+ whereColumn(column1, operation, column2, joinCondition = "and", negateCondition = false) {
57
+ this.parts.where.push({
58
+ type: "operationColumn",
59
+ column1,
60
+ operation,
61
+ column2,
62
+ joinCondition,
63
+ negateCondition
64
+ });
65
+ return this;
66
+ }
67
+ whereNull(column, joinCondition = "and", negateCondition = false) {
68
+ this.parts.where.push({ type: "null", column, joinCondition, negateCondition });
69
+ return this;
70
+ }
71
+ clearWhere() {
72
+ this.parts.where = [];
73
+ return this;
74
+ }
75
+ select(selects) {
76
+ this.parts.select = [...selects];
77
+ return this;
78
+ }
79
+ groupBy(columns) {
80
+ this.parts.groupBy = [...columns];
81
+ return this;
82
+ }
83
+ havingOp(column, operation, value, joinCondition = "and", negateCondition = false) {
84
+ this.parts.having.push({
85
+ type: "operation",
86
+ column,
87
+ operation,
88
+ value,
89
+ joinCondition,
90
+ negateCondition
91
+ });
92
+ return this;
93
+ }
94
+ havingRaw(sql, bindings, joinCondition = "and", negateCondition = false) {
95
+ this.parts.having.push({ type: "raw", sql, bindings, joinCondition, negateCondition });
96
+ return this;
97
+ }
98
+ orderBy(column, direction = "asc") {
99
+ this.parts.orderBy.push(`${column} ${direction}`);
100
+ return this;
101
+ }
102
+ limit(limit) {
103
+ this.parts.limit = limit;
104
+ return this;
105
+ }
106
+ offset(offset) {
107
+ this.parts.offset = offset;
108
+ return this;
109
+ }
110
+ toSql() {
111
+ return this.grammar.toSql(this);
112
+ }
113
+ async get() {
114
+ return await this.connection?.runQuery(this.toSql());
115
+ }
116
+ async getCursor() {
117
+ return await this.connection?.runCursor(this.toSql());
118
+ }
119
+ getConnection() {
120
+ return this.connection;
121
+ }
122
+ async insert(data) {
123
+ const csql = this.grammar.compileInsert(this, data);
124
+ return await this.connection?.runQuery(csql);
125
+ }
126
+ async insertGetId(data, options = { primaryKey: ["id"] }) {
127
+ const csql = this.grammar.compileInsertGetId(this, data, options);
128
+ return await this.connection?.runQuery(csql);
129
+ }
130
+ async update(data) {
131
+ const csql = this.grammar.compileUpdate(this, data);
132
+ return await this.connection?.runQuery(csql);
133
+ }
134
+ async upsert(data, uniqueColumns, updateColumns) {
135
+ const csql = this.grammar.compileUpsert(this, data, uniqueColumns, updateColumns);
136
+ return await this.connection?.runQuery(csql);
137
+ }
138
+ async delete() {
139
+ const csql = this.grammar.compileDelete(this);
140
+ return await this.connection?.runQuery(csql);
141
+ }
142
+ innerJoin(table, condtions) {
143
+ this.parts.join.push({ type: "inner", table, conditions: condtions });
144
+ return this;
145
+ }
146
+ leftJoin(table, condtions) {
147
+ this.parts.join.push({ type: "left", table, conditions: condtions });
148
+ return this;
149
+ }
150
+ rightJoin(table, condtions) {
151
+ this.parts.join.push({ type: "right", table, conditions: condtions });
152
+ return this;
153
+ }
154
+ fullJoin(table, condtions) {
155
+ this.parts.join.push({ type: "full", table, conditions: condtions });
156
+ return this;
157
+ }
158
+ }
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ Query
162
+ });
163
+ //# sourceMappingURL=Query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Query.ts"],"sourcesContent":["import { Connection } from './Connection';\nimport { QueryGrammar } from './QueryGrammar';\nimport { CompiledSql, JoinCondition, Parameter, selectType, whereType, havingType, joinType } from './types';\n\nexport type QueryParts = {\n select: selectType[];\n table: string;\n join: joinType[];\n where: whereType[];\n groupBy: string[];\n having: havingType[];\n orderBy: string[];\n limit: number | null;\n offset: number | null;\n};\n\nexport class Query {\n allowedOperations: string[] = ['=', '>', '<', '!=', 'like', 'ilike'];\n parts: QueryParts = {\n select: ['*'],\n table: '',\n join: [],\n where: [],\n groupBy: [],\n having: [],\n orderBy: [],\n limit: null,\n offset: null,\n };\n\n constructor(\n private readonly connection: Connection | null,\n private readonly grammar: QueryGrammar\n ) {}\n\n table(tableName: string): this {\n this.parts.table = tableName;\n return this;\n }\n\n whereOp(\n column: string,\n operation: (typeof this.allowedOperations)[number],\n value: Parameter,\n joinCondition: JoinCondition = 'and',\n negateCondition: boolean = false\n ): this {\n this.parts.where.push({\n type: 'operation',\n column,\n operation,\n value,\n joinCondition,\n negateCondition,\n });\n return this;\n }\n\n whereColumn(column1: string, operation: (typeof this.allowedOperations)[number], column2: string, joinCondition: JoinCondition = 'and', negateCondition: boolean = false): this {\n this.parts.where.push({\n type: 'operationColumn',\n column1,\n operation,\n column2,\n joinCondition,\n negateCondition,\n });\n return this;\n }\n\n whereNull(\n column: string,\n joinCondition: JoinCondition = 'and',\n negateCondition: boolean = false\n ): this {\n this.parts.where.push({ type: 'null', column, joinCondition, negateCondition });\n return this;\n }\n\n clearWhere(): this {\n this.parts.where = [];\n return this;\n }\n\n select(selects: selectType[]): this {\n this.parts.select = [...selects];\n return this;\n }\n\n groupBy(columns: string[]): this {\n this.parts.groupBy = [...columns];\n return this;\n }\n\n havingOp(\n column: string,\n operation: (typeof this.allowedOperations)[number],\n value: Parameter,\n joinCondition: JoinCondition = 'and',\n negateCondition: boolean = false\n ): this {\n this.parts.having.push({\n type: 'operation',\n column,\n operation,\n value,\n joinCondition,\n negateCondition,\n });\n return this;\n }\n\n havingRaw(\n sql: string,\n bindings: Parameter[],\n joinCondition: JoinCondition = 'and',\n negateCondition: boolean = false\n ): this {\n this.parts.having.push({ type: 'raw', sql, bindings, joinCondition, negateCondition });\n return this;\n }\n\n orderBy(column: string, direction: 'asc' | 'desc' = 'asc'): this {\n this.parts.orderBy.push(`${column} ${direction}`);\n return this;\n }\n\n limit(limit: number): this {\n this.parts.limit = limit;\n return this;\n }\n\n offset(offset: number): this {\n this.parts.offset = offset;\n return this;\n }\n\n toSql(): CompiledSql {\n return this.grammar.toSql(this);\n }\n\n async get() {\n return await this.connection?.runQuery(this.toSql());\n }\n\n async getCursor() {\n return await this.connection?.runCursor(this.toSql());\n }\n\n getConnection(): Connection | null {\n return this.connection;\n }\n\n async insert(data: Record<string, Parameter>) {\n const csql: CompiledSql = this.grammar.compileInsert(this, data);\n return await this.connection?.runQuery(csql);\n }\n\n async insertGetId(\n data: Record<string, Parameter>,\n options: { primaryKey: string[] } = { primaryKey: ['id'] }\n ) {\n const csql: CompiledSql = this.grammar.compileInsertGetId(this, data, options);\n return await this.connection?.runQuery(csql);\n }\n\n async update(data: Record<string, Parameter>) {\n const csql: CompiledSql = this.grammar.compileUpdate(this, data);\n return await this.connection?.runQuery(csql);\n }\n\n async upsert(data: Record<string, Parameter>, uniqueColumns: string[], updateColumns: string[]) {\n const csql: CompiledSql = this.grammar.compileUpsert(this, data, uniqueColumns, updateColumns);\n return await this.connection?.runQuery(csql);\n }\n\n async delete() {\n const csql: CompiledSql = this.grammar.compileDelete(this);\n return await this.connection?.runQuery(csql);\n }\n\n innerJoin(table: string, condtions: whereType[]): this {\n this.parts.join.push({ type: 'inner', table, conditions: condtions });\n return this;\n }\n\n leftJoin(table: string, condtions: whereType[]): this {\n this.parts.join.push({ type: 'left', table, conditions: condtions });\n return this;\n }\n\n rightJoin(table: string, condtions: whereType[]): this {\n this.parts.join.push({ type: 'right', table, conditions: condtions });\n return this;\n }\n\n fullJoin(table: string, condtions: whereType[]): this {\n this.parts.join.push({ type: 'full', table, conditions: condtions });\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,MAAM,MAAM;AAAA,EAcjB,YACmB,YACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAhBH,oBAA8B,CAAC,KAAK,KAAK,KAAK,MAAM,QAAQ,OAAO;AAAA,EACnE,QAAoB;AAAA,IAClB,QAAQ,CAAC,GAAG;AAAA,IACZ,OAAO;AAAA,IACP,MAAM,CAAC;AAAA,IACP,OAAO,CAAC;AAAA,IACR,SAAS,CAAC;AAAA,IACV,QAAQ,CAAC;AAAA,IACT,SAAS,CAAC;AAAA,IACV,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA,EAOA,MAAM,WAAyB;AAC7B,SAAK,MAAM,QAAQ;AACnB,WAAO;AAAA,EACT;AAAA,EAEA,QACE,QACA,WACA,OACA,gBAA+B,OAC/B,kBAA2B,OACrB;AACN,SAAK,MAAM,MAAM,KAAK;AAAA,MACpB,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,SAAiB,WAAoD,SAAiB,gBAA+B,OAAO,kBAA2B,OAAa;AAC9K,SAAK,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AAAA,EACT;AAAA,EAEA,UAAU,OAAe,WAA8B;AACrD,SAAK,MAAM,KAAK,KAAK,EAAE,MAAM,SAAS,OAAO,YAAY,UAAU,CAAC;AACpE,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,OAAe,WAA8B;AACpD,SAAK,MAAM,KAAK,KAAK,EAAE,MAAM,QAAQ,OAAO,YAAY,UAAU,CAAC;AACnE,WAAO;AAAA,EACT;AACF;","names":[]}
package/dist/Query.mjs ADDED
@@ -0,0 +1,139 @@
1
+ class Query {
2
+ constructor(connection, grammar) {
3
+ this.connection = connection;
4
+ this.grammar = grammar;
5
+ }
6
+ allowedOperations = ["=", ">", "<", "!=", "like", "ilike"];
7
+ parts = {
8
+ select: ["*"],
9
+ table: "",
10
+ join: [],
11
+ where: [],
12
+ groupBy: [],
13
+ having: [],
14
+ orderBy: [],
15
+ limit: null,
16
+ offset: null
17
+ };
18
+ table(tableName) {
19
+ this.parts.table = tableName;
20
+ return this;
21
+ }
22
+ whereOp(column, operation, value, joinCondition = "and", negateCondition = false) {
23
+ this.parts.where.push({
24
+ type: "operation",
25
+ column,
26
+ operation,
27
+ value,
28
+ joinCondition,
29
+ negateCondition
30
+ });
31
+ return this;
32
+ }
33
+ whereColumn(column1, operation, column2, joinCondition = "and", negateCondition = false) {
34
+ this.parts.where.push({
35
+ type: "operationColumn",
36
+ column1,
37
+ operation,
38
+ column2,
39
+ joinCondition,
40
+ negateCondition
41
+ });
42
+ return this;
43
+ }
44
+ whereNull(column, joinCondition = "and", negateCondition = false) {
45
+ this.parts.where.push({ type: "null", column, joinCondition, negateCondition });
46
+ return this;
47
+ }
48
+ clearWhere() {
49
+ this.parts.where = [];
50
+ return this;
51
+ }
52
+ select(selects) {
53
+ this.parts.select = [...selects];
54
+ return this;
55
+ }
56
+ groupBy(columns) {
57
+ this.parts.groupBy = [...columns];
58
+ return this;
59
+ }
60
+ havingOp(column, operation, value, joinCondition = "and", negateCondition = false) {
61
+ this.parts.having.push({
62
+ type: "operation",
63
+ column,
64
+ operation,
65
+ value,
66
+ joinCondition,
67
+ negateCondition
68
+ });
69
+ return this;
70
+ }
71
+ havingRaw(sql, bindings, joinCondition = "and", negateCondition = false) {
72
+ this.parts.having.push({ type: "raw", sql, bindings, joinCondition, negateCondition });
73
+ return this;
74
+ }
75
+ orderBy(column, direction = "asc") {
76
+ this.parts.orderBy.push(`${column} ${direction}`);
77
+ return this;
78
+ }
79
+ limit(limit) {
80
+ this.parts.limit = limit;
81
+ return this;
82
+ }
83
+ offset(offset) {
84
+ this.parts.offset = offset;
85
+ return this;
86
+ }
87
+ toSql() {
88
+ return this.grammar.toSql(this);
89
+ }
90
+ async get() {
91
+ return await this.connection?.runQuery(this.toSql());
92
+ }
93
+ async getCursor() {
94
+ return await this.connection?.runCursor(this.toSql());
95
+ }
96
+ getConnection() {
97
+ return this.connection;
98
+ }
99
+ async insert(data) {
100
+ const csql = this.grammar.compileInsert(this, data);
101
+ return await this.connection?.runQuery(csql);
102
+ }
103
+ async insertGetId(data, options = { primaryKey: ["id"] }) {
104
+ const csql = this.grammar.compileInsertGetId(this, data, options);
105
+ return await this.connection?.runQuery(csql);
106
+ }
107
+ async update(data) {
108
+ const csql = this.grammar.compileUpdate(this, data);
109
+ return await this.connection?.runQuery(csql);
110
+ }
111
+ async upsert(data, uniqueColumns, updateColumns) {
112
+ const csql = this.grammar.compileUpsert(this, data, uniqueColumns, updateColumns);
113
+ return await this.connection?.runQuery(csql);
114
+ }
115
+ async delete() {
116
+ const csql = this.grammar.compileDelete(this);
117
+ return await this.connection?.runQuery(csql);
118
+ }
119
+ innerJoin(table, condtions) {
120
+ this.parts.join.push({ type: "inner", table, conditions: condtions });
121
+ return this;
122
+ }
123
+ leftJoin(table, condtions) {
124
+ this.parts.join.push({ type: "left", table, conditions: condtions });
125
+ return this;
126
+ }
127
+ rightJoin(table, condtions) {
128
+ this.parts.join.push({ type: "right", table, conditions: condtions });
129
+ return this;
130
+ }
131
+ fullJoin(table, condtions) {
132
+ this.parts.join.push({ type: "full", table, conditions: condtions });
133
+ return this;
134
+ }
135
+ }
136
+ export {
137
+ Query
138
+ };
139
+ //# sourceMappingURL=Query.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Query.ts"],"sourcesContent":["import { Connection } from './Connection';\nimport { QueryGrammar } from './QueryGrammar';\nimport { CompiledSql, JoinCondition, Parameter, selectType, whereType, havingType, joinType } from './types';\n\nexport type QueryParts = {\n select: selectType[];\n table: string;\n join: joinType[];\n where: whereType[];\n groupBy: string[];\n having: havingType[];\n orderBy: string[];\n limit: number | null;\n offset: number | null;\n};\n\nexport class Query {\n allowedOperations: string[] = ['=', '>', '<', '!=', 'like', 'ilike'];\n parts: QueryParts = {\n select: ['*'],\n table: '',\n join: [],\n where: [],\n groupBy: [],\n having: [],\n orderBy: [],\n limit: null,\n offset: null,\n };\n\n constructor(\n private readonly connection: Connection | null,\n private readonly grammar: QueryGrammar\n ) {}\n\n table(tableName: string): this {\n this.parts.table = tableName;\n return this;\n }\n\n whereOp(\n column: string,\n operation: (typeof this.allowedOperations)[number],\n value: Parameter,\n joinCondition: JoinCondition = 'and',\n negateCondition: boolean = false\n ): this {\n this.parts.where.push({\n type: 'operation',\n column,\n operation,\n value,\n joinCondition,\n negateCondition,\n });\n return this;\n }\n\n whereColumn(column1: string, operation: (typeof this.allowedOperations)[number], column2: string, joinCondition: JoinCondition = 'and', negateCondition: boolean = false): this {\n this.parts.where.push({\n type: 'operationColumn',\n column1,\n operation,\n column2,\n joinCondition,\n negateCondition,\n });\n return this;\n }\n\n whereNull(\n column: string,\n joinCondition: JoinCondition = 'and',\n negateCondition: boolean = false\n ): this {\n this.parts.where.push({ type: 'null', column, joinCondition, negateCondition });\n return this;\n }\n\n clearWhere(): this {\n this.parts.where = [];\n return this;\n }\n\n select(selects: selectType[]): this {\n this.parts.select = [...selects];\n return this;\n }\n\n groupBy(columns: string[]): this {\n this.parts.groupBy = [...columns];\n return this;\n }\n\n havingOp(\n column: string,\n operation: (typeof this.allowedOperations)[number],\n value: Parameter,\n joinCondition: JoinCondition = 'and',\n negateCondition: boolean = false\n ): this {\n this.parts.having.push({\n type: 'operation',\n column,\n operation,\n value,\n joinCondition,\n negateCondition,\n });\n return this;\n }\n\n havingRaw(\n sql: string,\n bindings: Parameter[],\n joinCondition: JoinCondition = 'and',\n negateCondition: boolean = false\n ): this {\n this.parts.having.push({ type: 'raw', sql, bindings, joinCondition, negateCondition });\n return this;\n }\n\n orderBy(column: string, direction: 'asc' | 'desc' = 'asc'): this {\n this.parts.orderBy.push(`${column} ${direction}`);\n return this;\n }\n\n limit(limit: number): this {\n this.parts.limit = limit;\n return this;\n }\n\n offset(offset: number): this {\n this.parts.offset = offset;\n return this;\n }\n\n toSql(): CompiledSql {\n return this.grammar.toSql(this);\n }\n\n async get() {\n return await this.connection?.runQuery(this.toSql());\n }\n\n async getCursor() {\n return await this.connection?.runCursor(this.toSql());\n }\n\n getConnection(): Connection | null {\n return this.connection;\n }\n\n async insert(data: Record<string, Parameter>) {\n const csql: CompiledSql = this.grammar.compileInsert(this, data);\n return await this.connection?.runQuery(csql);\n }\n\n async insertGetId(\n data: Record<string, Parameter>,\n options: { primaryKey: string[] } = { primaryKey: ['id'] }\n ) {\n const csql: CompiledSql = this.grammar.compileInsertGetId(this, data, options);\n return await this.connection?.runQuery(csql);\n }\n\n async update(data: Record<string, Parameter>) {\n const csql: CompiledSql = this.grammar.compileUpdate(this, data);\n return await this.connection?.runQuery(csql);\n }\n\n async upsert(data: Record<string, Parameter>, uniqueColumns: string[], updateColumns: string[]) {\n const csql: CompiledSql = this.grammar.compileUpsert(this, data, uniqueColumns, updateColumns);\n return await this.connection?.runQuery(csql);\n }\n\n async delete() {\n const csql: CompiledSql = this.grammar.compileDelete(this);\n return await this.connection?.runQuery(csql);\n }\n\n innerJoin(table: string, condtions: whereType[]): this {\n this.parts.join.push({ type: 'inner', table, conditions: condtions });\n return this;\n }\n\n leftJoin(table: string, condtions: whereType[]): this {\n this.parts.join.push({ type: 'left', table, conditions: condtions });\n return this;\n }\n\n rightJoin(table: string, condtions: whereType[]): this {\n this.parts.join.push({ type: 'right', table, conditions: condtions });\n return this;\n }\n\n fullJoin(table: string, condtions: whereType[]): this {\n this.parts.join.push({ type: 'full', table, conditions: condtions });\n return this;\n }\n}\n"],"mappings":"AAgBO,MAAM,MAAM;AAAA,EAcjB,YACmB,YACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAhBH,oBAA8B,CAAC,KAAK,KAAK,KAAK,MAAM,QAAQ,OAAO;AAAA,EACnE,QAAoB;AAAA,IAClB,QAAQ,CAAC,GAAG;AAAA,IACZ,OAAO;AAAA,IACP,MAAM,CAAC;AAAA,IACP,OAAO,CAAC;AAAA,IACR,SAAS,CAAC;AAAA,IACV,QAAQ,CAAC;AAAA,IACT,SAAS,CAAC;AAAA,IACV,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA,EAOA,MAAM,WAAyB;AAC7B,SAAK,MAAM,QAAQ;AACnB,WAAO;AAAA,EACT;AAAA,EAEA,QACE,QACA,WACA,OACA,gBAA+B,OAC/B,kBAA2B,OACrB;AACN,SAAK,MAAM,MAAM,KAAK;AAAA,MACpB,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,SAAiB,WAAoD,SAAiB,gBAA+B,OAAO,kBAA2B,OAAa;AAC9K,SAAK,MAAM,MAAM,KAAK;AAAA,MACpB,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,UACE,QACA,gBAA+B,OAC/B,kBAA2B,OACrB;AACN,SAAK,MAAM,MAAM,KAAK,EAAE,MAAM,QAAQ,QAAQ,eAAe,gBAAgB,CAAC;AAC9E,WAAO;AAAA,EACT;AAAA,EAEA,aAAmB;A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 export { b as QueryGrammar } from './Connection-Z5qLWvdu.mjs';
2
+ import './types-C_aDrXJN.mjs';
3
+ import './Blueprint.mjs';
4
+ import './SchemaGrammar.mjs';
@@ -0,0 +1,4 @@
1
+ export { b as QueryGrammar } from './Connection-DBxWn3YO.js';
2
+ import './types-C_aDrXJN.js';
3
+ import './Blueprint.js';
4
+ import './SchemaGrammar.js';