@pineliner/odb-client 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/README.md ADDED
@@ -0,0 +1,316 @@
1
+ # ODBLite Client
2
+
3
+ A TypeScript/JavaScript client for ODBLite that provides a postgres.js-like interface for LibSQL databases. This isomorphic client transforms template string SQL to LibSQL JSON format while maintaining familiar syntax.
4
+
5
+ ## Features
6
+
7
+ - 🔄 **Isomorphic**: Works in Node.js, Bun, and browsers
8
+ - 📝 **Template String SQL**: postgres.js-style template literals
9
+ - 🛡️ **Type Safe**: Full TypeScript support with generics
10
+ - ⚡ **HTTP-based**: Communicates with ODBLite service over HTTP
11
+ - 🔄 **Retry Logic**: Built-in connection retry with exponential backoff
12
+ - 🎯 **LibSQL Compatible**: Optimized for LibSQL/SQLite databases
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @your-org/odblite-client
18
+ # or
19
+ bun add @your-org/odblite-client
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ **🎯 SUPPORTS BOTH QUERY STYLES** - See [QUERY_STYLES.md](./QUERY_STYLES.md) for full documentation
25
+
26
+ ### Style 1: Template Strings (postgres.js-like)
27
+
28
+ ```typescript
29
+ import { odblite } from '@pineliner/odb-client';
30
+
31
+ const sql = odblite({
32
+ baseUrl: 'http://localhost:8671',
33
+ apiKey: 'your-api-key',
34
+ databaseId: 'your-database-hash'
35
+ });
36
+
37
+ // Template string queries
38
+ const users = await sql`SELECT * FROM users WHERE age > ${25}`;
39
+ const user = await sql`SELECT * FROM users WHERE id = ${userId}`;
40
+ ```
41
+
42
+ ### Style 2: Query Method (? placeholders)
43
+
44
+ ```typescript
45
+ import { odblite } from '@pineliner/odb-client';
46
+
47
+ const sql = odblite({
48
+ baseUrl: 'http://localhost:8671',
49
+ apiKey: 'your-api-key',
50
+ databaseId: 'your-database-hash'
51
+ });
52
+
53
+ // Query method with parameters
54
+ const users = await sql.query('SELECT * FROM users WHERE age > ?', [25]);
55
+ const user = await sql.query('SELECT * FROM users WHERE id = ?', [userId]);
56
+ ```
57
+
58
+ **👉 Both styles work identically! Choose what you prefer.**
59
+
60
+ // Context-aware sql() - detects WHERE conditions automatically!
61
+ const activeUsers = await sql`
62
+ SELECT * FROM users
63
+ WHERE ${sql({ active: true, role: ['admin', 'user'] })} // Arrays = IN clauses!
64
+ `;
65
+
66
+ // Transactions work exactly like postgres.js with context-aware tx()!
67
+ const tx = await sql.begin();
68
+ await tx`INSERT INTO users ${tx({ name: 'John', age: 30 })}`;
69
+ await tx`UPDATE users SET ${tx({ active: true })} WHERE id = 1`;
70
+ await tx.commit();
71
+ ```
72
+
73
+ ## API Reference
74
+
75
+ ### Factory Functions
76
+
77
+ ```typescript
78
+ // With config object - returns callable sql function
79
+ const sql = odblite({
80
+ baseUrl: 'http://localhost:3000',
81
+ apiKey: 'your-api-key',
82
+ databaseId: 'your-database-id',
83
+ timeout: 30000,
84
+ retries: 3
85
+ });
86
+
87
+ // With individual parameters - returns callable sql function
88
+ const sql = odblite('http://localhost:3000', 'your-api-key', 'your-database-id');
89
+ ```
90
+
91
+ ### Template String Queries (Identical to postgres.js!)
92
+
93
+ ```typescript
94
+ // Basic queries - sql is directly callable!
95
+ const users = await sql`SELECT * FROM users`;
96
+ const user = await sql`SELECT * FROM users WHERE id = ${id}`;
97
+
98
+ // Array values (IN clauses)
99
+ const users = await sql`SELECT * FROM users WHERE id IN ${[1, 2, 3]}`;
100
+
101
+ // Object values - context-aware!
102
+ await sql`UPDATE users SET ${userUpdate} WHERE id = ${id}`;
103
+ ```
104
+
105
+ ### Context-Aware sql() Function
106
+
107
+ The `sql()` function intelligently detects the context and formats accordingly:
108
+
109
+ ```typescript
110
+ // WHERE conditions - detects null/array values
111
+ const conditions = sql({
112
+ active: true,
113
+ deleted_at: null, // Becomes "IS NULL"
114
+ id: [1, 2, 3], // Becomes "IN (?, ?, ?)"
115
+ name: 'John' // Becomes "= ?"
116
+ });
117
+ // Result: "active" = ? AND "deleted_at" IS NULL AND "id" IN (?, ?, ?) AND "name" = ?
118
+
119
+ // SET clauses - detects simple objects
120
+ const setData = sql({ name: 'John', age: 30 });
121
+ // Result: "name" = ?, "age" = ?
122
+
123
+ // INSERT VALUES - detects arrays of objects
124
+ const insertData = sql([
125
+ { name: 'John', age: 30 },
126
+ { name: 'Jane', age: 25 }
127
+ ]);
128
+ // Result: ("name", "age") VALUES (?, ?), (?, ?)
129
+
130
+ // IN clauses - detects primitive arrays
131
+ const inClause = sql([1, 2, 3]);
132
+ // Result: (?, ?, ?)
133
+ ```
134
+
135
+ ### Raw Query Method
136
+
137
+ ```typescript
138
+ const result = await sql.query('SELECT * FROM users WHERE id = ?', [123]);
139
+ ```
140
+
141
+ ### Utility Methods (Minimal)
142
+
143
+ ```typescript
144
+ // Raw SQL (unescaped) - for table/column names
145
+ const tableName = sql.raw('users');
146
+ await sql`SELECT * FROM ${tableName}`;
147
+
148
+ // Identifier escaping - for dynamic column names
149
+ const columnName = sql.identifier('user-name');
150
+ await sql`SELECT ${columnName} FROM users`;
151
+
152
+ // Everything else uses context-aware sql()!
153
+ const whereClause = sql({
154
+ active: true,
155
+ role: ['admin', 'user'],
156
+ created_at: null
157
+ });
158
+ await sql`SELECT * FROM users WHERE ${whereClause}`;
159
+
160
+ const insertClause = sql([
161
+ { name: 'John', age: 30 },
162
+ { name: 'Jane', age: 25 }
163
+ ]);
164
+ await sql`INSERT INTO users ${insertClause}`;
165
+
166
+ const setClause = sql({ name: 'John', age: 31 });
167
+ await sql`UPDATE users SET ${setClause} WHERE id = ${id}`;
168
+ ```
169
+
170
+ ### Transactions (Context-Aware Like Main sql Function!)
171
+
172
+ ```typescript
173
+ // Begin transaction - returns callable transaction function with context detection
174
+ const tx = await sql.begin();
175
+
176
+ try {
177
+ // tx() is context-aware just like sql()!
178
+ await tx`INSERT INTO users ${tx({ name: 'John', email: 'john@example.com' })}`;
179
+ await tx`UPDATE settings SET ${tx({ last_user: 'John', updated_at: new Date() })}`;
180
+
181
+ // Use WHERE conditions in transactions
182
+ await tx`DELETE FROM temp_data WHERE ${tx({ expired: true, created_at: null })}`;
183
+
184
+ await tx.commit();
185
+ } catch (error) {
186
+ await tx.rollback();
187
+ throw error;
188
+ }
189
+
190
+ // Batch operations with context-aware tx()
191
+ const tx2 = await sql.begin();
192
+ const users = [
193
+ { name: 'Alice', email: 'alice@example.com' },
194
+ { name: 'Bob', email: 'bob@example.com' }
195
+ ];
196
+
197
+ await tx2`INSERT INTO users ${tx2(users)}`; // Automatic bulk insert detection!
198
+ await tx2.commit();
199
+ ```
200
+
201
+ ### Database Management
202
+
203
+ ```typescript
204
+ // Switch database
205
+ sql.setDatabase('another-database-id');
206
+
207
+ // Health check
208
+ const isHealthy = await sql.ping();
209
+
210
+ // Get database info
211
+ const info = await sql.getDatabaseInfo();
212
+
213
+ // Create new client with different config
214
+ const newSql = sql.configure({ timeout: 60000 });
215
+ ```
216
+
217
+ ### Error Handling
218
+
219
+ ```typescript
220
+ import { QueryError, ConnectionError } from '@your-org/odblite-client';
221
+
222
+ try {
223
+ await sql`SELECT * FROM users WHERE invalid_column = ${value}`;
224
+ } catch (error) {
225
+ if (error instanceof QueryError) {
226
+ console.log('SQL Error:', error.message);
227
+ console.log('Query:', error.query);
228
+ console.log('Params:', error.params);
229
+ } else if (error instanceof ConnectionError) {
230
+ console.log('Connection Error:', error.message);
231
+ }
232
+ }
233
+ ```
234
+
235
+ ## Type Safety
236
+
237
+ ```typescript
238
+ interface User {
239
+ id: number;
240
+ name: string;
241
+ email: string;
242
+ created_at: string;
243
+ }
244
+
245
+ // Typed query results
246
+ const users = await sql<User>`SELECT * FROM users`;
247
+ // users.rows is User[]
248
+
249
+ const user = await sql<User>`SELECT * FROM users WHERE id = ${1}`;
250
+ // user.rows[0] is User | undefined
251
+ ```
252
+
253
+ ## Configuration Options
254
+
255
+ ```typescript
256
+ interface ODBLiteConfig {
257
+ baseUrl: string; // ODBLite service URL
258
+ apiKey: string; // API authentication key
259
+ databaseId?: string; // Target database ID
260
+ timeout?: number; // Request timeout (default: 30000ms)
261
+ retries?: number; // Retry attempts (default: 3)
262
+ }
263
+ ```
264
+
265
+ ## Query Result Format
266
+
267
+ ```typescript
268
+ interface QueryResult<T> {
269
+ rows: T[]; // Query result rows
270
+ rowsAffected: number; // Number of affected rows
271
+ executionTime: number; // Query execution time in ms
272
+ databaseName?: string; // Database name
273
+ }
274
+ ```
275
+
276
+ ## Comparison with postgres.js
277
+
278
+ This client provides a similar API to postgres.js but optimized for LibSQL:
279
+
280
+ ```typescript
281
+ // postgres.js style - works the same!
282
+ const users = await sql`SELECT * FROM users WHERE age > ${25}`;
283
+ const user = await sql`SELECT * FROM users WHERE id = ${userId}`;
284
+
285
+ // Object destructuring
286
+ const [user] = await sql`SELECT * FROM users WHERE id = ${1}`;
287
+
288
+ // Template string power
289
+ const searchTerm = 'john';
290
+ const users = await sql`
291
+ SELECT * FROM users
292
+ WHERE name ILIKE ${'%' + searchTerm + '%'}
293
+ ORDER BY created_at DESC
294
+ LIMIT ${10}
295
+ `;
296
+ ```
297
+
298
+ ## Development
299
+
300
+ ```bash
301
+ # Install dependencies
302
+ bun install
303
+
304
+ # Run tests
305
+ bun test
306
+
307
+ # Build
308
+ bun run build
309
+
310
+ # Type check
311
+ bun run typecheck
312
+ ```
313
+
314
+ ## License
315
+
316
+ MIT
@@ -0,0 +1,110 @@
1
+ import type { ODBLiteConfig, ODBLiteConnection, QueryResult, Transaction, TransactionCallback, TransactionMode, SQLFragment } from '../types.ts';
2
+ interface SQLFunction {
3
+ <T = any>(sql: TemplateStringsArray, ...values: any[]): Promise<QueryResult<T>>;
4
+ <T = any>(input: any): SQLFragment;
5
+ raw(text: string): string;
6
+ identifier(name: string): string;
7
+ query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
8
+ execute<T = any>(sql: string | {
9
+ sql: string;
10
+ args?: any[];
11
+ }, args?: any[]): Promise<QueryResult<T>>;
12
+ begin(): Promise<Transaction>;
13
+ begin<T>(callback: TransactionCallback<T>): Promise<T>;
14
+ begin<T>(mode: TransactionMode, callback: TransactionCallback<T>): Promise<T>;
15
+ ping(): Promise<boolean>;
16
+ end(): Promise<void>;
17
+ setDatabase(databaseId: string): SQLFunction;
18
+ getDatabaseInfo(): Promise<any>;
19
+ configure(updates: Partial<ODBLiteConfig>): SQLFunction;
20
+ }
21
+ /**
22
+ * Main ODBLite client that provides postgres.js-like interface
23
+ */
24
+ export declare class ODBLiteClient implements ODBLiteConnection {
25
+ private httpClient;
26
+ config: ODBLiteConfig;
27
+ sql: SQLFunction;
28
+ constructor(config: ODBLiteConfig);
29
+ /**
30
+ * Execute a transaction with callback (postgres.js style)
31
+ */
32
+ private executeTransactionWithCallback;
33
+ /**
34
+ * Raw query method
35
+ * Usage: client.query('SELECT * FROM users WHERE id = ?', [123])
36
+ */
37
+ query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
38
+ /**
39
+ * Begin a transaction
40
+ * Note: Uses simple transaction model suitable for HTTP-based access
41
+ */
42
+ begin(): Promise<Transaction>;
43
+ /**
44
+ * Health check
45
+ */
46
+ ping(): Promise<boolean>;
47
+ /**
48
+ * Close connection (no-op for HTTP client)
49
+ */
50
+ end(): Promise<void>;
51
+ /**
52
+ * Set the database ID for queries
53
+ */
54
+ setDatabase(databaseId: string): this;
55
+ /**
56
+ * Get database information
57
+ */
58
+ getDatabaseInfo(): Promise<any>;
59
+ /**
60
+ * Create a new client instance with updated configuration
61
+ */
62
+ configure(updates: Partial<ODBLiteConfig>): ODBLiteClient;
63
+ /**
64
+ * Create raw SQL that won't be parameterized
65
+ * Usage: sql`SELECT * FROM ${raw('users')}`
66
+ */
67
+ static raw(text: string): string;
68
+ /**
69
+ * Escape identifier (table/column names)
70
+ * Usage: sql`SELECT * FROM ${identifier('user-table')}`
71
+ */
72
+ static identifier(name: string): string;
73
+ /**
74
+ * Build WHERE clause from object
75
+ * Usage: const whereClause = ODBLiteClient.where({ id: 1, name: 'John' });
76
+ */
77
+ static where(conditions: Record<string, any>): SQLFragment;
78
+ /**
79
+ * Build INSERT VALUES from object(s)
80
+ * Usage: const insertClause = ODBLiteClient.insertValues({ name: 'John', age: 30 });
81
+ */
82
+ static insertValues(data: Record<string, any> | Record<string, any>[]): SQLFragment;
83
+ /**
84
+ * Build UPDATE SET clause from object
85
+ * Usage: const setClause = ODBLiteClient.updateSet({ name: 'John', age: 30 });
86
+ */
87
+ static updateSet(data: Record<string, any>): SQLFragment;
88
+ /**
89
+ * Join SQL fragments
90
+ * Usage: const query = ODBLiteClient.join([baseQuery, whereClause], ' WHERE ');
91
+ */
92
+ static join(fragments: Array<{
93
+ text: string;
94
+ values: any[];
95
+ }>, separator?: string): SQLFragment;
96
+ }
97
+ /**
98
+ * Factory function to create ODBLite client (postgres.js style)
99
+ * Returns the sql function directly, not the client class
100
+ */
101
+ export declare function odblite(config: ODBLiteConfig): SQLFunction;
102
+ export declare function odblite(baseUrl: string, apiKey: string, databaseId?: string): SQLFunction;
103
+ export declare const raw: typeof ODBLiteClient.raw;
104
+ export declare const identifier: typeof ODBLiteClient.identifier;
105
+ export declare const where: typeof ODBLiteClient.where;
106
+ export declare const insertValues: typeof ODBLiteClient.insertValues;
107
+ export declare const updateSet: typeof ODBLiteClient.updateSet;
108
+ export declare const join: typeof ODBLiteClient.join;
109
+ export {};
110
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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;AAOjJ,UAAU,WAAW;IAEnB,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,C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AAA;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"}
@@ -0,0 +1,37 @@
1
+ import type { ODBLiteConfig, QueryResult } from '../types.ts';
2
+ /**
3
+ * HTTP client for communicating with ODBLite service
4
+ */
5
+ export declare class HTTPClient {
6
+ private config;
7
+ constructor(config: ODBLiteConfig);
8
+ /**
9
+ * Execute a query against the ODBLite service
10
+ */
11
+ query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
12
+ /**
13
+ * Check database health
14
+ */
15
+ ping(): Promise<boolean>;
16
+ /**
17
+ * Get database information
18
+ */
19
+ getDatabaseInfo(): Promise<any>;
20
+ /**
21
+ * Set the database ID for subsequent queries
22
+ */
23
+ setDatabase(databaseId: string): void;
24
+ /**
25
+ * Make HTTP request with retry logic
26
+ */
27
+ private makeRequest;
28
+ /**
29
+ * Create a new HTTPClient with updated config
30
+ */
31
+ configure(updates: Partial<ODBLiteConfig>): HTTPClient;
32
+ /**
33
+ * Get current configuration
34
+ */
35
+ getConfig(): Readonly<ODBLiteConfig>;
36
+ }
37
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +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,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAoD9E;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAqB9B;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,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;CAGrC"}
@@ -0,0 +1,70 @@
1
+ import type { SQLFragment, PreparedQuery } from '../types.ts';
2
+ /**
3
+ * SQL template string parser that converts postgres.js-style template strings
4
+ * into LibSQL-compatible parameterized queries
5
+ */
6
+ export declare class SQLParser {
7
+ /**
8
+ * Parse input that can be template strings, objects, or arrays
9
+ * Context-aware like postgres.js
10
+ */
11
+ static parse(sql: TemplateStringsArray | any, values?: any[]): PreparedQuery;
12
+ /**
13
+ * Parse contextual input (objects, arrays, etc.)
14
+ * Uses heuristics to detect the intended context
15
+ */
16
+ private static parseContextualInput;
17
+ /**
18
+ * Build a SET clause for UPDATE statements
19
+ */
20
+ private static buildSetClause;
21
+ /**
22
+ * Parse template string SQL into LibSQL format
23
+ */
24
+ private static parseTemplateString;
25
+ /**
26
+ * Create a raw SQL fragment (not parameterized)
27
+ */
28
+ static raw(text: string): string;
29
+ /**
30
+ * Create an identifier (table name, column name, etc.)
31
+ */
32
+ static identifier(name: string): string;
33
+ /**
34
+ * Escape SQL identifiers (table names, column names)
35
+ */
36
+ private static escapeIdentifier;
37
+ /**
38
+ * Convert JavaScript values to LibSQL-compatible values
39
+ */
40
+ private static convertValue;
41
+ /**
42
+ * Create a SQL fragment for building complex queries
43
+ */
44
+ static fragment(sql: TemplateStringsArray, ...values: any[]): SQLFragment;
45
+ /**
46
+ * Join multiple SQL fragments
47
+ */
48
+ static join(fragments: SQLFragment[], separator?: string): SQLFragment;
49
+ /**
50
+ * Helper for building WHERE clauses from objects
51
+ */
52
+ static where(conditions: Record<string, any>): SQLFragment;
53
+ /**
54
+ * Helper for building INSERT VALUES from objects
55
+ */
56
+ static insertValues(data: Record<string, any> | Record<string, any>[]): SQLFragment;
57
+ /**
58
+ * Helper for building UPDATE SET clauses from objects
59
+ */
60
+ static updateSet(data: Record<string, any>): SQLFragment;
61
+ }
62
+ export declare const sql: typeof SQLParser.parse;
63
+ export declare const raw: typeof SQLParser.raw;
64
+ export declare const identifier: typeof SQLParser.identifier;
65
+ export declare const fragment: typeof SQLParser.fragment;
66
+ export declare const join: typeof SQLParser.join;
67
+ export declare const where: typeof SQLParser.where;
68
+ export declare const insertValues: typeof SQLParser.insertValues;
69
+ export declare const updateSet: typeof SQLParser.updateSet;
70
+ //# sourceMappingURL=sql-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-parser.d.ts","sourceRoot":"","sources":["../../src/core/sql-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAkB,MAAM,aAAa,CAAC;AAE9E;;;GAGG;AACH,qBAAa,SAAS;IACpB;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,oBAAoB,GAAG,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,aAAa;IAU5E;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAyEnC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAgB7B;;OAEG;IACH,OA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TTPClient } from './http-client.ts';
3
+ /**
4
+ * Create a transaction function similar to the main sql function
5
+ */
6
+ export declare function createTransaction(httpClient: HTTPClient): Transaction;
7
+ /**
8
+ * Transaction implementation for ODBLite
9
+ * Note: SQLite transactions are simulated at the client level since ODBLite
10
+ * operates on individual queries. This provides a familiar API but doesn't
11
+ * provide true ACID guarantees across multiple HTTP requests.
12
+ */
13
+ export declare class ODBLiteTransaction {
14
+ private httpClient;
15
+ private isCommitted;
16
+ private isRolledBack;
17
+ private queries;
18
+ constructor(httpClient: HTTPClient);
19
+ /**
20
+ * Execute a query within the transaction
21
+ * For SQLite, we'll queue queries and execute them in batch on commit
22
+ */
23
+ sql<T = any>(sql: TemplateStringsArray, ...values: any[]): Promise<QueryResult<T>>;
24
+ /**
25
+ * Commit the transaction by executing all queued queries
26
+ */
27
+ commit(): Promise<void>;
28
+ /**
29
+ * Rollback the transaction
30
+ */
31
+ rollback(): Promise<void>;
32
+ /**
33
+ * Check if transaction is still active
34
+ */
35
+ private checkTransactionState;
36
+ /**
37
+ * Determine if a query is a read operation
38
+ */
39
+ private isReadQuery;
40
+ }
41
+ /**
42
+ * Create a simple transaction function that executes immediately
43
+ * This is more suitable for HTTP-based databases where true transactions
44
+ * across multiple requests are not practical
45
+ */
46
+ export declare function createSimpleTransaction(httpClient: HTTPClient): Transaction;
47
+ /**
48
+ * Simple transaction implementation that executes immediately
49
+ * This is more suitable for HTTP-based databases where true transactions
50
+ * across multiple requests are not practical
51
+ */
52
+ export declare class SimpleTransaction {
53
+ private httpClient;
54
+ private isActive;
55
+ constructor(httpClient: HTTPClient);
56
+ sql<T = any>(sql: TemplateStringsArray, ...values: any[]): Promise<QueryResult<T>>;
57
+ commit(): Promise<void>;
58
+ rollback(): Promise<void>;
59
+ }
60
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/core/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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