@mastra/cloudflare-d1 0.0.0-support-d1-client-20250701191943 → 0.0.0-suspendRuntimeContextTypeFix-20250930142630

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.
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Type definition for SQL query parameters
3
+ */
4
+ export type SqlParam = string | number | boolean | null | undefined;
5
+ /**
6
+ * Interface for SQL query options with generic type support
7
+ */
8
+ export interface SqlQueryOptions {
9
+ /** SQL query to execute */
10
+ sql: string;
11
+ /** Parameters to bind to the query */
12
+ params?: SqlParam[];
13
+ /** Whether to return only the first result */
14
+ first?: boolean;
15
+ }
16
+ /**
17
+ * SQL Builder class for constructing type-safe SQL queries
18
+ * This helps create maintainable and secure SQL queries with proper parameter handling
19
+ */
20
+ export declare class SqlBuilder {
21
+ private sql;
22
+ private params;
23
+ private whereAdded;
24
+ select(columns?: string | string[]): SqlBuilder;
25
+ from(table: string): SqlBuilder;
26
+ /**
27
+ * Add a WHERE clause to the query
28
+ * @param condition The condition to add
29
+ * @param params Parameters to bind to the condition
30
+ */
31
+ where(condition: string, ...params: SqlParam[]): SqlBuilder;
32
+ /**
33
+ * Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
34
+ * @param condition The condition to add
35
+ * @param params Parameters to bind to the condition
36
+ */
37
+ whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
38
+ andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
39
+ orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
40
+ orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
41
+ limit(count: number): SqlBuilder;
42
+ offset(count: number): SqlBuilder;
43
+ count(): SqlBuilder;
44
+ /**
45
+ * Insert a row, or update specific columns on conflict (upsert).
46
+ * @param table Table name
47
+ * @param columns Columns to insert
48
+ * @param values Values to insert
49
+ * @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
50
+ * @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
51
+ */
52
+ insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
53
+ update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
54
+ delete(table: string): SqlBuilder;
55
+ /**
56
+ * Create a table if it doesn't exist
57
+ * @param table The table name
58
+ * @param columnDefinitions The column definitions as an array of strings
59
+ * @param tableConstraints Optional constraints for the table
60
+ * @returns The builder instance
61
+ */
62
+ createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
63
+ /**
64
+ * Check if an index exists in the database
65
+ * @param indexName The name of the index to check
66
+ * @param tableName The table the index is on
67
+ * @returns The builder instance
68
+ */
69
+ checkIndexExists(indexName: string, tableName: string): SqlBuilder;
70
+ /**
71
+ * Create an index if it doesn't exist
72
+ * @param indexName The name of the index to create
73
+ * @param tableName The table to create the index on
74
+ * @param columnName The column to index
75
+ * @param indexType Optional index type (e.g., 'UNIQUE')
76
+ * @returns The builder instance
77
+ */
78
+ createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
79
+ /**
80
+ * Add a LIKE condition to the query
81
+ * @param column The column to check
82
+ * @param value The value to match (will be wrapped with % for LIKE)
83
+ * @param exact If true, will not add % wildcards
84
+ */
85
+ like(column: string, value: string, exact?: boolean): SqlBuilder;
86
+ /**
87
+ * Add a JSON LIKE condition for searching in JSON fields
88
+ * @param column The JSON column to search in
89
+ * @param key The JSON key to match
90
+ * @param value The value to match
91
+ */
92
+ jsonLike(column: string, key: string, value: string): SqlBuilder;
93
+ /**
94
+ * Get the built query
95
+ * @returns Object containing the SQL string and parameters array
96
+ */
97
+ build(): {
98
+ sql: string;
99
+ params: SqlParam[];
100
+ };
101
+ /**
102
+ * Reset the builder for reuse
103
+ * @returns The reset builder instance
104
+ */
105
+ reset(): SqlBuilder;
106
+ }
107
+ export declare function createSqlBuilder(): SqlBuilder;
108
+ /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
109
+ type SelectIdentifier = string & {
110
+ __brand: 'SelectIdentifier';
111
+ };
112
+ /**
113
+ * Parses and returns a valid SQL SELECT column identifier.
114
+ * Allows a single identifier (letters, numbers, underscores), or '*', optionally with 'AS alias'.
115
+ *
116
+ * @param column - The column identifier string to parse.
117
+ * @returns The validated column identifier as a branded type.
118
+ * @throws {Error} If invalid.
119
+ *
120
+ * @example
121
+ * const col = parseSelectIdentifier('user_id'); // Ok
122
+ * parseSelectIdentifier('user_id AS uid'); // Ok
123
+ * parseSelectIdentifier('*'); // Ok
124
+ * parseSelectIdentifier('user id'); // Throws error
125
+ */
126
+ export declare function parseSelectIdentifier(column: string): SelectIdentifier;
127
+ export {};
128
+ //# sourceMappingURL=sql-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-builder.d.ts","sourceRoot":"","sources":["../../src/storage/sql-builder.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,19 @@
1
+ export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
2
+ id: string;
3
+ parentSpanId: string;
4
+ traceId: string;
5
+ name: string;
6
+ scope: string | undefined;
7
+ kind: string;
8
+ status: string;
9
+ events: string;
10
+ links: string;
11
+ attributes: string | undefined;
12
+ startTime: string;
13
+ endTime: string;
14
+ other: string;
15
+ createdAt: string;
16
+ };
17
+ export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
18
+ interval?: number) => Promise<T>;
19
+ //# sourceMappingURL=test-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/storage/test-utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,EAAE,aAAa,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;;;;;;;;;;;CAejG,CAAC;AAGH,eAAO,MAAM,UAAU,GAAU,CAAC,EAChC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,EACjC,gBAAe,EAAE,sDAAsD;AACvE,iBAAe,KACd,OAAO,CAAC,CAAC,CAYX,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@mastra/cloudflare-d1",
3
- "version": "0.0.0-support-d1-client-20250701191943",
3
+ "version": "0.0.0-suspendRuntimeContextTypeFix-20250930142630",
4
4
  "description": "D1 provider for Mastra - includes db storage capabilities",
5
5
  "type": "module",
6
6
  "files": [
7
- "dist"
7
+ "dist",
8
+ "CHANGELOG.md"
8
9
  ],
9
10
  "main": "dist/index.js",
10
11
  "types": "dist/index.d.ts",
@@ -15,35 +16,45 @@
15
16
  "default": "./dist/index.js"
16
17
  },
17
18
  "require": {
18
- "types": "./dist/index.d.cts",
19
+ "types": "./dist/index.d.ts",
19
20
  "default": "./dist/index.cjs"
20
21
  }
21
22
  },
22
23
  "./package.json": "./package.json"
23
24
  },
24
25
  "dependencies": {
25
- "cloudflare": "^4.4.1"
26
+ "cloudflare": "^4.5.0"
26
27
  },
27
28
  "devDependencies": {
28
- "@cloudflare/workers-types": "^4.20250620.0",
29
+ "@cloudflare/workers-types": "^4.20250913.0",
29
30
  "@microsoft/api-extractor": "^7.52.8",
30
31
  "@types/node": "^20.19.0",
31
- "dotenv": "^16.5.0",
32
- "eslint": "^9.29.0",
33
- "miniflare": "^4.20250617.4",
32
+ "dotenv": "^17.0.0",
33
+ "eslint": "^9.35.0",
34
+ "miniflare": "^4.20250913.0",
34
35
  "tsup": "^8.5.0",
35
36
  "typescript": "^5.8.3",
36
37
  "vitest": "^3.2.4",
37
- "@internal/lint": "0.0.0-support-d1-client-20250701191943",
38
- "@internal/storage-test-utils": "0.0.11",
39
- "@mastra/core": "0.0.0-support-d1-client-20250701191943"
38
+ "@internal/storage-test-utils": "0.0.38",
39
+ "@internal/lint": "0.0.0-suspendRuntimeContextTypeFix-20250930142630",
40
+ "@mastra/core": "0.0.0-suspendRuntimeContextTypeFix-20250930142630",
41
+ "@internal/types-builder": "0.0.0-suspendRuntimeContextTypeFix-20250930142630"
40
42
  },
41
43
  "peerDependencies": {
42
- "@mastra/core": "0.0.0-support-d1-client-20250701191943"
44
+ "@mastra/core": "0.0.0-suspendRuntimeContextTypeFix-20250930142630"
45
+ },
46
+ "homepage": "https://mastra.ai",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/mastra-ai/mastra.git",
50
+ "directory": "stores/cloudflare-d1"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/mastra-ai/mastra/issues"
43
54
  },
44
55
  "scripts": {
45
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
46
- "build:watch": "pnpm build --watch",
56
+ "build": "tsup --silent --config tsup.config.ts",
57
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
47
58
  "test": "vitest run",
48
59
  "lint": "eslint ."
49
60
  }
@@ -1,422 +0,0 @@
1
- import { default as Cloudflare_2 } from 'cloudflare';
2
- import type { D1Database as D1Database_2 } from '@cloudflare/workers-types';
3
- import type { EvalRow } from '@mastra/core/storage';
4
- import type { MastraMessageContentV2 } from '@mastra/core/agent';
5
- import type { MastraMessageV1 } from '@mastra/core/memory';
6
- import type { MastraMessageV2 } from '@mastra/core/memory';
7
- import { MastraStorage } from '@mastra/core/storage';
8
- import type { PaginationInfo } from '@mastra/core/storage';
9
- import type { StorageColumn } from '@mastra/core/storage';
10
- import type { StorageGetMessagesArg } from '@mastra/core/storage';
11
- import type { StorageThreadType } from '@mastra/core/memory';
12
- import type { TABLE_NAMES } from '@mastra/core/storage';
13
- import type { Trace } from '@mastra/core/telemetry';
14
- import type { WorkflowRun } from '@mastra/core/storage';
15
- import type { WorkflowRuns } from '@mastra/core/storage';
16
- import type { WorkflowRunState } from '@mastra/core/workflows';
17
-
18
- export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
19
- id: string;
20
- parentSpanId: string;
21
- traceId: string;
22
- name: string;
23
- scope: string | undefined;
24
- kind: string;
25
- status: string;
26
- events: string;
27
- links: string;
28
- attributes: string | undefined;
29
- startTime: string;
30
- endTime: string;
31
- other: string;
32
- createdAt: string;
33
- };
34
-
35
- export declare function createSqlBuilder(): SqlBuilder;
36
-
37
- declare interface D1Client {
38
- query(args: {
39
- sql: string;
40
- params: string[];
41
- }): Promise<{
42
- result: D1QueryResult;
43
- }>;
44
- }
45
- export { D1Client }
46
- export { D1Client as D1Client_alias_1 }
47
-
48
- declare interface D1ClientConfig {
49
- /** Optional prefix for table names */
50
- tablePrefix?: string;
51
- /** D1 Client */
52
- client: D1Client;
53
- }
54
- export { D1ClientConfig }
55
- export { D1ClientConfig as D1ClientConfig_alias_1 }
56
-
57
- /**
58
- * Configuration for D1 using the REST API
59
- */
60
- declare interface D1Config {
61
- /** Cloudflare account ID */
62
- accountId: string;
63
- /** Cloudflare API token with D1 access */
64
- apiToken: string;
65
- /** D1 database ID */
66
- databaseId: string;
67
- /** Optional prefix for table names */
68
- tablePrefix?: string;
69
- }
70
- export { D1Config }
71
- export { D1Config as D1Config_alias_1 }
72
-
73
- declare type D1QueryResult = Awaited<ReturnType<Cloudflare_2['d1']['database']['query']>>['result'];
74
- export { D1QueryResult }
75
- export { D1QueryResult as D1QueryResult_alias_1 }
76
-
77
- declare class D1Store extends MastraStorage {
78
- private client?;
79
- private binding?;
80
- private tablePrefix;
81
- /**
82
- * Creates a new D1Store instance
83
- * @param config Configuration for D1 access (either REST API or Workers Binding API)
84
- */
85
- constructor(config: D1StoreConfig);
86
- private getTableName;
87
- private formatSqlParams;
88
- private executeWorkersBindingQuery;
89
- private executeRestQuery;
90
- /**
91
- * Execute a SQL query against the D1 database
92
- * @param options Query options including SQL, parameters, and whether to return only the first result
93
- * @returns Query results as an array or a single object if first=true
94
- */
95
- private executeQuery;
96
- private getTableColumns;
97
- private serializeValue;
98
- private deserializeValue;
99
- protected getSqlType(type: StorageColumn['type']): string;
100
- createTable({ tableName, schema, }: {
101
- tableName: TABLE_NAMES;
102
- schema: Record<string, StorageColumn>;
103
- }): Promise<void>;
104
- /**
105
- * Alters table schema to add columns if they don't exist
106
- * @param tableName Name of the table
107
- * @param schema Schema of the table
108
- * @param ifNotExists Array of column names to add if they don't exist
109
- */
110
- alterTable({ tableName, schema, ifNotExists, }: {
111
- tableName: TABLE_NAMES;
112
- schema: Record<string, StorageColumn>;
113
- ifNotExists: string[];
114
- }): Promise<void>;
115
- clearTable({ tableName }: {
116
- tableName: TABLE_NAMES;
117
- }): Promise<void>;
118
- private processRecord;
119
- insert({ tableName, record }: {
120
- tableName: TABLE_NAMES;
121
- record: Record<string, any>;
122
- }): Promise<void>;
123
- load<R>({ tableName, keys }: {
124
- tableName: TABLE_NAMES;
125
- keys: Record<string, string>;
126
- }): Promise<R | null>;
127
- getThreadById({ threadId }: {
128
- threadId: string;
129
- }): Promise<StorageThreadType | null>;
130
- /**
131
- * @deprecated use getThreadsByResourceIdPaginated instead
132
- */
133
- getThreadsByResourceId({ resourceId }: {
134
- resourceId: string;
135
- }): Promise<StorageThreadType[]>;
136
- getThreadsByResourceIdPaginated(args: {
137
- resourceId: string;
138
- page: number;
139
- perPage: number;
140
- }): Promise<PaginationInfo & {
141
- threads: StorageThreadType[];
142
- }>;
143
- saveThread({ thread }: {
144
- thread: StorageThreadType;
145
- }): Promise<StorageThreadType>;
146
- updateThread({ id, title, metadata, }: {
147
- id: string;
148
- title: string;
149
- metadata: Record<string, unknown>;
150
- }): Promise<StorageThreadType>;
151
- deleteThread({ threadId }: {
152
- threadId: string;
153
- }): Promise<void>;
154
- saveMessages(args: {
155
- messages: MastraMessageV1[];
156
- format?: undefined | 'v1';
157
- }): Promise<MastraMessageV1[]>;
158
- saveMessages(args: {
159
- messages: MastraMessageV2[];
160
- format: 'v2';
161
- }): Promise<MastraMessageV2[]>;
162
- private _getIncludedMessages;
163
- /**
164
- * @deprecated use getMessagesPaginated instead
165
- */
166
- getMessages(args: StorageGetMessagesArg & {
167
- format?: 'v1';
168
- }): Promise<MastraMessageV1[]>;
169
- getMessages(args: StorageGetMessagesArg & {
170
- format: 'v2';
171
- }): Promise<MastraMessageV2[]>;
172
- getMessagesPaginated({ threadId, selectBy, format, }: StorageGetMessagesArg & {
173
- format?: 'v1' | 'v2';
174
- }): Promise<PaginationInfo & {
175
- messages: MastraMessageV1[] | MastraMessageV2[];
176
- }>;
177
- persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
178
- workflowName: string;
179
- runId: string;
180
- snapshot: WorkflowRunState;
181
- }): Promise<void>;
182
- loadWorkflowSnapshot(params: {
183
- workflowName: string;
184
- runId: string;
185
- }): Promise<WorkflowRunState | null>;
186
- /**
187
- * Insert multiple records in a batch operation
188
- * @param tableName The table to insert into
189
- * @param records The records to insert
190
- */
191
- batchInsert({ tableName, records }: {
192
- tableName: TABLE_NAMES;
193
- records: Record<string, any>[];
194
- }): Promise<void>;
195
- /**
196
- * Upsert multiple records in a batch operation
197
- * @param tableName The table to insert into
198
- * @param records The records to insert
199
- */
200
- private batchUpsert;
201
- /**
202
- * @deprecated use getTracesPaginated instead
203
- */
204
- getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
205
- name?: string;
206
- scope?: string;
207
- page: number;
208
- perPage: number;
209
- attributes?: Record<string, string>;
210
- fromDate?: Date;
211
- toDate?: Date;
212
- }): Promise<Trace[]>;
213
- getTracesPaginated(args: {
214
- name?: string;
215
- scope?: string;
216
- attributes?: Record<string, string>;
217
- page: number;
218
- perPage: number;
219
- fromDate?: Date;
220
- toDate?: Date;
221
- }): Promise<PaginationInfo & {
222
- traces: Trace[];
223
- }>;
224
- /**
225
- * @deprecated use getEvals instead
226
- */
227
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
228
- getEvals(options?: {
229
- agentName?: string;
230
- type?: 'test' | 'live';
231
- page?: number;
232
- perPage?: number;
233
- fromDate?: Date;
234
- toDate?: Date;
235
- }): Promise<PaginationInfo & {
236
- evals: EvalRow[];
237
- }>;
238
- private parseWorkflowRun;
239
- private hasColumn;
240
- getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
241
- workflowName?: string;
242
- fromDate?: Date;
243
- toDate?: Date;
244
- limit?: number;
245
- offset?: number;
246
- resourceId?: string;
247
- }): Promise<WorkflowRuns>;
248
- getWorkflowRunById({ runId, workflowName, }: {
249
- runId: string;
250
- workflowName?: string;
251
- }): Promise<WorkflowRun | null>;
252
- /**
253
- * Close the database connection
254
- * No explicit cleanup needed for D1 in either REST or Workers Binding mode
255
- */
256
- close(): Promise<void>;
257
- updateMessages(_args: {
258
- messages: Partial<Omit<MastraMessageV2, 'createdAt'>> & {
259
- id: string;
260
- content?: {
261
- metadata?: MastraMessageContentV2['metadata'];
262
- content?: MastraMessageContentV2['content'];
263
- };
264
- }[];
265
- }): Promise<MastraMessageV2[]>;
266
- }
267
- export { D1Store }
268
- export { D1Store as D1Store_alias_1 }
269
-
270
- /**
271
- * Combined configuration type supporting both REST API and Workers Binding API
272
- */
273
- declare type D1StoreConfig = D1Config | D1WorkersConfig | D1ClientConfig;
274
- export { D1StoreConfig }
275
- export { D1StoreConfig as D1StoreConfig_alias_1 }
276
-
277
- /**
278
- * Configuration for D1 using the Workers Binding API
279
- */
280
- declare interface D1WorkersConfig {
281
- /** D1 database binding from Workers environment */
282
- binding: D1Database_2;
283
- /** Optional prefix for table names */
284
- tablePrefix?: string;
285
- }
286
- export { D1WorkersConfig }
287
- export { D1WorkersConfig as D1WorkersConfig_alias_1 }
288
-
289
- /**
290
- * Parses and returns a valid SQL SELECT column identifier.
291
- * Allows a single identifier (letters, numbers, underscores), or '*', optionally with 'AS alias'.
292
- *
293
- * @param column - The column identifier string to parse.
294
- * @returns The validated column identifier as a branded type.
295
- * @throws {Error} If invalid.
296
- *
297
- * @example
298
- * const col = parseSelectIdentifier('user_id'); // Ok
299
- * parseSelectIdentifier('user_id AS uid'); // Ok
300
- * parseSelectIdentifier('*'); // Ok
301
- * parseSelectIdentifier('user id'); // Throws error
302
- */
303
- export declare function parseSelectIdentifier(column: string): SelectIdentifier;
304
-
305
- export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
306
- interval?: number) => Promise<T>;
307
-
308
- /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
309
- declare type SelectIdentifier = string & {
310
- __brand: 'SelectIdentifier';
311
- };
312
-
313
- /**
314
- * SQL Builder class for constructing type-safe SQL queries
315
- * This helps create maintainable and secure SQL queries with proper parameter handling
316
- */
317
- export declare class SqlBuilder {
318
- private sql;
319
- private params;
320
- private whereAdded;
321
- select(columns?: string | string[]): SqlBuilder;
322
- from(table: string): SqlBuilder;
323
- /**
324
- * Add a WHERE clause to the query
325
- * @param condition The condition to add
326
- * @param params Parameters to bind to the condition
327
- */
328
- where(condition: string, ...params: SqlParam[]): SqlBuilder;
329
- /**
330
- * Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
331
- * @param condition The condition to add
332
- * @param params Parameters to bind to the condition
333
- */
334
- whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
335
- andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
336
- orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
337
- orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
338
- limit(count: number): SqlBuilder;
339
- offset(count: number): SqlBuilder;
340
- count(): SqlBuilder;
341
- /**
342
- * Insert a row, or update specific columns on conflict (upsert).
343
- * @param table Table name
344
- * @param columns Columns to insert
345
- * @param values Values to insert
346
- * @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
347
- * @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
348
- */
349
- insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
350
- update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
351
- delete(table: string): SqlBuilder;
352
- /**
353
- * Create a table if it doesn't exist
354
- * @param table The table name
355
- * @param columnDefinitions The column definitions as an array of strings
356
- * @param tableConstraints Optional constraints for the table
357
- * @returns The builder instance
358
- */
359
- createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
360
- /**
361
- * Check if an index exists in the database
362
- * @param indexName The name of the index to check
363
- * @param tableName The table the index is on
364
- * @returns The builder instance
365
- */
366
- checkIndexExists(indexName: string, tableName: string): SqlBuilder;
367
- /**
368
- * Create an index if it doesn't exist
369
- * @param indexName The name of the index to create
370
- * @param tableName The table to create the index on
371
- * @param columnName The column to index
372
- * @param indexType Optional index type (e.g., 'UNIQUE')
373
- * @returns The builder instance
374
- */
375
- createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
376
- /**
377
- * Add a LIKE condition to the query
378
- * @param column The column to check
379
- * @param value The value to match (will be wrapped with % for LIKE)
380
- * @param exact If true, will not add % wildcards
381
- */
382
- like(column: string, value: string, exact?: boolean): SqlBuilder;
383
- /**
384
- * Add a JSON LIKE condition for searching in JSON fields
385
- * @param column The JSON column to search in
386
- * @param key The JSON key to match
387
- * @param value The value to match
388
- */
389
- jsonLike(column: string, key: string, value: string): SqlBuilder;
390
- /**
391
- * Get the built query
392
- * @returns Object containing the SQL string and parameters array
393
- */
394
- build(): {
395
- sql: string;
396
- params: SqlParam[];
397
- };
398
- /**
399
- * Reset the builder for reuse
400
- * @returns The reset builder instance
401
- */
402
- reset(): SqlBuilder;
403
- }
404
-
405
- /**
406
- * Type definition for SQL query parameters
407
- */
408
- export declare type SqlParam = string | number | boolean | null | undefined;
409
-
410
- /**
411
- * Interface for SQL query options with generic type support
412
- */
413
- export declare interface SqlQueryOptions {
414
- /** SQL query to execute */
415
- sql: string;
416
- /** Parameters to bind to the query */
417
- params?: SqlParam[];
418
- /** Whether to return only the first result */
419
- first?: boolean;
420
- }
421
-
422
- export { }