@pineliner/odb-client 1.0.9 → 1.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.
- package/dist/core/client.d.ts +13 -2
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/http-client.d.ts +32 -0
- package/dist/core/http-client.d.ts.map +1 -1
- package/dist/core/transaction.d.ts +8 -0
- package/dist/core/transaction.d.ts.map +1 -1
- package/dist/database/types.d.ts +13 -0
- package/dist/database/types.d.ts.map +1 -1
- package/dist/index.cjs +280 -53
- package/dist/index.js +280 -53
- package/dist/service/service-client.d.ts +18 -2
- package/dist/service/service-client.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/client.ts +28 -11
- package/src/core/http-client.ts +141 -0
- package/src/core/transaction.ts +203 -0
- package/src/database/adapters/odblite.ts +68 -5
- package/src/database/types.ts +15 -0
- package/src/service/service-client.ts +34 -2
package/dist/core/client.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { ODBLiteConfig, ODBLiteConnection, QueryResult, Transaction, TransactionCallback, TransactionMode, SQLFragment } from '../types.ts';
|
|
2
|
+
import { HTTPClient } from './http-client.ts';
|
|
3
|
+
interface BatchResult<T = any> {
|
|
4
|
+
results: QueryResult<T>[];
|
|
5
|
+
executionTime: number;
|
|
6
|
+
statementsExecuted: number;
|
|
7
|
+
}
|
|
2
8
|
interface SQLFunction {
|
|
3
9
|
<T = any>(sql: TemplateStringsArray, ...values: any[]): Promise<QueryResult<T>>;
|
|
4
10
|
<T = any>(input: any): SQLFragment;
|
|
@@ -9,6 +15,10 @@ interface SQLFunction {
|
|
|
9
15
|
sql: string;
|
|
10
16
|
args?: any[];
|
|
11
17
|
}, args?: any[]): Promise<QueryResult<T>>;
|
|
18
|
+
batch<T = any>(statements: Array<{
|
|
19
|
+
sql: string;
|
|
20
|
+
params?: any[];
|
|
21
|
+
}>): Promise<BatchResult<T>>;
|
|
12
22
|
begin(): Promise<Transaction>;
|
|
13
23
|
begin<T>(callback: TransactionCallback<T>): Promise<T>;
|
|
14
24
|
begin<T>(mode: TransactionMode, callback: TransactionCallback<T>): Promise<T>;
|
|
@@ -22,12 +32,13 @@ interface SQLFunction {
|
|
|
22
32
|
* Main ODBLite client that provides postgres.js-like interface
|
|
23
33
|
*/
|
|
24
34
|
export declare class ODBLiteClient implements ODBLiteConnection {
|
|
25
|
-
|
|
35
|
+
httpClient: HTTPClient;
|
|
26
36
|
config: ODBLiteConfig;
|
|
27
37
|
sql: SQLFunction;
|
|
28
38
|
constructor(config: ODBLiteConfig);
|
|
29
39
|
/**
|
|
30
40
|
* Execute a transaction with callback (postgres.js style)
|
|
41
|
+
* Uses batch-based transaction for true ACID guarantees
|
|
31
42
|
*/
|
|
32
43
|
private executeTransactionWithCallback;
|
|
33
44
|
/**
|
|
@@ -37,7 +48,7 @@ export declare class ODBLiteClient implements ODBLiteConnection {
|
|
|
37
48
|
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
38
49
|
/**
|
|
39
50
|
* Begin a transaction
|
|
40
|
-
*
|
|
51
|
+
* Uses batch-based transaction for true ACID guarantees
|
|
41
52
|
*/
|
|
42
53
|
begin(): Promise<Transaction>;
|
|
43
54
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjJ,OAAO,EAAE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IAAI,EAAE,MAAM,GAAG,MAAM;IAIhC;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAI5C;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;IAIrE;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAI1C;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC,EAAE,SAAS,SAAM;CAG/E;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;AAC5D,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;AAkB3F,eAAO,MAAM,GAAG,0BAAoB,CAAC;AACrC,eAAO,MAAM,UAAU,iCAA2B,CAAC;AACnD,eAAO,MAAM,KAAK,4BAAsB,CAAC;AACzC,eAAO,MAAM,YAAY,mCAA6B,CAAC;AACvD,eAAO,MAAM,SAAS,gCAA0B,CAAC;AACjD,eAAO,MAAM,IAAI,2BAAqB,CAAC"}
|
|
@@ -9,6 +9,18 @@ export declare class HTTPClient {
|
|
|
9
9
|
* Execute a query against the ODBLite service
|
|
10
10
|
*/
|
|
11
11
|
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
12
|
+
/**
|
|
13
|
+
* Execute multiple statements on the same connection (for transactions)
|
|
14
|
+
* All statements are sent in a single HTTP request and executed atomically on the server
|
|
15
|
+
*/
|
|
16
|
+
batch<T = any>(statements: Array<{
|
|
17
|
+
sql: string;
|
|
18
|
+
params?: any[];
|
|
19
|
+
}>): Promise<{
|
|
20
|
+
results: QueryResult<T>[];
|
|
21
|
+
executionTime: number;
|
|
22
|
+
statementsExecuted: number;
|
|
23
|
+
}>;
|
|
12
24
|
/**
|
|
13
25
|
* Check database health
|
|
14
26
|
*/
|
|
@@ -33,5 +45,25 @@ export declare class HTTPClient {
|
|
|
33
45
|
* Get current configuration
|
|
34
46
|
*/
|
|
35
47
|
getConfig(): Readonly<ODBLiteConfig>;
|
|
48
|
+
/**
|
|
49
|
+
* Ensure namespaces exist for the database
|
|
50
|
+
* Creates the namespace .db files if they don't exist
|
|
51
|
+
*/
|
|
52
|
+
ensureNamespaces(namespaces: string[]): Promise<{
|
|
53
|
+
success: boolean;
|
|
54
|
+
databaseName: string;
|
|
55
|
+
namespaces: string[];
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Get namespace information for the database
|
|
59
|
+
*/
|
|
60
|
+
getNamespaces(): Promise<{
|
|
61
|
+
success: boolean;
|
|
62
|
+
databaseName: string;
|
|
63
|
+
exists: boolean;
|
|
64
|
+
namespaces: string[];
|
|
65
|
+
registered: boolean;
|
|
66
|
+
registeredNamespaces: string[];
|
|
67
|
+
}>;
|
|
36
68
|
}
|
|
37
69
|
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/core/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAA;AAG9E;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAe;gBAEjB,MAAM,EAAE,aAAa;IAajC;;OAEG;IACG,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,E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AAG,CAAC;IAqBrC;;OAEG;IACH,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAIrC;;OAEG;YACW,WAAW;IAgDzB;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,UAAU;IAOtD;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,aAAa,CAAC;IAIpC;;;OAGG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QACpD,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,EAAE,CAAC;KACtB,CAAC;IAqCF;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC;QAC7B,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,OAAO,CAAC;QAChB,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,UAAU,EAAE,OAAO,CAAC;QACpB,oBAAoB,EAAE,MAAM,EAAE,CAAC;KAChC,CAAC;CAiCH"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { Transaction, QueryResult } from '../types.ts';
|
|
2
2
|
import type { HTTPClient } from './http-client.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Create a batch-based transaction that executes all statements atomically
|
|
5
|
+
* using the /batch endpoint. This ensures true ACID transactions by:
|
|
6
|
+
* 1. Collecting all write statements during callback execution
|
|
7
|
+
* 2. Sending BEGIN + statements + COMMIT as a single batch request
|
|
8
|
+
* 3. If callback throws, nothing is executed (implicit rollback)
|
|
9
|
+
*/
|
|
10
|
+
export declare function createBatchTransaction(httpClient: HTTPClient): Transaction;
|
|
3
11
|
/**
|
|
4
12
|
* Create a transaction function similar to the main sql function
|
|
5
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/core/transaction.ts"],"names":[],"mappings":"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CAAC,CAAC;IASlF,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAKvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAIhC"}
|
package/dist/database/types.d.ts
CHANGED
|
@@ -62,6 +62,19 @@ export interface Connection {
|
|
|
62
62
|
createORM?(): any;
|
|
63
63
|
databaseHash?: string;
|
|
64
64
|
databaseName?: string;
|
|
65
|
+
ensureNamespaces?(namespaces: string[]): Promise<{
|
|
66
|
+
success: boolean;
|
|
67
|
+
databaseName: string;
|
|
68
|
+
namespaces: string[];
|
|
69
|
+
}>;
|
|
70
|
+
getNamespaces?(): Promise<{
|
|
71
|
+
success: boolean;
|
|
72
|
+
databaseName: string;
|
|
73
|
+
exists: boolean;
|
|
74
|
+
namespaces: string[];
|
|
75
|
+
registered: boolean;
|
|
76
|
+
registeredNamespaces: string[];
|
|
77
|
+
}>;
|
|
65
78
|
}
|
|
66
79
|
/**
|
|
67
80
|
* Prepared statement interface
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,cAAc,GACd,WAAW,GACX,WAAW,CAAA;AAEf;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IAEtB;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;C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,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,IAAI,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC/B"}
|
package/dist/index.cjs
CHANGED
|
@@ -574,6 +574,34 @@ var __webpack_exports__ = {};
|
|
|
574
574
|
throw new types_QueryError(error instanceof Error ? error.message : 'Unknown error occurred', sql, params, error instanceof Error ? error : void 0);
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
|
+
async batch(statements) {
|
|
578
|
+
if (!this.config.databaseId) throw new ConnectionError('No database ID configured. Use setDatabase() first.');
|
|
579
|
+
const url = `${this.config.baseUrl}/batch/${this.config.databaseId}`;
|
|
580
|
+
const body = {
|
|
581
|
+
statements
|
|
582
|
+
};
|
|
583
|
+
try {
|
|
584
|
+
const response = await this.makeRequest(url, {
|
|
585
|
+
method: 'POST',
|
|
586
|
+
headers: {
|
|
587
|
+
'Content-Type': 'application/json',
|
|
588
|
+
Authorization: `Bearer ${this.config.apiKey}`
|
|
589
|
+
},
|
|
590
|
+
body: JSON.stringify(body)
|
|
591
|
+
});
|
|
592
|
+
const data = await response.json();
|
|
593
|
+
if (!data.success) throw new types_QueryError(data.error || 'Batch failed');
|
|
594
|
+
const batchData = data.data || data;
|
|
595
|
+
return {
|
|
596
|
+
results: batchData.results || [],
|
|
597
|
+
executionTime: batchData.executionTime || 0,
|
|
598
|
+
statementsExecuted: batchData.statementsExecuted || statements.length
|
|
599
|
+
};
|
|
600
|
+
} catch (error) {
|
|
601
|
+
if (error instanceof types_QueryError || error instanceof ConnectionError) throw error;
|
|
602
|
+
throw new types_QueryError(error instanceof Error ? error.message : 'Unknown error occurred', void 0, void 0, error instanceof Error ? error : void 0);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
577
605
|
async ping() {
|
|
578
606
|
if (!this.config.databaseId) return false;
|
|
579
607
|
try {
|
|
@@ -650,6 +678,47 @@ var __webpack_exports__ = {};
|
|
|
650
678
|
...this.config
|
|
651
679
|
};
|
|
652
680
|
}
|
|
681
|
+
async ensureNamespaces(namespaces) {
|
|
682
|
+
if (!this.config.databaseId) throw new ConnectionError('No database ID configured. Use setDatabase() first.');
|
|
683
|
+
const url = `${this.config.baseUrl}/namespaces/${this.config.databaseId}`;
|
|
684
|
+
const body = {
|
|
685
|
+
namespaces
|
|
686
|
+
};
|
|
687
|
+
try {
|
|
688
|
+
const response = await this.makeRequest(url, {
|
|
689
|
+
method: 'POST',
|
|
690
|
+
headers: {
|
|
691
|
+
'Content-Type': 'application/json',
|
|
692
|
+
Authorization: `Bearer ${this.config.apiKey}`
|
|
693
|
+
},
|
|
694
|
+
body: JSON.stringify(body)
|
|
695
|
+
});
|
|
696
|
+
const data = await response.json();
|
|
697
|
+
if (!data.success) throw new ConnectionError(data.error || 'Failed to ensure namespaces');
|
|
698
|
+
return data;
|
|
699
|
+
} catch (error) {
|
|
700
|
+
if (error instanceof ConnectionError) throw error;
|
|
701
|
+
throw new ConnectionError(error instanceof Error ? error.message : 'Unknown error occurred', error instanceof Error ? error : void 0);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
async getNamespaces() {
|
|
705
|
+
if (!this.config.databaseId) throw new ConnectionError('No database ID configured. Use setDatabase() first.');
|
|
706
|
+
const url = `${this.config.baseUrl}/namespaces/${this.config.databaseId}`;
|
|
707
|
+
try {
|
|
708
|
+
const response = await this.makeRequest(url, {
|
|
709
|
+
method: 'GET',
|
|
710
|
+
headers: {
|
|
711
|
+
Authorization: `Bearer ${this.config.apiKey}`
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
const data = await response.json();
|
|
715
|
+
if (!data.success) throw new ConnectionError(data.error || 'Failed to get namespaces');
|
|
716
|
+
return data;
|
|
717
|
+
} catch (error) {
|
|
718
|
+
if (error instanceof ConnectionError) throw error;
|
|
719
|
+
throw new ConnectionError(error instanceof Error ? error.message : 'Unknown error occurred', error instanceof Error ? error : void 0);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
653
722
|
}
|
|
654
723
|
class sql_parser_SQLParser {
|
|
655
724
|
static parse(sql, values) {
|
|
@@ -839,6 +908,147 @@ var __webpack_exports__ = {};
|
|
|
839
908
|
sql_parser_SQLParser.where.bind(sql_parser_SQLParser);
|
|
840
909
|
sql_parser_SQLParser.insertValues.bind(sql_parser_SQLParser);
|
|
841
910
|
sql_parser_SQLParser.updateSet.bind(sql_parser_SQLParser);
|
|
911
|
+
function createBatchTransaction(httpClient) {
|
|
912
|
+
let isCommitted = false;
|
|
913
|
+
let isRolledBack = false;
|
|
914
|
+
const queuedStatements = [];
|
|
915
|
+
const checkTransactionState = ()=>{
|
|
916
|
+
if (isCommitted) throw new types_QueryError('Transaction has already been committed');
|
|
917
|
+
if (isRolledBack) throw new types_QueryError('Transaction has been rolled back');
|
|
918
|
+
};
|
|
919
|
+
const isReadQuery = (sql)=>{
|
|
920
|
+
const trimmed = sql.trim().toUpperCase();
|
|
921
|
+
return trimmed.startsWith('SELECT') || trimmed.startsWith('WITH') || trimmed.startsWith('EXPLAIN') || trimmed.startsWith('PRAGMA');
|
|
922
|
+
};
|
|
923
|
+
const txFunction = (sql, ...values)=>{
|
|
924
|
+
checkTransactionState();
|
|
925
|
+
if (Array.isArray(sql) && ('raw' in sql || 'string' == typeof sql[0] && values.length >= 0)) {
|
|
926
|
+
const parsed = sql_parser_SQLParser.parse(sql, values);
|
|
927
|
+
if (isReadQuery(parsed.sql)) return httpClient.query(parsed.sql, parsed.params);
|
|
928
|
+
queuedStatements.push(parsed);
|
|
929
|
+
return Promise.resolve({
|
|
930
|
+
rows: [],
|
|
931
|
+
rowsAffected: 0,
|
|
932
|
+
executionTime: 0
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
const parsed = sql_parser_SQLParser.parse(sql, values);
|
|
936
|
+
return {
|
|
937
|
+
text: parsed.sql,
|
|
938
|
+
values: parsed.params
|
|
939
|
+
};
|
|
940
|
+
};
|
|
941
|
+
txFunction.raw = (text)=>sql_parser_SQLParser.raw(text);
|
|
942
|
+
txFunction.identifier = (name)=>sql_parser_SQLParser.identifier(name);
|
|
943
|
+
txFunction.execute = async (sql, args)=>{
|
|
944
|
+
checkTransactionState();
|
|
945
|
+
const sqlStr = 'string' == typeof sql ? sql : sql.sql;
|
|
946
|
+
const params = 'string' == typeof sql ? args || [] : sql.args || [];
|
|
947
|
+
if (isReadQuery(sqlStr)) return await httpClient.query(sqlStr, params);
|
|
948
|
+
queuedStatements.push({
|
|
949
|
+
sql: sqlStr,
|
|
950
|
+
params
|
|
951
|
+
});
|
|
952
|
+
return {
|
|
953
|
+
rows: [],
|
|
954
|
+
rowsAffected: 0,
|
|
955
|
+
executionTime: 0
|
|
956
|
+
};
|
|
957
|
+
};
|
|
958
|
+
txFunction.query = async (sql, params = [])=>{
|
|
959
|
+
checkTransactionState();
|
|
960
|
+
if (isReadQuery(sql)) return await httpClient.query(sql, params);
|
|
961
|
+
queuedStatements.push({
|
|
962
|
+
sql,
|
|
963
|
+
params
|
|
964
|
+
});
|
|
965
|
+
return {
|
|
966
|
+
rows: [],
|
|
967
|
+
rowsAffected: 0,
|
|
968
|
+
executionTime: 0
|
|
969
|
+
};
|
|
970
|
+
};
|
|
971
|
+
txFunction.commit = async ()=>{
|
|
972
|
+
checkTransactionState();
|
|
973
|
+
if (0 === queuedStatements.length) {
|
|
974
|
+
isCommitted = true;
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
try {
|
|
978
|
+
const batchStatements = [
|
|
979
|
+
{
|
|
980
|
+
sql: 'BEGIN',
|
|
981
|
+
params: []
|
|
982
|
+
},
|
|
983
|
+
...queuedStatements,
|
|
984
|
+
{
|
|
985
|
+
sql: 'COMMIT',
|
|
986
|
+
params: []
|
|
987
|
+
}
|
|
988
|
+
];
|
|
989
|
+
await httpClient.batch(batchStatements);
|
|
990
|
+
isCommitted = true;
|
|
991
|
+
} catch (error) {
|
|
992
|
+
isRolledBack = true;
|
|
993
|
+
throw new types_QueryError(`Transaction failed: ${error instanceof Error ? error.message : 'Unknown error'}`, void 0, void 0, error instanceof Error ? error : void 0);
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
txFunction.rollback = async ()=>{
|
|
997
|
+
checkTransactionState();
|
|
998
|
+
queuedStatements.length = 0;
|
|
999
|
+
isRolledBack = true;
|
|
1000
|
+
};
|
|
1001
|
+
txFunction.savepoint = async (callback)=>{
|
|
1002
|
+
checkTransactionState();
|
|
1003
|
+
const savepointStatements = [];
|
|
1004
|
+
const savepointTx = (sql, ...values)=>{
|
|
1005
|
+
if (isCommitted || isRolledBack) throw new types_QueryError('Transaction is no longer active');
|
|
1006
|
+
if (Array.isArray(sql) && ('raw' in sql || 'string' == typeof sql[0] && values.length >= 0)) {
|
|
1007
|
+
const parsed = sql_parser_SQLParser.parse(sql, values);
|
|
1008
|
+
if (isReadQuery(parsed.sql)) return httpClient.query(parsed.sql, parsed.params);
|
|
1009
|
+
savepointStatements.push(parsed);
|
|
1010
|
+
return Promise.resolve({
|
|
1011
|
+
rows: [],
|
|
1012
|
+
rowsAffected: 0,
|
|
1013
|
+
executionTime: 0
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
const parsed = sql_parser_SQLParser.parse(sql, values);
|
|
1017
|
+
return {
|
|
1018
|
+
text: parsed.sql,
|
|
1019
|
+
values: parsed.params
|
|
1020
|
+
};
|
|
1021
|
+
};
|
|
1022
|
+
savepointTx.raw = (text)=>sql_parser_SQLParser.raw(text);
|
|
1023
|
+
savepointTx.identifier = (name)=>sql_parser_SQLParser.identifier(name);
|
|
1024
|
+
savepointTx.execute = async (sql, args)=>{
|
|
1025
|
+
const sqlStr = 'string' == typeof sql ? sql : sql.sql;
|
|
1026
|
+
const params = 'string' == typeof sql ? args || [] : sql.args || [];
|
|
1027
|
+
if (isReadQuery(sqlStr)) return await httpClient.query(sqlStr, params);
|
|
1028
|
+
savepointStatements.push({
|
|
1029
|
+
sql: sqlStr,
|
|
1030
|
+
params
|
|
1031
|
+
});
|
|
1032
|
+
return {
|
|
1033
|
+
rows: [],
|
|
1034
|
+
rowsAffected: 0,
|
|
1035
|
+
executionTime: 0
|
|
1036
|
+
};
|
|
1037
|
+
};
|
|
1038
|
+
savepointTx.commit = async ()=>{};
|
|
1039
|
+
savepointTx.rollback = async ()=>{
|
|
1040
|
+
savepointStatements.length = 0;
|
|
1041
|
+
};
|
|
1042
|
+
try {
|
|
1043
|
+
const result = await callback(savepointTx);
|
|
1044
|
+
queuedStatements.push(...savepointStatements);
|
|
1045
|
+
return result;
|
|
1046
|
+
} catch (error) {
|
|
1047
|
+
throw error;
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
return txFunction;
|
|
1051
|
+
}
|
|
842
1052
|
class ODBLiteTransaction {
|
|
843
1053
|
httpClient;
|
|
844
1054
|
isCommitted = false;
|
|
@@ -890,51 +1100,6 @@ var __webpack_exports__ = {};
|
|
|
890
1100
|
return trimmed.startsWith('SELECT') || trimmed.startsWith('WITH') || trimmed.startsWith('EXPLAIN') || trimmed.startsWith('PRAGMA');
|
|
891
1101
|
}
|
|
892
1102
|
}
|
|
893
|
-
function createSimpleTransaction(httpClient) {
|
|
894
|
-
let isActive = true;
|
|
895
|
-
const txFunction = (sql, ...values)=>{
|
|
896
|
-
if (!isActive) throw new types_QueryError('Transaction is no longer active');
|
|
897
|
-
if (Array.isArray(sql) && ('raw' in sql || 'string' == typeof sql[0] && values.length >= 0)) {
|
|
898
|
-
const parsed = sql_parser_SQLParser.parse(sql, values);
|
|
899
|
-
return httpClient.query(parsed.sql, parsed.params);
|
|
900
|
-
}
|
|
901
|
-
const parsed = sql_parser_SQLParser.parse(sql, values);
|
|
902
|
-
return {
|
|
903
|
-
text: parsed.sql,
|
|
904
|
-
values: parsed.params
|
|
905
|
-
};
|
|
906
|
-
};
|
|
907
|
-
txFunction.raw = (text)=>sql_parser_SQLParser.raw(text);
|
|
908
|
-
txFunction.identifier = (name)=>sql_parser_SQLParser.identifier(name);
|
|
909
|
-
txFunction.execute = async (sql, args)=>{
|
|
910
|
-
if (!isActive) throw new types_QueryError('Transaction is no longer active');
|
|
911
|
-
if ('string' == typeof sql) return await httpClient.query(sql, args || []);
|
|
912
|
-
return await httpClient.query(sql.sql, sql.args || []);
|
|
913
|
-
};
|
|
914
|
-
txFunction.query = async (sql, params = [])=>{
|
|
915
|
-
if (!isActive) throw new types_QueryError('Transaction is no longer active');
|
|
916
|
-
return await httpClient.query(sql, params);
|
|
917
|
-
};
|
|
918
|
-
txFunction.commit = async ()=>{
|
|
919
|
-
isActive = false;
|
|
920
|
-
};
|
|
921
|
-
txFunction.rollback = async ()=>{
|
|
922
|
-
isActive = false;
|
|
923
|
-
};
|
|
924
|
-
txFunction.savepoint = async (callback)=>{
|
|
925
|
-
if (!isActive) throw new types_QueryError('Transaction is no longer active');
|
|
926
|
-
const savepointTx = createSimpleTransaction(httpClient);
|
|
927
|
-
try {
|
|
928
|
-
const result = await callback(savepointTx);
|
|
929
|
-
await savepointTx.commit();
|
|
930
|
-
return result;
|
|
931
|
-
} catch (error) {
|
|
932
|
-
await savepointTx.rollback();
|
|
933
|
-
throw error;
|
|
934
|
-
}
|
|
935
|
-
};
|
|
936
|
-
return txFunction;
|
|
937
|
-
}
|
|
938
1103
|
class SimpleTransaction {
|
|
939
1104
|
httpClient;
|
|
940
1105
|
isActive = true;
|
|
@@ -978,10 +1143,11 @@ var __webpack_exports__ = {};
|
|
|
978
1143
|
if ('string' == typeof sql) return await this.httpClient.query(sql, args || []);
|
|
979
1144
|
return await this.httpClient.query(sql.sql, sql.args || []);
|
|
980
1145
|
};
|
|
1146
|
+
sqlFunction.batch = async (statements)=>await this.httpClient.batch(statements);
|
|
981
1147
|
sqlFunction.begin = async (modeOrCallback, callback)=>{
|
|
982
1148
|
if ('function' == typeof modeOrCallback) return this.executeTransactionWithCallback(modeOrCallback);
|
|
983
1149
|
if ('string' == typeof modeOrCallback && callback) return this.executeTransactionWithCallback(callback, modeOrCallback);
|
|
984
|
-
return
|
|
1150
|
+
return createBatchTransaction(this.httpClient);
|
|
985
1151
|
};
|
|
986
1152
|
sqlFunction.ping = async ()=>await this.httpClient.ping();
|
|
987
1153
|
sqlFunction.end = async ()=>{};
|
|
@@ -1001,7 +1167,7 @@ var __webpack_exports__ = {};
|
|
|
1001
1167
|
this.sql = sqlFunction;
|
|
1002
1168
|
}
|
|
1003
1169
|
async executeTransactionWithCallback(callback, mode) {
|
|
1004
|
-
const tx =
|
|
1170
|
+
const tx = createBatchTransaction(this.httpClient);
|
|
1005
1171
|
try {
|
|
1006
1172
|
const result = await callback(tx);
|
|
1007
1173
|
await tx.commit();
|
|
@@ -1015,7 +1181,7 @@ var __webpack_exports__ = {};
|
|
|
1015
1181
|
return await this.httpClient.query(sql, params);
|
|
1016
1182
|
}
|
|
1017
1183
|
async begin() {
|
|
1018
|
-
return
|
|
1184
|
+
return createBatchTransaction(this.httpClient);
|
|
1019
1185
|
}
|
|
1020
1186
|
async ping() {
|
|
1021
1187
|
return await this.httpClient.ping();
|
|
@@ -1120,11 +1286,12 @@ var __webpack_exports__ = {};
|
|
|
1120
1286
|
if (!result.success) throw new Error(result.error || 'Failed to list databases');
|
|
1121
1287
|
return result.databases;
|
|
1122
1288
|
}
|
|
1123
|
-
async createDatabase(name, nodeId) {
|
|
1289
|
+
async createDatabase(name, nodeId, namespaces) {
|
|
1124
1290
|
const body = {
|
|
1125
1291
|
name
|
|
1126
1292
|
};
|
|
1127
1293
|
if (nodeId) body.nodeId = nodeId;
|
|
1294
|
+
if (namespaces && namespaces.length > 0) body.namespaces = namespaces;
|
|
1128
1295
|
const response = await fetch(`${this.apiUrl}/api/tenant/databases`, {
|
|
1129
1296
|
method: 'POST',
|
|
1130
1297
|
headers: {
|
|
@@ -1172,6 +1339,21 @@ var __webpack_exports__ = {};
|
|
|
1172
1339
|
break;
|
|
1173
1340
|
}
|
|
1174
1341
|
}
|
|
1342
|
+
async ensureNamespaces(hash, namespaces) {
|
|
1343
|
+
const response = await fetch(`${this.apiUrl}/api/tenant/databases/${hash}/namespaces`, {
|
|
1344
|
+
method: 'POST',
|
|
1345
|
+
headers: {
|
|
1346
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
1347
|
+
'Content-Type': 'application/json'
|
|
1348
|
+
},
|
|
1349
|
+
body: JSON.stringify({
|
|
1350
|
+
namespaces
|
|
1351
|
+
})
|
|
1352
|
+
});
|
|
1353
|
+
const result = await response.json();
|
|
1354
|
+
if (!result.success) throw new Error(result.error || 'Failed to ensure namespaces');
|
|
1355
|
+
return result;
|
|
1356
|
+
}
|
|
1175
1357
|
async listNodes() {
|
|
1176
1358
|
const response = await fetch(`${this.apiUrl}/api/tenant/nodes`, {
|
|
1177
1359
|
headers: {
|
|
@@ -1840,13 +2022,52 @@ var __webpack_exports__ = {};
|
|
|
1840
2022
|
async transaction(fn) {
|
|
1841
2023
|
if (this.inTransaction) return fn(this);
|
|
1842
2024
|
this.inTransaction = true;
|
|
2025
|
+
const queuedStatements = [];
|
|
2026
|
+
const txConnection = {
|
|
2027
|
+
...this,
|
|
2028
|
+
execute: async (sql, params = [], options)=>{
|
|
2029
|
+
const sqlStr = 'string' == typeof sql ? sql : sql.sql;
|
|
2030
|
+
const sqlParams = 'string' == typeof sql ? params : sql.args || [];
|
|
2031
|
+
queuedStatements.push({
|
|
2032
|
+
sql: sqlStr,
|
|
2033
|
+
params: sqlParams
|
|
2034
|
+
});
|
|
2035
|
+
return {
|
|
2036
|
+
rows: [],
|
|
2037
|
+
rowsAffected: 0
|
|
2038
|
+
};
|
|
2039
|
+
},
|
|
2040
|
+
query: async (sql, params = [], options)=>{
|
|
2041
|
+
queuedStatements.push({
|
|
2042
|
+
sql,
|
|
2043
|
+
params
|
|
2044
|
+
});
|
|
2045
|
+
return {
|
|
2046
|
+
rows: [],
|
|
2047
|
+
rowsAffected: 0
|
|
2048
|
+
};
|
|
2049
|
+
},
|
|
2050
|
+
transaction: async (innerFn)=>innerFn(txConnection),
|
|
2051
|
+
begin: async (innerFn)=>innerFn(txConnection)
|
|
2052
|
+
};
|
|
1843
2053
|
try {
|
|
1844
|
-
await
|
|
1845
|
-
|
|
1846
|
-
|
|
2054
|
+
const result = await fn(txConnection);
|
|
2055
|
+
if (queuedStatements.length > 0) {
|
|
2056
|
+
const batchStatements = [
|
|
2057
|
+
{
|
|
2058
|
+
sql: 'BEGIN',
|
|
2059
|
+
params: []
|
|
2060
|
+
},
|
|
2061
|
+
...queuedStatements,
|
|
2062
|
+
{
|
|
2063
|
+
sql: 'COMMIT',
|
|
2064
|
+
params: []
|
|
2065
|
+
}
|
|
2066
|
+
];
|
|
2067
|
+
await this.client.sql.batch(batchStatements);
|
|
2068
|
+
}
|
|
1847
2069
|
return result;
|
|
1848
2070
|
} catch (error) {
|
|
1849
|
-
await this.execute('ROLLBACK');
|
|
1850
2071
|
throw error;
|
|
1851
2072
|
} finally{
|
|
1852
2073
|
this.inTransaction = false;
|
|
@@ -1860,6 +2081,12 @@ var __webpack_exports__ = {};
|
|
|
1860
2081
|
const { createORM } = __webpack_require__("./src/orm/index.ts");
|
|
1861
2082
|
return createORM(this);
|
|
1862
2083
|
}
|
|
2084
|
+
async ensureNamespaces(namespaces) {
|
|
2085
|
+
return this.client.httpClient.ensureNamespaces(namespaces);
|
|
2086
|
+
}
|
|
2087
|
+
async getNamespaces() {
|
|
2088
|
+
return this.client.httpClient.getNamespaces();
|
|
2089
|
+
}
|
|
1863
2090
|
}
|
|
1864
2091
|
function parseSQL(sqlContent, options = {}) {
|
|
1865
2092
|
const separatePragma = options.separatePragma ?? true;
|