sourcesql 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michal Přikryl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # SourceSQL
2
+
3
+ **C++ style SQL interface for Node.js
4
+ inspired by Source / Source2 development**
5
+
6
+ ------------------------------------------------------------------------
7
+
8
+ ## Overview
9
+
10
+ `SourceSQL` is a lightweight **OOP SQL abstraction layer** designed to
11
+ replicate the feel of **SourceMod / Source2 SQL APIs** in modern
12
+ JavaScript and TypeScript.
13
+
14
+ It provides a **virtual-like interface (`ISQL*`)** with familiar methods
15
+ such as:
16
+
17
+ - `Query`
18
+ - `GetResultSet`
19
+ - `FetchRow`
20
+ - `GetInt64`
21
+
22
+ The goal is to create a **low-level, predictable, and safe SQL layer**
23
+ that behaves similarly to C++ plugin environments.
24
+
25
+ ------------------------------------------------------------------------
26
+
27
+ ## Features
28
+
29
+ - C++-style API (`ISQLConnection`, `ISQLQuery`, `ISQLResult`, `ISQLRow`)
30
+ - Promise-based & callback-based queries
31
+ - MySQL driver (`mysql2`)
32
+ - Safe queries using prepared statements (`?`)
33
+ - `queryEx` helper (tuple `[result, error]`)
34
+ - Transaction support
35
+ - BigInt-safe (`GetInt64`)
36
+ - Multi-database support (`db.table`)
37
+ - Clean TypeScript typings
38
+ - Easily extensible (SQLite, Postgres, etc.)
39
+
40
+ ------------------------------------------------------------------------
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ npm install sourcesql mysql2
46
+ ```
47
+
48
+ ------------------------------------------------------------------------
49
+
50
+ ## Basic Usage
51
+
52
+ ```ts
53
+ import { MySQLConnection } from "sourcesql";
54
+
55
+ const db = new MySQLConnection({
56
+ host: "localhost",
57
+ user: "root",
58
+ password: ""
59
+ });
60
+
61
+ await db.Connect();
62
+
63
+ const query = await db.Query(
64
+ "SELECT id, name FROM test.users WHERE id = ?",
65
+ [1]
66
+ );
67
+
68
+ const result = query.GetResultSet();
69
+
70
+ while (result.MoreRows()) {
71
+ const row = result.FetchRow();
72
+
73
+ const id = row.GetInt("id");
74
+ const name = row.GetString("name");
75
+
76
+ console.log(id, name);
77
+ }
78
+
79
+ await db.Destroy();
80
+ ```
81
+
82
+ ------------------------------------------------------------------------
83
+
84
+ ## QueryEx (C++ style)
85
+
86
+ ```ts
87
+ import { queryEx } from "sourcesql";
88
+
89
+ const [query, err] = await queryEx(
90
+ db,
91
+ "SELECT * FROM test.users WHERE id = ?",
92
+ [1]
93
+ );
94
+
95
+ if (err) {
96
+ console.error(err);
97
+ } else {
98
+ const result = query.GetResultSet();
99
+ }
100
+ ```
101
+
102
+ ------------------------------------------------------------------------
103
+
104
+ ## Safe Queries (SQL Injection Protection)
105
+
106
+ ```ts
107
+ // SAFE
108
+ await db.Query(
109
+ "SELECT * FROM users WHERE name = ?",
110
+ [name]
111
+ );
112
+
113
+ // UNSAFE (NEVER DO THIS)
114
+ await db.Query(`SELECT * FROM users WHERE name = '${name}'`);
115
+ ```
116
+
117
+ ------------------------------------------------------------------------
118
+
119
+ ## Multi Database Queries
120
+
121
+ ```ts
122
+ await db.Query("SELECT * FROM test.users");
123
+ await db.Query("SELECT * FROM logs.sessions");
124
+ ```
125
+
126
+ Or safely:
127
+
128
+ ```ts
129
+ const table = db.EscapeTable("test", "users");
130
+ await db.Query(`SELECT * FROM ${table}`);
131
+ ```
132
+
133
+ ------------------------------------------------------------------------
134
+
135
+ ## Transactions
136
+
137
+ ```ts
138
+ await db.ExecuteTransaction(
139
+ [
140
+ "INSERT INTO test.users (name) VALUES ('A')",
141
+ "UPDATE test.users SET name='B' WHERE id=1"
142
+ ],
143
+ (results) => {
144
+ console.log("Transaction success:", results.length);
145
+ },
146
+ (error) => {
147
+ console.error("Transaction failed:", error);
148
+ }
149
+ );
150
+ ```
151
+
152
+ ------------------------------------------------------------------------
153
+
154
+ ## API
155
+
156
+ ### ISQLConnection
157
+
158
+ ```ts
159
+ Connect(callback?: (success: boolean) => void): Promise<void>
160
+ Query(sql: string, params?: any[]): Promise<ISQLQuery>
161
+ QueryCallback(sql: string, callback: (query, err?) => void): void
162
+ ExecuteTransaction(...)
163
+ Destroy(): Promise<void>
164
+
165
+ Escape(value: any): string
166
+ EscapeId(value: string): string
167
+ EscapeTable(db: string, table: string): string
168
+ ```
169
+
170
+ ------------------------------------------------------------------------
171
+
172
+ ### ISQLQuery
173
+
174
+ ```ts
175
+ GetResultSet(): ISQLResult | null
176
+ GetInsertId(): number
177
+ GetAffectedRows(): number
178
+ GetType(): QueryType
179
+ ```
180
+
181
+ ------------------------------------------------------------------------
182
+
183
+ ### ISQLResult
184
+
185
+ ```ts
186
+ GetRowCount(): number
187
+ GetFieldCount(): number
188
+
189
+ FieldNameToNum(name: string): number | null
190
+ FieldNumToName(index: number): string | null
191
+
192
+ MoreRows(): boolean
193
+ FetchRow(): ISQLRow | null
194
+ CurrentRow(): ISQLRow | null
195
+
196
+ Rewind(): void
197
+ ```
198
+
199
+ ------------------------------------------------------------------------
200
+
201
+ ### ISQLRow
202
+
203
+ ```ts
204
+ GetString(field: string | number): string | null
205
+ GetInt(field: string | number): number
206
+ GetFloat(field: string | number): number
207
+ GetInt64(field: string | number): string
208
+ IsNull(field: string | number): boolean
209
+ ```
210
+
211
+ ------------------------------------------------------------------------
212
+
213
+ ## Query Types
214
+
215
+ ```ts
216
+ import { QueryType } from "sourcesql";
217
+
218
+ switch (query.GetType()) {
219
+ case QueryType.SELECT:
220
+ break;
221
+ case QueryType.INSERT:
222
+ console.log(query.GetInsertId());
223
+ break;
224
+ case QueryType.UPDATE:
225
+ case QueryType.DELETE:
226
+ console.log(query.GetAffectedRows());
227
+ break;
228
+ }
229
+ ```
230
+
231
+ ------------------------------------------------------------------------
232
+
233
+ ## Example (Field Index)
234
+
235
+ ```ts
236
+ const col = result.FieldNameToNum("name");
237
+
238
+ while (result.MoreRows()) {
239
+ const row = result.FetchRow();
240
+ console.log(row.GetString(col));
241
+ }
242
+ ```
243
+
244
+ ------------------------------------------------------------------------
245
+
246
+ ## Notes
247
+
248
+ - Always use **string for BIGINT values** (SteamID, Discord IDs)
249
+ - Use `?` placeholders to prevent SQL injection
250
+ - Do not escape values manually — use prepared params
251
+ - Tables/columns must use `EscapeId`
252
+
253
+ ------------------------------------------------------------------------
254
+
255
+ ## Roadmap
256
+
257
+ - SQLite driver
258
+ - PostgreSQL driver
259
+ - Prepared statements cache
260
+ - Query formatter (`%d`, `%s`)
261
+ - Async queue (SourceMod style)
262
+ - Connection manager
263
+ - Typed queries
264
+
265
+ ------------------------------------------------------------------------
266
+
267
+ ## License
268
+
269
+ MIT
270
+
271
+ ------------------------------------------------------------------------
272
+
273
+ ## Author
274
+
275
+ **Michal "Slynx" Přikryl**
276
+ https://slynxdev.cz
@@ -0,0 +1,61 @@
1
+ import mysql from 'mysql2/promise';
2
+
3
+ interface ISQLRow {
4
+ GetString(field: string | number): string | null;
5
+ GetInt(field: string | number): number;
6
+ GetFloat(field: string | number): number;
7
+ GetInt64(field: string | number): string;
8
+ IsNull(field: string | number): boolean;
9
+ }
10
+
11
+ interface ISQLResult {
12
+ GetRowCount(): number;
13
+ GetFieldCount(): number;
14
+ FieldNameToNum(name: string): number | null;
15
+ FieldNumToName(index: number): string | null;
16
+ MoreRows(): boolean;
17
+ FetchRow(): ISQLRow | null;
18
+ CurrentRow(): ISQLRow | null;
19
+ Rewind(): void;
20
+ GetFieldType(field: number): number;
21
+ }
22
+
23
+ declare enum QueryType {
24
+ SELECT = 0,
25
+ INSERT = 1,
26
+ UPDATE = 2,
27
+ DELETE = 3,
28
+ OTHER = 4
29
+ }
30
+ interface ISQLQuery {
31
+ GetResultSet(): ISQLResult | null;
32
+ GetInsertId(): number;
33
+ GetAffectedRows(): number;
34
+ GetType(): QueryType;
35
+ }
36
+
37
+ interface ISQLConnection {
38
+ Query(sql: string, params?: any[]): Promise<ISQLQuery>;
39
+ Escape(value: any): string;
40
+ EscapeId(value: string): string;
41
+ }
42
+
43
+ declare class MySQLConnection implements ISQLConnection {
44
+ private config;
45
+ private pool;
46
+ private connected;
47
+ constructor(config: mysql.PoolOptions);
48
+ private BuildQueryResult;
49
+ Connect(callback?: (success: boolean) => void): Promise<void>;
50
+ Query(sql: string, params?: any[]): Promise<ISQLQuery>;
51
+ QueryCallback(sql: string, callback: (query: ISQLQuery | null, error?: any) => void, params?: any[]): void;
52
+ ExecuteTransaction(queries: string[], success: (queries: ISQLQuery[]) => void, failure: (error: string) => void): Promise<void>;
53
+ Destroy(): Promise<void>;
54
+ Escape(value: any): string;
55
+ EscapeId(value: string): string;
56
+ EscapeTable(database: string, table: string): string;
57
+ }
58
+
59
+ declare function QueryEx(conn: ISQLConnection, sql: string, params?: any[]): Promise<readonly [ISQLQuery | null, Error | null]>;
60
+
61
+ export { type ISQLConnection, type ISQLQuery, type ISQLResult, type ISQLRow, MySQLConnection, QueryEx, QueryType };
package/dist/index.js ADDED
@@ -0,0 +1,201 @@
1
+ // src/core/ISQLQuery.ts
2
+ var QueryType = /* @__PURE__ */ ((QueryType2) => {
3
+ QueryType2[QueryType2["SELECT"] = 0] = "SELECT";
4
+ QueryType2[QueryType2["INSERT"] = 1] = "INSERT";
5
+ QueryType2[QueryType2["UPDATE"] = 2] = "UPDATE";
6
+ QueryType2[QueryType2["DELETE"] = 3] = "DELETE";
7
+ QueryType2[QueryType2["OTHER"] = 4] = "OTHER";
8
+ return QueryType2;
9
+ })(QueryType || {});
10
+
11
+ // src/drivers/mysql/MySQLConnection.ts
12
+ import mysql from "mysql2/promise";
13
+
14
+ // src/drivers/mysql/MySQLRow.ts
15
+ var MySQLRow = class {
16
+ constructor(row, fields) {
17
+ this.row = row;
18
+ this.fields = fields;
19
+ }
20
+ resolve(field) {
21
+ if (typeof field === "number")
22
+ return this.row[this.fields[field]];
23
+ return this.row[field];
24
+ }
25
+ GetString(field) {
26
+ const val = this.resolve(field);
27
+ return val == null ? null : String(val);
28
+ }
29
+ GetInt(field) {
30
+ const val = this.resolve(field);
31
+ return val == null ? 0 : Number(val);
32
+ }
33
+ GetFloat(field) {
34
+ return this.GetInt(field);
35
+ }
36
+ GetInt64(field) {
37
+ const val = this.resolve(field);
38
+ return val == null ? "0" : String(val);
39
+ }
40
+ IsNull(field) {
41
+ return this.resolve(field) == null;
42
+ }
43
+ };
44
+
45
+ // src/drivers/mysql/MySQLResult.ts
46
+ var MySQLResult = class {
47
+ constructor(rows) {
48
+ this.rows = rows;
49
+ this.index = -1;
50
+ this.current = null;
51
+ this.fields = rows.length > 0 ? Object.keys(rows[0]) : [];
52
+ }
53
+ GetRowCount() {
54
+ return this.rows.length;
55
+ }
56
+ GetFieldCount() {
57
+ return this.fields.length;
58
+ }
59
+ FieldNameToNum(name) {
60
+ const idx = this.fields.indexOf(name);
61
+ return idx === -1 ? null : idx;
62
+ }
63
+ FieldNumToName(index) {
64
+ return this.fields[index] ?? null;
65
+ }
66
+ MoreRows() {
67
+ return this.index + 1 < this.rows.length;
68
+ }
69
+ FetchRow() {
70
+ if (!this.MoreRows()) return null;
71
+ this.index++;
72
+ this.current = new MySQLRow(this.rows[this.index], this.fields);
73
+ return this.current;
74
+ }
75
+ CurrentRow() {
76
+ return this.current;
77
+ }
78
+ Rewind() {
79
+ this.index = -1;
80
+ this.current = null;
81
+ }
82
+ GetFieldType(field) {
83
+ return 0;
84
+ }
85
+ };
86
+
87
+ // src/drivers/mysql/MySQLQuery.ts
88
+ var MySQLQuery = class {
89
+ constructor(rows, meta, sql) {
90
+ this.meta = meta;
91
+ this.sql = sql;
92
+ this.type = this.DetectType(sql);
93
+ if (rows && rows.length > 0) {
94
+ this.result = new MySQLResult(rows);
95
+ } else {
96
+ this.result = null;
97
+ }
98
+ }
99
+ DetectType(sql) {
100
+ const q = sql.trim().toLowerCase();
101
+ if (q.startsWith("select")) return 0 /* SELECT */;
102
+ if (q.startsWith("insert")) return 1 /* INSERT */;
103
+ if (q.startsWith("update")) return 2 /* UPDATE */;
104
+ if (q.startsWith("delete")) return 3 /* DELETE */;
105
+ return 4 /* OTHER */;
106
+ }
107
+ GetResultSet() {
108
+ return this.result;
109
+ }
110
+ GetInsertId() {
111
+ return this.meta?.insertId ?? 0;
112
+ }
113
+ GetAffectedRows() {
114
+ return this.meta?.affectedRows ?? 0;
115
+ }
116
+ GetType() {
117
+ return this.type;
118
+ }
119
+ };
120
+
121
+ // src/drivers/mysql/MySQLConnection.ts
122
+ var MySQLConnection = class {
123
+ constructor(config) {
124
+ this.config = config;
125
+ this.connected = false;
126
+ this.pool = mysql.createPool(config);
127
+ }
128
+ BuildQueryResult(rows, meta, sql) {
129
+ if (Array.isArray(rows)) {
130
+ return new MySQLQuery(rows, meta, sql);
131
+ }
132
+ return new MySQLQuery([], rows, sql);
133
+ }
134
+ async Connect(callback) {
135
+ try {
136
+ const conn = await this.pool.getConnection();
137
+ await conn.ping();
138
+ conn.release();
139
+ this.connected = true;
140
+ callback?.(true);
141
+ } catch (err) {
142
+ this.connected = false;
143
+ callback?.(false);
144
+ throw err;
145
+ }
146
+ }
147
+ async Query(sql, params) {
148
+ const [rows, meta] = await this.pool.query(sql, params);
149
+ return this.BuildQueryResult(rows, meta, sql);
150
+ }
151
+ QueryCallback(sql, callback, params) {
152
+ this.Query(sql, params).then((q) => callback(q)).catch((err) => callback(null, err));
153
+ }
154
+ async ExecuteTransaction(queries, success, failure) {
155
+ const conn = await this.pool.getConnection();
156
+ try {
157
+ await conn.beginTransaction();
158
+ const results = [];
159
+ for (const sql of queries) {
160
+ const [rows, meta] = await conn.query(sql);
161
+ results.push(this.BuildQueryResult(rows, meta, sql));
162
+ }
163
+ await conn.commit();
164
+ success(results);
165
+ } catch (err) {
166
+ await conn.rollback();
167
+ failure(err?.message ?? "Transaction failed");
168
+ } finally {
169
+ conn.release();
170
+ }
171
+ }
172
+ async Destroy() {
173
+ await this.pool.end();
174
+ this.connected = false;
175
+ }
176
+ Escape(value) {
177
+ return mysql.escape(value);
178
+ }
179
+ EscapeId(value) {
180
+ return mysql.escapeId(value);
181
+ }
182
+ EscapeTable(database, table) {
183
+ return `${this.EscapeId(database)}.${this.EscapeId(table)}`;
184
+ }
185
+ };
186
+
187
+ // src/utils/queryEx.ts
188
+ async function QueryEx(conn, sql, params) {
189
+ try {
190
+ const q = await conn.Query(sql, params);
191
+ return [q, null];
192
+ } catch (e) {
193
+ return [null, e instanceof Error ? e : new Error(String(e))];
194
+ }
195
+ }
196
+ export {
197
+ MySQLConnection,
198
+ QueryEx,
199
+ QueryType
200
+ };
201
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/ISQLQuery.ts","../src/drivers/mysql/MySQLConnection.ts","../src/drivers/mysql/MySQLRow.ts","../src/drivers/mysql/MySQLResult.ts","../src/drivers/mysql/MySQLQuery.ts","../src/utils/queryEx.ts"],"sourcesContent":["import { ISQLResult } from \"./ISQLResult\";\n\nexport enum QueryType {\n SELECT,\n INSERT,\n UPDATE,\n DELETE,\n OTHER\n}\n\nexport interface ISQLQuery {\n GetResultSet(): ISQLResult | null;\n GetInsertId(): number;\n GetAffectedRows(): number;\n\n GetType(): QueryType;\n}","import mysql from \"mysql2/promise\";\nimport { ISQLConnection } from \"@core/ISQLConnection\";\nimport { ISQLQuery } from \"@core/ISQLQuery\";\nimport { MySQLQuery } from \"@drivers/mysql/MySQLQuery\";\n\nexport class MySQLConnection implements ISQLConnection {\n private pool: mysql.Pool;\n private connected = false;\n\n constructor(private config: mysql.PoolOptions) {\n this.pool = mysql.createPool(config);\n }\n\n private BuildQueryResult(rows: any, meta: any, sql: string): ISQLQuery {\n if (Array.isArray(rows)) {\n return new MySQLQuery(rows, meta, sql);\n }\n\n return new MySQLQuery([], rows, sql);\n }\n\n async Connect(callback?: (success: boolean) => void): Promise<void> {\n try {\n // ping = test connection\n const conn = await this.pool.getConnection();\n await conn.ping();\n conn.release();\n\n this.connected = true;\n callback?.(true);\n } catch (err) {\n this.connected = false;\n callback?.(false);\n throw err;\n }\n }\n\n async Query(sql: string, params?: any[]): Promise<ISQLQuery> {\n const [rows, meta] = await this.pool.query<any>(sql, params);\n return this.BuildQueryResult(rows, meta, sql);\n }\n\n QueryCallback(\n sql: string,\n callback: (query: ISQLQuery | null, error?: any) => void,\n params?: any[]\n ) {\n this.Query(sql, params)\n .then(q => callback(q))\n .catch(err => callback(null, err));\n }\n\n async ExecuteTransaction(\n queries: string[],\n success: (queries: ISQLQuery[]) => void,\n failure: (error: string) => void\n ) {\n const conn = await this.pool.getConnection();\n\n try {\n await conn.beginTransaction();\n\n const results: ISQLQuery[] = [];\n\n for (const sql of queries) {\n const [rows, meta] = await conn.query<any>(sql);\n results.push(this.BuildQueryResult(rows, meta, sql));\n }\n\n await conn.commit();\n success(results);\n\n } catch (err: any) {\n await conn.rollback();\n failure(err?.message ?? \"Transaction failed\");\n\n } finally {\n conn.release();\n }\n }\n\n async Destroy(): Promise<void> {\n await this.pool.end();\n this.connected = false;\n }\n\n Escape(value: any): string {\n return mysql.escape(value);\n }\n\n EscapeId(value: string): string {\n return mysql.escapeId(value);\n }\n\n EscapeTable(database: string, table: string): string {\n return `${this.EscapeId(database)}.${this.EscapeId(table)}`;\n }\n}\n","import { ISQLRow } from \"@core/ISQLRow\";\n\nexport class MySQLRow implements ISQLRow {\n constructor(private row: any, private fields: string[]) {}\n\n private resolve(field: string | number): any {\n if (typeof field === \"number\")\n return this.row[this.fields[field]];\n return this.row[field];\n }\n\n GetString(field: string | number): string | null {\n const val = this.resolve(field);\n return val == null ? null : String(val);\n }\n\n GetInt(field: string | number): number {\n const val = this.resolve(field);\n return val == null ? 0 : Number(val);\n }\n\n GetFloat(field: string | number): number {\n return this.GetInt(field);\n }\n\n GetInt64(field: string | number): string {\n const val = this.resolve(field);\n return val == null ? \"0\" : String(val);\n }\n\n IsNull(field: string | number): boolean {\n return this.resolve(field) == null;\n }\n}\n","import { ISQLResult } from \"@core/ISQLResult\";\nimport { ISQLRow } from \"@core/ISQLRow\";\nimport { MySQLRow } from \"@drivers/mysql/MySQLRow\";\n\nexport class MySQLResult implements ISQLResult {\n private index = -1;\n private fields: string[];\n private current: ISQLRow | null = null;\n\n constructor(private rows: any[]) {\n this.fields = rows.length > 0 ? Object.keys(rows[0]) : [];\n }\n\n GetRowCount(): number {\n return this.rows.length;\n }\n\n GetFieldCount(): number {\n return this.fields.length;\n }\n\n FieldNameToNum(name: string): number | null {\n const idx = this.fields.indexOf(name);\n return idx === -1 ? null : idx;\n }\n\n FieldNumToName(index: number): string | null {\n return this.fields[index] ?? null;\n }\n\n MoreRows(): boolean {\n return this.index + 1 < this.rows.length;\n }\n\n FetchRow(): ISQLRow | null {\n if (!this.MoreRows()) return null;\n this.index++;\n this.current = new MySQLRow(this.rows[this.index], this.fields);\n return this.current;\n }\n\n CurrentRow(): ISQLRow | null {\n return this.current;\n }\n\n Rewind(): void {\n this.index = -1;\n this.current = null;\n }\n\n GetFieldType(field: number): number {\n return 0; // WIP\n }\n}\n","import { ISQLQuery, QueryType } from \"@core/ISQLQuery\";\nimport { MySQLResult } from \"./MySQLResult\";\n\nexport class MySQLQuery implements ISQLQuery {\n private result: MySQLResult | null;\n private type: QueryType;\n\n constructor(\n rows: any[],\n private meta: any,\n private sql: string\n ) {\n this.type = this.DetectType(sql);\n\n if (rows && rows.length > 0) {\n this.result = new MySQLResult(rows);\n } else {\n this.result = null;\n }\n }\n\n private DetectType(sql: string): QueryType {\n const q = sql.trim().toLowerCase();\n\n if (q.startsWith(\"select\")) return QueryType.SELECT;\n if (q.startsWith(\"insert\")) return QueryType.INSERT;\n if (q.startsWith(\"update\")) return QueryType.UPDATE;\n if (q.startsWith(\"delete\")) return QueryType.DELETE;\n\n return QueryType.OTHER;\n }\n\n GetResultSet() {\n return this.result;\n }\n\n GetInsertId(): number {\n return this.meta?.insertId ?? 0;\n }\n\n GetAffectedRows(): number {\n return this.meta?.affectedRows ?? 0;\n }\n\n GetType(): QueryType {\n return this.type;\n }\n}\n","import { ISQLConnection } from \"@core/ISQLConnection\";\nimport { ISQLQuery } from \"@core/ISQLQuery\";\n\nexport async function QueryEx(\n conn: ISQLConnection,\n sql: string,\n params?: any[]\n): Promise<readonly [ISQLQuery | null, Error | null]> {\n try {\n const q = await conn.Query(sql, params);\n return [q, null];\n } catch (e: any) {\n return [null, e instanceof Error ? e : new Error(String(e))];\n }\n}\n"],"mappings":";AAEO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AALU,SAAAA;AAAA,GAAA;;;ACFZ,OAAO,WAAW;;;ACEX,IAAM,WAAN,MAAkC;AAAA,EACvC,YAAoB,KAAkB,QAAkB;AAApC;AAAkB;AAAA,EAAmB;AAAA,EAEjD,QAAQ,OAA6B;AAC3C,QAAI,OAAO,UAAU;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A,EACnB;AAAA,EAEA,OAAO,OAAoB;AACzB,WAAO,MAAM,OAAO,KAAK;AAAA,EAC3B;AAAA,EAEA,SAAS,OAAuB;AAC9B,WAAO,MAAM,SAAS,KAAK;AAAA,EAC7B;AAAA,EAEA,YAAY,UAAkB,OAAuB;AACnD,WAAO,GAAG,KAAK,SAAS,QAAQ,CAAC,IAAI,KAAK,SAAS,KAAK,CAAC;AAAA,EAC3D;AACF;;;AI9FA,eAAsB,QACpB,MACA,KACA,QACoD;AACpD,MAAI;AACF,UAAM,IAAI,MAAM,KAAK,MAAM,KAAK,MAAM;AACtC,WAAO,CAAC,GAAG,IAAI;AAAA,EACjB,SAAS,GAAQ;AACf,WAAO,CAAC,MAAM,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC;AAAA,EAC7D;AACF;","names":["QueryType"]}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "sourcesql",
3
+ "version": "1.0.0",
4
+ "description": "C++ style SQL interface for Node.js",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsup"
19
+ },
20
+ "keywords": [
21
+ "mysql",
22
+ "sql",
23
+ "typescript",
24
+ "database",
25
+ "wrapper",
26
+ "oop",
27
+ "sourcesql"
28
+ ],
29
+ "author": "Michal \"Slynx\" Přikryl",
30
+ "license": "MIT",
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "dependencies": {
35
+ "mysql2": "^3.17.1"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^25.2.3",
39
+ "tsup": "^8.5.1",
40
+ "typescript": "^5.0.0"
41
+ }
42
+ }