@qualithm/arrow-flight-sql-js 0.0.1 → 0.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.

Potentially problematic release.


This version of @qualithm/arrow-flight-sql-js might be problematic. Click here for more details.

@@ -1 +1,363 @@
1
+ /**
2
+ * Fluent SQL query builder for constructing type-safe queries.
3
+ *
4
+ * This module provides a query builder API that generates SQL strings
5
+ * compatible with the FlightSqlClient.query() and executeUpdate() methods.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { QueryBuilder } from "@qualithm/arrow-flight-sql-js"
10
+ *
11
+ * const query = new QueryBuilder()
12
+ * .select("id", "name", "email")
13
+ * .from("users")
14
+ * .where("status", "=", "active")
15
+ * .orderBy("created_at", "DESC")
16
+ * .limit(10)
17
+ * .build()
18
+ *
19
+ * const result = await client.query(query)
20
+ * ```
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ /** SQL comparison operators */
25
+ export type ComparisonOperator = "=" | "!=" | "<>" | "<" | "<=" | ">" | ">=" | "LIKE" | "NOT LIKE" | "ILIKE" | "IN" | "NOT IN" | "IS" | "IS NOT" | "BETWEEN";
26
+ /** Sort direction */
27
+ export type SortDirection = "ASC" | "DESC";
28
+ /** Join types */
29
+ export type JoinType = "INNER" | "LEFT" | "RIGHT" | "FULL" | "CROSS";
30
+ /** Logical operators for combining conditions */
31
+ export type LogicalOperator = "AND" | "OR";
32
+ /** A single WHERE condition */
33
+ export type WhereCondition = {
34
+ column: string;
35
+ operator: ComparisonOperator;
36
+ value: SqlValue;
37
+ logical: LogicalOperator;
38
+ };
39
+ /** A raw SQL expression */
40
+ export type RawExpression = {
41
+ __raw: true;
42
+ sql: string;
43
+ };
44
+ /** SQL value types */
45
+ export type SqlValue = string | number | boolean | bigint | null | Date | RawExpression | SqlValue[];
46
+ /** Column with optional alias */
47
+ export type ColumnSpec = string | {
48
+ column: string;
49
+ alias: string;
50
+ };
51
+ /** Order by specification */
52
+ export type OrderSpec = {
53
+ column: string;
54
+ direction: SortDirection;
55
+ nulls?: "FIRST" | "LAST";
56
+ };
57
+ /** Join specification */
58
+ export type JoinSpec = {
59
+ type: JoinType;
60
+ table: string;
61
+ alias?: string;
62
+ on: string;
63
+ };
64
+ /** Result of building a query */
65
+ export type BuiltQuery = {
66
+ /** The SQL query string */
67
+ sql: string;
68
+ /** Parameter values for prepared statements (if using parameterized mode) */
69
+ params: SqlValue[];
70
+ };
71
+ /**
72
+ * Creates a raw SQL expression that won't be escaped.
73
+ *
74
+ * WARNING: Only use with trusted input. Raw expressions bypass escaping
75
+ * and can lead to SQL injection if used with untrusted data.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const query = new QueryBuilder()
80
+ * .select("*")
81
+ * .from("events")
82
+ * .where("created_at", ">", raw("NOW() - INTERVAL '1 day'"))
83
+ * .build()
84
+ * ```
85
+ */
86
+ export declare function raw(sql: string): RawExpression;
87
+ /**
88
+ * Escape a SQL identifier (table name, column name).
89
+ * Uses double quotes for standard SQL compliance.
90
+ */
91
+ export declare function escapeIdentifier(identifier: string): string;
92
+ /**
93
+ * Escape a SQL string value.
94
+ * Uses single quotes with proper escaping.
95
+ */
96
+ export declare function escapeString(value: string): string;
97
+ /**
98
+ * Format a SQL value for inclusion in a query.
99
+ */
100
+ export declare function formatValue(value: SqlValue): string;
101
+ /**
102
+ * Fluent SQL query builder.
103
+ *
104
+ * Supports SELECT, INSERT, UPDATE, and DELETE operations with a chainable API.
105
+ *
106
+ * @example SELECT query
107
+ * ```typescript
108
+ * const sql = new QueryBuilder()
109
+ * .select("id", "name")
110
+ * .from("users")
111
+ * .where("active", "=", true)
112
+ * .limit(10)
113
+ * .build()
114
+ * ```
115
+ *
116
+ * @example INSERT query
117
+ * ```typescript
118
+ * const sql = new QueryBuilder()
119
+ * .insertInto("users")
120
+ * .columns("name", "email")
121
+ * .values("Alice", "alice@example.com")
122
+ * .build()
123
+ * ```
124
+ *
125
+ * @example UPDATE query
126
+ * ```typescript
127
+ * const sql = new QueryBuilder()
128
+ * .update("users")
129
+ * .set("status", "inactive")
130
+ * .where("last_login", "<", new Date("2024-01-01"))
131
+ * .build()
132
+ * ```
133
+ *
134
+ * @example DELETE query
135
+ * ```typescript
136
+ * const sql = new QueryBuilder()
137
+ * .deleteFrom("users")
138
+ * .where("status", "=", "deleted")
139
+ * .build()
140
+ * ```
141
+ */
142
+ export declare class QueryBuilder {
143
+ private _operation;
144
+ private _distinct;
145
+ private _columns;
146
+ private _table;
147
+ private _tableAlias?;
148
+ private _joins;
149
+ private _conditions;
150
+ private _groupBy;
151
+ private _having;
152
+ private _orderBy;
153
+ private _limit?;
154
+ private _offset?;
155
+ private _parameterized;
156
+ private _params;
157
+ private _insertColumns;
158
+ private _insertValues;
159
+ private _setValues;
160
+ /**
161
+ * Specify columns to select.
162
+ *
163
+ * @param columns - Column names or column specs with aliases
164
+ * @returns this for chaining
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * .select("id", "name")
169
+ * .select({ column: "email", alias: "user_email" })
170
+ * .select("*")
171
+ * ```
172
+ */
173
+ select(...columns: ColumnSpec[]): this;
174
+ /**
175
+ * Select distinct rows only.
176
+ */
177
+ distinct(): this;
178
+ /**
179
+ * Specify the table to query from.
180
+ *
181
+ * @param table - Table name
182
+ * @param alias - Optional table alias
183
+ */
184
+ from(table: string, alias?: string): this;
185
+ /**
186
+ * Add a JOIN clause.
187
+ *
188
+ * @param type - Join type (INNER, LEFT, RIGHT, FULL, CROSS)
189
+ * @param table - Table to join
190
+ * @param on - Join condition
191
+ * @param alias - Optional table alias
192
+ */
193
+ join(type: JoinType, table: string, on: string, alias?: string): this;
194
+ /**
195
+ * Add an INNER JOIN clause.
196
+ */
197
+ innerJoin(table: string, on: string, alias?: string): this;
198
+ /**
199
+ * Add a LEFT JOIN clause.
200
+ */
201
+ leftJoin(table: string, on: string, alias?: string): this;
202
+ /**
203
+ * Add a RIGHT JOIN clause.
204
+ */
205
+ rightJoin(table: string, on: string, alias?: string): this;
206
+ /**
207
+ * Add a WHERE condition.
208
+ *
209
+ * @param column - Column name
210
+ * @param operator - Comparison operator
211
+ * @param value - Value to compare against
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * .where("status", "=", "active")
216
+ * .where("age", ">=", 18)
217
+ * .where("role", "IN", ["admin", "moderator"])
218
+ * .where("deleted_at", "IS", null)
219
+ * ```
220
+ */
221
+ where(column: string, operator: ComparisonOperator, value: SqlValue): this;
222
+ /**
223
+ * Add an OR WHERE condition.
224
+ */
225
+ orWhere(column: string, operator: ComparisonOperator, value: SqlValue): this;
226
+ /**
227
+ * Add a WHERE BETWEEN condition.
228
+ */
229
+ whereBetween(column: string, min: SqlValue, max: SqlValue): this;
230
+ /**
231
+ * Add a WHERE IN condition.
232
+ */
233
+ whereIn(column: string, values: SqlValue[]): this;
234
+ /**
235
+ * Add a WHERE IS NULL condition.
236
+ */
237
+ whereNull(column: string): this;
238
+ /**
239
+ * Add a WHERE IS NOT NULL condition.
240
+ */
241
+ whereNotNull(column: string): this;
242
+ /**
243
+ * Add GROUP BY columns.
244
+ */
245
+ groupBy(...columns: string[]): this;
246
+ /**
247
+ * Add a HAVING condition.
248
+ */
249
+ having(column: string, operator: ComparisonOperator, value: SqlValue): this;
250
+ /**
251
+ * Add ORDER BY clause.
252
+ *
253
+ * @param column - Column to order by
254
+ * @param direction - Sort direction (ASC or DESC)
255
+ * @param nulls - NULLS FIRST or NULLS LAST
256
+ */
257
+ orderBy(column: string, direction?: SortDirection, nulls?: "FIRST" | "LAST"): this;
258
+ /**
259
+ * Set the maximum number of rows to return.
260
+ */
261
+ limit(count: number): this;
262
+ /**
263
+ * Set the number of rows to skip.
264
+ */
265
+ offset(count: number): this;
266
+ /**
267
+ * Start an INSERT statement.
268
+ *
269
+ * @param table - Table to insert into
270
+ */
271
+ insertInto(table: string): this;
272
+ /**
273
+ * Specify columns for INSERT.
274
+ */
275
+ columns(...columns: string[]): this;
276
+ /**
277
+ * Add values to INSERT.
278
+ * Can be called multiple times for multi-row inserts.
279
+ *
280
+ * @param values - Values corresponding to columns
281
+ */
282
+ values(...values: SqlValue[]): this;
283
+ /**
284
+ * Start an UPDATE statement.
285
+ *
286
+ * @param table - Table to update
287
+ */
288
+ update(table: string): this;
289
+ /**
290
+ * Set a column value for UPDATE.
291
+ *
292
+ * @param column - Column to update
293
+ * @param value - New value
294
+ */
295
+ set(column: string, value: SqlValue): this;
296
+ /**
297
+ * Set multiple column values for UPDATE.
298
+ *
299
+ * @param values - Object mapping column names to values
300
+ */
301
+ setMany(values: Record<string, SqlValue>): this;
302
+ /**
303
+ * Start a DELETE statement.
304
+ *
305
+ * @param table - Table to delete from
306
+ */
307
+ deleteFrom(table: string): this;
308
+ /**
309
+ * Build the SQL query string.
310
+ *
311
+ * @returns The complete SQL query string
312
+ */
313
+ build(): string;
314
+ /**
315
+ * Build query with parameter placeholders for prepared statements.
316
+ *
317
+ * @returns Object containing SQL with placeholders and parameter values
318
+ */
319
+ buildParameterized(): BuiltQuery;
320
+ /**
321
+ * Create a copy of this query builder.
322
+ */
323
+ clone(): QueryBuilder;
324
+ /**
325
+ * Reset the builder to initial state.
326
+ */
327
+ reset(): this;
328
+ private buildSelect;
329
+ private buildInsert;
330
+ private buildUpdate;
331
+ private buildDelete;
332
+ private buildConditions;
333
+ private formatOrParam;
334
+ }
335
+ /**
336
+ * Create a new QueryBuilder for a SELECT query.
337
+ *
338
+ * @param columns - Columns to select
339
+ * @returns A new QueryBuilder with SELECT initialized
340
+ */
341
+ export declare function select(...columns: ColumnSpec[]): QueryBuilder;
342
+ /**
343
+ * Create a new QueryBuilder for an INSERT query.
344
+ *
345
+ * @param table - Table to insert into
346
+ * @returns A new QueryBuilder with INSERT initialized
347
+ */
348
+ export declare function insertInto(table: string): QueryBuilder;
349
+ /**
350
+ * Create a new QueryBuilder for an UPDATE query.
351
+ *
352
+ * @param table - Table to update
353
+ * @returns A new QueryBuilder with UPDATE initialized
354
+ */
355
+ export declare function update(table: string): QueryBuilder;
356
+ /**
357
+ * Create a new QueryBuilder for a DELETE query.
358
+ *
359
+ * @param table - Table to delete from
360
+ * @returns A new QueryBuilder with DELETE initialized
361
+ */
362
+ export declare function deleteFrom(table: string): QueryBuilder;
1
363
  //# sourceMappingURL=query-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../src/query-builder.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../src/query-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,+BAA+B;AAC/B,MAAM,MAAM,kBAAkB,GAC1B,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,MAAM,GACN,UAAU,GACV,OAAO,GACP,IAAI,GACJ,QAAQ,GACR,IAAI,GACJ,QAAQ,GACR,SAAS,CAAA;AAEb,qBAAqB;AACrB,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C,iBAAiB;AACjB,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAA;AAEpE,iDAAiD;AACjD,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,IAAI,CAAA;AAE1C,+BAA+B;AAC/B,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,kBAAkB,CAAA;IAC5B,KAAK,EAAE,QAAQ,CAAA;IACf,OAAO,EAAE,eAAe,CAAA;CACzB,CAAA;AAED,2BAA2B;AAC3B,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,IAAI,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,sBAAsB;AACtB,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GA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