baja-lite 1.8.8 → 1.8.9

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 (47) hide show
  1. package/boot-remote.d.ts +1 -1
  2. package/boot-remote.js +6 -1
  3. package/boot.d.ts +1 -1
  4. package/boot.js +6 -1
  5. package/cache.d.ts +91 -0
  6. package/cache.js +515 -0
  7. package/const/index.d.ts +2 -0
  8. package/const/index.js +2 -0
  9. package/const/symbols.d.ts +73 -0
  10. package/const/symbols.js +78 -0
  11. package/const/types.d.ts +504 -0
  12. package/const/types.js +127 -0
  13. package/db/dao/format-dialects.d.ts +6 -0
  14. package/db/dao/format-dialects.js +8 -0
  15. package/db/dao/mysql.d.ts +44 -0
  16. package/db/dao/mysql.js +303 -0
  17. package/db/dao/postgresql.d.ts +44 -0
  18. package/db/dao/postgresql.js +322 -0
  19. package/db/dao/sqlite-remote.d.ts +46 -0
  20. package/db/dao/sqlite-remote.js +226 -0
  21. package/db/dao/sqlite.d.ts +41 -0
  22. package/db/dao/sqlite.js +237 -0
  23. package/db/index.d.ts +8 -0
  24. package/db/index.js +8 -0
  25. package/db/service.d.ts +778 -0
  26. package/db/service.js +1651 -0
  27. package/db/sql-template.d.ts +46 -0
  28. package/db/sql-template.js +660 -0
  29. package/db/stream-query.d.ts +607 -0
  30. package/db/stream-query.js +1626 -0
  31. package/index.d.ts +4 -1
  32. package/index.js +4 -1
  33. package/logger.d.ts +46 -0
  34. package/logger.js +35 -0
  35. package/package.json +1 -1
  36. package/sqlite.d.ts +1 -1
  37. package/sqlite.js +2 -1
  38. package/{test-mysql.js → test/test-mysql.js} +3 -2
  39. package/{test-postgresql.js → test/test-postgresql.js} +3 -2
  40. package/{test-sqlite.js → test/test-sqlite.js} +3 -2
  41. package/sql.d.ts +0 -2222
  42. package/sql.js +0 -5503
  43. /package/{test-mysql.d.ts → test/test-mysql.d.ts} +0 -0
  44. /package/{test-postgresql.d.ts → test/test-postgresql.d.ts} +0 -0
  45. /package/{test-sqlite.d.ts → test/test-sqlite.d.ts} +0 -0
  46. /package/{test-xml.d.ts → test/test-xml.d.ts} +0 -0
  47. /package/{test-xml.js → test/test-xml.js} +0 -0
@@ -0,0 +1,237 @@
1
+ var _a;
2
+ import { snowflake } from '../../snowflake.js';
3
+ import { _daoConnection, _daoDB, _GlobalSqlOption, _inTransaction, _LoggerService } from '../../const/symbols.js';
4
+ import { SyncMode } from '../../const/types.js';
5
+ export class SqliteConnection {
6
+ constructor(conn) {
7
+ this[_a] = false;
8
+ this[_daoConnection] = conn;
9
+ }
10
+ execute(sync, sql, params) {
11
+ try {
12
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
13
+ if (!sql) {
14
+ return { affectedRows: 0, insertId: 0n };
15
+ }
16
+ ;
17
+ if (sync === SyncMode.Async) {
18
+ globalThis[_LoggerService].warn(`SQLITE not supported async mode`);
19
+ return { affectedRows: 0, insertId: 0n };
20
+ }
21
+ ;
22
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
23
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
24
+ }
25
+ const result = this[_daoConnection].prepare(sql).run(params ?? {});
26
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
27
+ globalThis[_LoggerService].verbose?.(result);
28
+ }
29
+ const { changes, lastInsertRowid } = result;
30
+ return { affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n };
31
+ }
32
+ catch (error) {
33
+ globalThis[_LoggerService].error(`
34
+ error: ${error},
35
+ sql: ${sql},
36
+ params: ${params}
37
+ `);
38
+ throw error;
39
+ }
40
+ }
41
+ pluck(sync, sql, params) {
42
+ try {
43
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
44
+ if (!sql) {
45
+ return null;
46
+ }
47
+ ;
48
+ if (sync === SyncMode.Async) {
49
+ globalThis[_LoggerService].warn(`SQLITE not supported async mode`);
50
+ return null;
51
+ }
52
+ ;
53
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
54
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
55
+ }
56
+ return this[_daoConnection].prepare(sql).pluck().get(params ?? {});
57
+ }
58
+ catch (error) {
59
+ globalThis[_LoggerService].error(`
60
+ error: ${error},
61
+ sql: ${sql},
62
+ params: ${params}
63
+ `);
64
+ throw error;
65
+ }
66
+ }
67
+ get(sync, sql, params) {
68
+ try {
69
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
70
+ if (!sql) {
71
+ return null;
72
+ }
73
+ ;
74
+ if (sync === SyncMode.Async) {
75
+ return null;
76
+ }
77
+ ;
78
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
79
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
80
+ }
81
+ return this[_daoConnection].prepare(sql).get(params ?? {});
82
+ }
83
+ catch (error) {
84
+ globalThis[_LoggerService].error(`
85
+ error: ${error},
86
+ sql: ${sql},
87
+ params: ${params}
88
+ `);
89
+ throw error;
90
+ }
91
+ }
92
+ raw(sync, sql, params) {
93
+ try {
94
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
95
+ if (!sql) {
96
+ return [];
97
+ }
98
+ ;
99
+ if (sync === SyncMode.Async) {
100
+ globalThis[_LoggerService].warn(`SQLITE not supported async mode`);
101
+ return [];
102
+ }
103
+ ;
104
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
105
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
106
+ }
107
+ return this[_daoConnection].prepare(sql).raw().all(params ?? {});
108
+ }
109
+ catch (error) {
110
+ globalThis[_LoggerService].error(`
111
+ error: ${error},
112
+ sql: ${sql},
113
+ params: ${params}
114
+ `);
115
+ throw error;
116
+ }
117
+ }
118
+ query(sync, sql, params) {
119
+ try {
120
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
121
+ if (!sql) {
122
+ return [];
123
+ }
124
+ ;
125
+ if (sync === SyncMode.Async) {
126
+ globalThis[_LoggerService].warn(`SQLITE not supported async mode`);
127
+ return [];
128
+ }
129
+ ;
130
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
131
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
132
+ }
133
+ return this[_daoConnection].prepare(sql).all(params ?? {});
134
+ }
135
+ catch (error) {
136
+ globalThis[_LoggerService].error(`
137
+ error: ${error},
138
+ sql: ${sql},
139
+ params: ${params}
140
+ `);
141
+ throw error;
142
+ }
143
+ }
144
+ release(sync) {
145
+ }
146
+ }
147
+ _a = _inTransaction;
148
+ export class Sqlite {
149
+ constructor(db) {
150
+ this[_daoDB] = db;
151
+ this[_daoDB].pragma('journal_mode = WAL');
152
+ this[_daoDB].exec(`
153
+ CREATE TABLE IF NOT EXISTS DUAL ( ______id INTEGER NOT NULL, PRIMARY KEY ( ______id ));
154
+ DELETE FROM DUAL;
155
+ INSERT INTO DUAL (______id ) VALUES ( 1 );
156
+ CREATE TABLE IF NOT EXISTS TABLE_VERSION (
157
+ ______tableName text NOT NULL,
158
+ ______version text NOT NULL,
159
+ PRIMARY KEY ( ______tableName )
160
+ );
161
+ `);
162
+ this[_daoDB].function('UUID_SHORT', { deterministic: false }, () => snowflake.generate());
163
+ this[_daoDB].function('UUID', { deterministic: false }, () => snowflake.generate());
164
+ this[_daoDB].function('TIME_TO_SEC', { deterministic: true }, (time) => {
165
+ const parts = time.split(':');
166
+ const hours = parseInt(parts[0] || '0');
167
+ const minutes = parseInt(parts[1] || '0');
168
+ const seconds = parseInt(parts[2] || '0');
169
+ return hours * 3600 + minutes * 60 + seconds;
170
+ });
171
+ this[_daoDB].function('IF', { deterministic: true }, (condition, v1, v2) => condition ? v1 : v2);
172
+ this[_daoDB].function('RIGHT', { deterministic: true }, (src, p) => src.slice(p * -1));
173
+ this[_daoDB].function('LEFT', { deterministic: true }, (str, len) => str?.substring(0, len) || null);
174
+ this[_daoDB].function('NOW', { deterministic: false }, () => new Date().toISOString().slice(0, 19).replace('T', ' '));
175
+ this[_daoDB].function('CURDATE', { deterministic: false }, () => new Date().toISOString().split('T')[0]);
176
+ this[_daoDB].function('DATE_FORMAT', { deterministic: true }, (dateStr, format) => {
177
+ const date = new Date(dateStr);
178
+ return format
179
+ .replace('%Y', date.getFullYear().toString())
180
+ .replace('%m', (date.getMonth() + 1).toString().padStart(2, '0'))
181
+ .replace('%d', date.getDate().toString().padStart(2, '0'))
182
+ .replace('%H', date.getHours().toString().padStart(2, '0'))
183
+ .replace('%i', date.getMinutes().toString().padStart(2, '0'))
184
+ .replace('%s', date.getSeconds().toString().padStart(2, '0'));
185
+ });
186
+ this[_daoDB].function('RAND', { deterministic: false }, () => Math.random());
187
+ this[_daoDB].function('UNIX_TIMESTAMP', { deterministic: false }, (dateStr) => dateStr
188
+ ? Math.floor(new Date(dateStr).getTime() / 1000)
189
+ : Math.floor(Date.now() / 1000));
190
+ }
191
+ createConnection(sync) {
192
+ if (sync === SyncMode.Async) {
193
+ globalThis[_LoggerService].error(`SQLITE not supported async mode`);
194
+ return null;
195
+ }
196
+ ;
197
+ return new SqliteConnection(this[_daoDB]);
198
+ }
199
+ transaction(sync, fn, conn) {
200
+ if (sync === SyncMode.Async) {
201
+ globalThis[_LoggerService].warn(`SQLITE not supported async mode`);
202
+ return null;
203
+ }
204
+ ;
205
+ if (!conn) {
206
+ conn = this.createConnection(SyncMode.Sync) ?? undefined;
207
+ }
208
+ if (conn[_inTransaction] !== true) {
209
+ return this[_daoDB].transaction(() => {
210
+ conn[_inTransaction] = true;
211
+ const rt = fn(conn);
212
+ conn[_inTransaction] = false;
213
+ return rt;
214
+ })();
215
+ }
216
+ else {
217
+ const rt = fn(conn);
218
+ return rt;
219
+ }
220
+ }
221
+ close(sync) {
222
+ if (sync === SyncMode.Sync) {
223
+ this[_daoDB].close();
224
+ }
225
+ ;
226
+ }
227
+ backup(sync, name) {
228
+ if (sync === SyncMode.Sync) {
229
+ this[_daoDB].backup(name);
230
+ }
231
+ ;
232
+ }
233
+ remove(sync) {
234
+ }
235
+ restore(sync, name) {
236
+ }
237
+ }
package/db/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './dao/format-dialects.js';
2
+ export * from './dao/mysql.js';
3
+ export * from './dao/postgresql.js';
4
+ export * from './dao/sqlite.js';
5
+ export * from './dao/sqlite-remote.js';
6
+ export * from './sql-template.js';
7
+ export * from './service.js';
8
+ export * from './stream-query.js';
package/db/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from './dao/format-dialects.js';
2
+ export * from './dao/mysql.js';
3
+ export * from './dao/postgresql.js';
4
+ export * from './dao/sqlite.js';
5
+ export * from './dao/sqlite-remote.js';
6
+ export * from './sql-template.js';
7
+ export * from './service.js';
8
+ export * from './stream-query.js';