@pol-studios/db 1.0.19 → 1.0.21
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/DataLayerContext-ZmLPYR_s.d.ts +825 -0
- package/dist/EntityPermissions-DwFt4tUd.d.ts +35 -0
- package/dist/FilterConfig-Bt2Ek74z.d.ts +99 -0
- package/dist/UserMetadataContext-B8gVWGMl.d.ts +35 -0
- package/dist/UserMetadataContext-DntmpK41.d.ts +33 -0
- package/dist/auth/context.d.ts +48 -0
- package/dist/auth/guards.d.ts +180 -0
- package/dist/auth/hooks.d.ts +312 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/client/index.d.ts +16 -0
- package/dist/core/index.d.ts +539 -0
- package/dist/database.types-ChFCG-4M.d.ts +8604 -0
- package/dist/executor-CB4KHyYG.d.ts +507 -0
- package/dist/gen/index.d.ts +1099 -0
- package/dist/hooks/index.d.ts +100 -0
- package/dist/index-BNKhgDdC.d.ts +433 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.native.d.ts +793 -0
- package/dist/index.web.d.ts +321 -0
- package/dist/mutation/index.d.ts +58 -0
- package/dist/parser/index.d.ts +366 -0
- package/dist/powersync-bridge/index.d.ts +284 -0
- package/dist/query/index.d.ts +723 -0
- package/dist/realtime/index.d.ts +44 -0
- package/dist/select-query-parser-BwyHum1L.d.ts +352 -0
- package/dist/setupAuthContext-Kv-THH-h.d.ts +61 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types-CYr9JiUE.d.ts +62 -0
- package/dist/useBatchUpsert-9OYjibLh.d.ts +24 -0
- package/dist/useDbCount-Id14x_1P.d.ts +1082 -0
- package/dist/useDbQuery-C-TL8jY1.d.ts +19 -0
- package/dist/useReceiptAI-6HkRpRml.d.ts +58 -0
- package/dist/useResolveFeedback-Ca2rh_Bs.d.ts +997 -0
- package/dist/useSupabase-DvWVuHHE.d.ts +28 -0
- package/dist/with-auth/index.d.ts +704 -0
- package/package.json +61 -13
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import { DatabaseSchema, ResolvedRelationship, TableSchema, SelectColumn, WhereClause, OrderBy, BuiltQuery, QueryOptions } from './core/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Relationship Resolver
|
|
5
|
+
*
|
|
6
|
+
* Looks up relationships between tables from the database schema.
|
|
7
|
+
* Used to determine how to join related data in queries.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Resolves relationships between tables using the database schema.
|
|
12
|
+
*
|
|
13
|
+
* Given a table and a relation name (which could be another table),
|
|
14
|
+
* this class determines:
|
|
15
|
+
* 1. Whether a relationship exists
|
|
16
|
+
* 2. The type of relationship (one-to-many or many-to-one)
|
|
17
|
+
* 3. Which columns are used for the join
|
|
18
|
+
*/
|
|
19
|
+
declare class RelationshipResolver {
|
|
20
|
+
private schema;
|
|
21
|
+
constructor(schema: DatabaseSchema);
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a relationship from one table to another.
|
|
24
|
+
*
|
|
25
|
+
* This handles both:
|
|
26
|
+
* - Forward relationships: This table has a FK to the related table (many-to-one)
|
|
27
|
+
* - Reverse relationships: Related table has a FK to this table (one-to-many)
|
|
28
|
+
*
|
|
29
|
+
* @param fromTable - The table we're querying from
|
|
30
|
+
* @param relationName - The name of the related table
|
|
31
|
+
* @returns The resolved relationship or null if not found
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Forward relationship (many-to-one)
|
|
35
|
+
* // EquipmentUnit.projectDatabaseId -> ProjectDatabase.id
|
|
36
|
+
* resolver.resolve("EquipmentUnit", "ProjectDatabase")
|
|
37
|
+
* // Returns: {
|
|
38
|
+
* // type: "many-to-one",
|
|
39
|
+
* // fromTable: "EquipmentUnit",
|
|
40
|
+
* // toTable: "ProjectDatabase",
|
|
41
|
+
* // foreignKey: "projectDatabaseId",
|
|
42
|
+
* // referencedColumn: "id"
|
|
43
|
+
* // }
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // Reverse relationship (one-to-many)
|
|
47
|
+
* // EquipmentUnit <- EquipmentFixture.equipmentUnitId
|
|
48
|
+
* resolver.resolve("EquipmentUnit", "EquipmentFixture")
|
|
49
|
+
* // Returns: {
|
|
50
|
+
* // type: "one-to-many",
|
|
51
|
+
* // fromTable: "EquipmentUnit",
|
|
52
|
+
* // toTable: "EquipmentFixture",
|
|
53
|
+
* // foreignKey: "equipmentUnitId",
|
|
54
|
+
* // referencedColumn: "id"
|
|
55
|
+
* // }
|
|
56
|
+
*/
|
|
57
|
+
resolve(fromTable: string, relationName: string): ResolvedRelationship | null;
|
|
58
|
+
/**
|
|
59
|
+
* Get all forward relationships for a table (many-to-one).
|
|
60
|
+
* These are relationships where this table has a foreign key.
|
|
61
|
+
*/
|
|
62
|
+
getForwardRelationships(tableName: string): ResolvedRelationship[];
|
|
63
|
+
/**
|
|
64
|
+
* Get all reverse relationships for a table (one-to-many).
|
|
65
|
+
* These are relationships where other tables have FKs pointing to this table.
|
|
66
|
+
*/
|
|
67
|
+
getReverseRelationships(tableName: string): ResolvedRelationship[];
|
|
68
|
+
/**
|
|
69
|
+
* Get all relationships for a table (both directions).
|
|
70
|
+
*/
|
|
71
|
+
getAllRelationships(tableName: string): ResolvedRelationship[];
|
|
72
|
+
/**
|
|
73
|
+
* Check if a relationship exists between two tables.
|
|
74
|
+
*/
|
|
75
|
+
hasRelationship(fromTable: string, toTable: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Get the table schema from the database schema.
|
|
78
|
+
* Searches across all schema namespaces (public, core, etc.).
|
|
79
|
+
*/
|
|
80
|
+
getTableSchema(tableName: string): TableSchema | null;
|
|
81
|
+
/**
|
|
82
|
+
* Get the primary key column for a table.
|
|
83
|
+
* Defaults to "id" if not explicitly found.
|
|
84
|
+
*/
|
|
85
|
+
getPrimaryKey(tableName: string): string;
|
|
86
|
+
/**
|
|
87
|
+
* Get all column names for a table.
|
|
88
|
+
*/
|
|
89
|
+
getColumnNames(tableName: string): string[];
|
|
90
|
+
/**
|
|
91
|
+
* Check if a table exists in the schema.
|
|
92
|
+
*/
|
|
93
|
+
hasTable(tableName: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Get all table names in the schema.
|
|
96
|
+
*/
|
|
97
|
+
getAllTableNames(): string[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Create a relationship resolver instance.
|
|
101
|
+
* Convenience function for creating a resolver.
|
|
102
|
+
*/
|
|
103
|
+
declare function createRelationshipResolver(schema: DatabaseSchema): RelationshipResolver;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* SQL Builder
|
|
107
|
+
*
|
|
108
|
+
* Builds SQLite queries from parsed select statements and query options.
|
|
109
|
+
* Produces parameterized queries for safe execution against PowerSync's local SQLite.
|
|
110
|
+
*
|
|
111
|
+
* Note: SQLite uses double quotes for identifiers (table/column names).
|
|
112
|
+
* This builder only creates queries for single tables - relations are queried
|
|
113
|
+
* separately and joined in code.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* SQLite query builder.
|
|
118
|
+
* Creates parameterized SQL queries for local SQLite execution.
|
|
119
|
+
*/
|
|
120
|
+
declare class SQLBuilder {
|
|
121
|
+
/**
|
|
122
|
+
* Build a SELECT query for a single table.
|
|
123
|
+
*
|
|
124
|
+
* @param table - Table name
|
|
125
|
+
* @param columns - Columns to select ("*" or array of column definitions)
|
|
126
|
+
* @param options - Query options (where, orderBy, limit, offset)
|
|
127
|
+
* @returns Built query with SQL and parameters
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const builder = new SQLBuilder();
|
|
131
|
+
* const query = builder.build("EquipmentUnit", "*", {
|
|
132
|
+
* where: { status: "active", projectDatabaseId: 123 },
|
|
133
|
+
* orderBy: [{ field: "name", direction: "asc" }],
|
|
134
|
+
* limit: 10
|
|
135
|
+
* });
|
|
136
|
+
* // query.sql: SELECT * FROM "EquipmentUnit" WHERE "status" = ? AND "projectDatabaseId" = ? ORDER BY "name" ASC LIMIT ?
|
|
137
|
+
* // query.params: ["active", 123, 10]
|
|
138
|
+
*/
|
|
139
|
+
build(table: string, columns: "*" | SelectColumn[], options?: {
|
|
140
|
+
where?: WhereClause;
|
|
141
|
+
orderBy?: OrderBy[];
|
|
142
|
+
limit?: number;
|
|
143
|
+
offset?: number;
|
|
144
|
+
}): BuiltQuery;
|
|
145
|
+
/**
|
|
146
|
+
* Build WHERE clauses from operator objects.
|
|
147
|
+
*/
|
|
148
|
+
private buildOperatorClauses;
|
|
149
|
+
/**
|
|
150
|
+
* Build a query to fetch related records by foreign key.
|
|
151
|
+
*
|
|
152
|
+
* @param table - The related table name
|
|
153
|
+
* @param foreignKey - The FK column to match against
|
|
154
|
+
* @param parentIds - Array of parent IDs to fetch related records for
|
|
155
|
+
* @param columns - Columns to select
|
|
156
|
+
* @returns Built query
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // Fetch all EquipmentFixtures for given EquipmentUnit IDs
|
|
160
|
+
* const query = builder.buildRelationQuery(
|
|
161
|
+
* "EquipmentFixture",
|
|
162
|
+
* "equipmentUnitId",
|
|
163
|
+
* ["uuid-1", "uuid-2"],
|
|
164
|
+
* "*"
|
|
165
|
+
* );
|
|
166
|
+
* // query.sql: SELECT * FROM "EquipmentFixture" WHERE "equipmentUnitId" IN (?, ?)
|
|
167
|
+
* // query.params: ["uuid-1", "uuid-2"]
|
|
168
|
+
*/
|
|
169
|
+
buildRelationQuery(table: string, foreignKey: string, parentIds: (string | number)[], columns: "*" | SelectColumn[]): BuiltQuery;
|
|
170
|
+
/**
|
|
171
|
+
* Build column list ensuring the foreign key is included.
|
|
172
|
+
*/
|
|
173
|
+
private buildColumnList;
|
|
174
|
+
/**
|
|
175
|
+
* Build a SELECT query for a single record by ID.
|
|
176
|
+
*
|
|
177
|
+
* @param table - Table name
|
|
178
|
+
* @param id - Record ID
|
|
179
|
+
* @param columns - Columns to select
|
|
180
|
+
* @param idColumn - Name of the ID column (defaults to "id")
|
|
181
|
+
* @returns Built query
|
|
182
|
+
*/
|
|
183
|
+
buildByIdQuery(table: string, id: string | number, columns?: "*" | SelectColumn[], idColumn?: string): BuiltQuery;
|
|
184
|
+
/**
|
|
185
|
+
* Build an INSERT query.
|
|
186
|
+
*
|
|
187
|
+
* @param table - Table name
|
|
188
|
+
* @param data - Record data to insert
|
|
189
|
+
* @returns Built query
|
|
190
|
+
*/
|
|
191
|
+
buildInsertQuery(table: string, data: Record<string, unknown>): BuiltQuery;
|
|
192
|
+
/**
|
|
193
|
+
* Build an UPDATE query.
|
|
194
|
+
*
|
|
195
|
+
* @param table - Table name
|
|
196
|
+
* @param id - Record ID
|
|
197
|
+
* @param data - Fields to update
|
|
198
|
+
* @param idColumn - Name of the ID column (defaults to "id")
|
|
199
|
+
* @returns Built query
|
|
200
|
+
*/
|
|
201
|
+
buildUpdateQuery(table: string, id: string | number, data: Record<string, unknown>, idColumn?: string): BuiltQuery;
|
|
202
|
+
/**
|
|
203
|
+
* Build a DELETE query.
|
|
204
|
+
*
|
|
205
|
+
* @param table - Table name
|
|
206
|
+
* @param id - Record ID
|
|
207
|
+
* @param idColumn - Name of the ID column (defaults to "id")
|
|
208
|
+
* @returns Built query
|
|
209
|
+
*/
|
|
210
|
+
buildDeleteQuery(table: string, id: string | number, idColumn?: string): BuiltQuery;
|
|
211
|
+
/**
|
|
212
|
+
* Build a COUNT query.
|
|
213
|
+
*
|
|
214
|
+
* @param table - Table name
|
|
215
|
+
* @param where - Optional where clause
|
|
216
|
+
* @returns Built query
|
|
217
|
+
*/
|
|
218
|
+
buildCountQuery(table: string, where?: WhereClause): BuiltQuery;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Create a new SQL builder instance.
|
|
222
|
+
*/
|
|
223
|
+
declare function createSQLBuilder(): SQLBuilder;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Result Joiner
|
|
227
|
+
*
|
|
228
|
+
* After querying the base table and related tables separately,
|
|
229
|
+
* this module joins them into a nested structure matching Supabase's format.
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Data about a relation to be joined onto base records.
|
|
234
|
+
*/
|
|
235
|
+
interface RelationJoinData {
|
|
236
|
+
records: Record<string, unknown>[];
|
|
237
|
+
relationship: ResolvedRelationship;
|
|
238
|
+
nestedRelations: Map<string, RelationJoinData>;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Result joiner for combining base records with related data.
|
|
242
|
+
*
|
|
243
|
+
* This class handles joining related data onto base records after
|
|
244
|
+
* separate queries have been executed. It supports:
|
|
245
|
+
* - One-to-many relationships (base gets array of related)
|
|
246
|
+
* - Many-to-one relationships (base gets single related object or null)
|
|
247
|
+
* - Nested relationships (recursive joining)
|
|
248
|
+
*/
|
|
249
|
+
declare class ResultJoiner {
|
|
250
|
+
/**
|
|
251
|
+
* Join related data onto base records.
|
|
252
|
+
*
|
|
253
|
+
* @param baseRecords - The base table records
|
|
254
|
+
* @param relatedRecords - Records from the related table
|
|
255
|
+
* @param relationship - The relationship definition
|
|
256
|
+
* @param relationName - The property name to use for the relation
|
|
257
|
+
* @returns Base records with related data attached
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* // One-to-many: EquipmentUnit -> EquipmentFixture[]
|
|
261
|
+
* const joiner = new ResultJoiner();
|
|
262
|
+
* const result = joiner.join(
|
|
263
|
+
* equipmentUnits,
|
|
264
|
+
* equipmentFixtures,
|
|
265
|
+
* { type: "one-to-many", foreignKey: "equipmentUnitId", referencedColumn: "id", ... },
|
|
266
|
+
* "EquipmentFixture"
|
|
267
|
+
* );
|
|
268
|
+
* // Each equipmentUnit now has EquipmentFixture: [...]
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* // Many-to-one: EquipmentUnit -> ProjectDatabase
|
|
272
|
+
* const result = joiner.join(
|
|
273
|
+
* equipmentUnits,
|
|
274
|
+
* projectDatabases,
|
|
275
|
+
* { type: "many-to-one", foreignKey: "projectDatabaseId", referencedColumn: "id", ... },
|
|
276
|
+
* "ProjectDatabase"
|
|
277
|
+
* );
|
|
278
|
+
* // Each equipmentUnit now has ProjectDatabase: {...} or null
|
|
279
|
+
*/
|
|
280
|
+
join<T extends Record<string, unknown>>(baseRecords: T[], relatedRecords: Record<string, unknown>[], relationship: ResolvedRelationship, relationName: string): T[];
|
|
281
|
+
/**
|
|
282
|
+
* Recursively join nested relations onto records.
|
|
283
|
+
*
|
|
284
|
+
* @param baseRecords - The base records
|
|
285
|
+
* @param relationData - Map of relation names to join data
|
|
286
|
+
* @returns Base records with all nested relations attached
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* // Join EquipmentFixture and ProjectDatabase onto EquipmentUnit
|
|
290
|
+
* // where EquipmentFixture has its own nested Organization relation
|
|
291
|
+
* const result = joiner.joinNested(equipmentUnits, new Map([
|
|
292
|
+
* ["EquipmentFixture", {
|
|
293
|
+
* records: fixtures,
|
|
294
|
+
* relationship: { type: "one-to-many", ... },
|
|
295
|
+
* nestedRelations: new Map()
|
|
296
|
+
* }],
|
|
297
|
+
* ["ProjectDatabase", {
|
|
298
|
+
* records: projects,
|
|
299
|
+
* relationship: { type: "many-to-one", ... },
|
|
300
|
+
* nestedRelations: new Map([
|
|
301
|
+
* ["Organization", { records: orgs, relationship: ..., nestedRelations: new Map() }]
|
|
302
|
+
* ])
|
|
303
|
+
* }]
|
|
304
|
+
* ]));
|
|
305
|
+
*/
|
|
306
|
+
joinNested<T extends Record<string, unknown>>(baseRecords: T[], relationData: Map<string, RelationJoinData>): T[];
|
|
307
|
+
/**
|
|
308
|
+
* Group records by a key field.
|
|
309
|
+
* Useful for preparing data before joining.
|
|
310
|
+
*
|
|
311
|
+
* @param records - Records to group
|
|
312
|
+
* @param keyField - Field to group by
|
|
313
|
+
* @returns Map of key values to arrays of records
|
|
314
|
+
*/
|
|
315
|
+
groupBy<T extends Record<string, unknown>>(records: T[], keyField: string): Map<unknown, T[]>;
|
|
316
|
+
/**
|
|
317
|
+
* Index records by a unique key field.
|
|
318
|
+
* Useful for many-to-one lookups.
|
|
319
|
+
*
|
|
320
|
+
* @param records - Records to index
|
|
321
|
+
* @param keyField - Field to index by (should be unique)
|
|
322
|
+
* @returns Map of key values to single records
|
|
323
|
+
*/
|
|
324
|
+
indexBy<T extends Record<string, unknown>>(records: T[], keyField: string): Map<unknown, T>;
|
|
325
|
+
/**
|
|
326
|
+
* Extract unique values for a field from records.
|
|
327
|
+
* Useful for building IN clauses for related queries.
|
|
328
|
+
*
|
|
329
|
+
* @param records - Records to extract from
|
|
330
|
+
* @param field - Field to extract
|
|
331
|
+
* @returns Array of unique non-null values
|
|
332
|
+
*/
|
|
333
|
+
extractUniqueValues<T extends Record<string, unknown>>(records: T[], field: string): (string | number)[];
|
|
334
|
+
/**
|
|
335
|
+
* Remove a relation property from records (for cleanup).
|
|
336
|
+
*
|
|
337
|
+
* @param records - Records to process
|
|
338
|
+
* @param relationName - Relation property to remove
|
|
339
|
+
* @returns Records without the specified property
|
|
340
|
+
*/
|
|
341
|
+
removeRelation<T extends Record<string, unknown>>(records: T[], relationName: string): Omit<T, typeof relationName>[];
|
|
342
|
+
/**
|
|
343
|
+
* Flatten a nested relation into the parent record.
|
|
344
|
+
* Useful for flattening many-to-one relations.
|
|
345
|
+
*
|
|
346
|
+
* @param records - Records with nested relation
|
|
347
|
+
* @param relationName - Name of the relation to flatten
|
|
348
|
+
* @param prefix - Prefix for flattened field names
|
|
349
|
+
* @returns Records with flattened relation fields
|
|
350
|
+
*/
|
|
351
|
+
flattenRelation<T extends Record<string, unknown>>(records: T[], relationName: string, prefix?: string): Record<string, unknown>[];
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Create a new result joiner instance.
|
|
355
|
+
*/
|
|
356
|
+
declare function createResultJoiner(): ResultJoiner;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Query Executor
|
|
360
|
+
*
|
|
361
|
+
* Orchestrates the full query execution pipeline:
|
|
362
|
+
* 1. Parse select string
|
|
363
|
+
* 2. Build SQL queries
|
|
364
|
+
* 3. Execute against PowerSync database
|
|
365
|
+
* 4. Join related data
|
|
366
|
+
*
|
|
367
|
+
* This provides a unified interface for executing Supabase-style queries
|
|
368
|
+
* against the local SQLite database via PowerSync.
|
|
369
|
+
*/
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Interface for PowerSync database.
|
|
373
|
+
* This matches the getAll method signature from @powersync/react-native.
|
|
374
|
+
*/
|
|
375
|
+
interface PowerSyncDatabase {
|
|
376
|
+
getAll<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
377
|
+
get<T>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
378
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
379
|
+
rowsAffected: number;
|
|
380
|
+
}>;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Query executor that handles the full query lifecycle.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* const executor = new QueryExecutor(db, databaseSchema);
|
|
387
|
+
*
|
|
388
|
+
* // Simple query
|
|
389
|
+
* const units = await executor.execute<EquipmentUnit>("EquipmentUnit", {
|
|
390
|
+
* where: { status: "active" },
|
|
391
|
+
* orderBy: [{ field: "name", direction: "asc" }],
|
|
392
|
+
* limit: 10
|
|
393
|
+
* });
|
|
394
|
+
*
|
|
395
|
+
* // Query with relations
|
|
396
|
+
* const unitsWithRelations = await executor.execute<EquipmentUnitWithRelations>(
|
|
397
|
+
* "EquipmentUnit",
|
|
398
|
+
* {
|
|
399
|
+
* select: "*, EquipmentFixture(*), ProjectDatabase(name, Organization(*))",
|
|
400
|
+
* where: { status: "active" }
|
|
401
|
+
* }
|
|
402
|
+
* );
|
|
403
|
+
*/
|
|
404
|
+
declare class QueryExecutor {
|
|
405
|
+
private db;
|
|
406
|
+
private schema;
|
|
407
|
+
private resolver;
|
|
408
|
+
private builder;
|
|
409
|
+
private joiner;
|
|
410
|
+
constructor(db: PowerSyncDatabase, schema: DatabaseSchema);
|
|
411
|
+
/**
|
|
412
|
+
* Execute a query and return results.
|
|
413
|
+
*
|
|
414
|
+
* @param table - The table to query
|
|
415
|
+
* @param options - Query options including select, where, orderBy, limit, offset
|
|
416
|
+
* @returns Array of records with relations attached
|
|
417
|
+
*/
|
|
418
|
+
execute<T>(table: string, options?: QueryOptions): Promise<T[]>;
|
|
419
|
+
/**
|
|
420
|
+
* Execute a query for a single record by ID.
|
|
421
|
+
*
|
|
422
|
+
* @param table - The table to query
|
|
423
|
+
* @param id - The record ID
|
|
424
|
+
* @param options - Query options (only select is used)
|
|
425
|
+
* @returns Single record or null
|
|
426
|
+
*/
|
|
427
|
+
executeById<T>(table: string, id: string | number, options?: Pick<QueryOptions, "select">): Promise<T | null>;
|
|
428
|
+
/**
|
|
429
|
+
* Execute a count query.
|
|
430
|
+
*
|
|
431
|
+
* @param table - The table to count
|
|
432
|
+
* @param options - Query options (only where is used)
|
|
433
|
+
* @returns Count of matching records
|
|
434
|
+
*/
|
|
435
|
+
count(table: string, options?: Pick<QueryOptions, "where">): Promise<number>;
|
|
436
|
+
/**
|
|
437
|
+
* Insert a record.
|
|
438
|
+
*
|
|
439
|
+
* @param table - The table to insert into
|
|
440
|
+
* @param data - The record data
|
|
441
|
+
* @returns The inserted record (re-fetched to get defaults)
|
|
442
|
+
*/
|
|
443
|
+
insert<T>(table: string, data: Record<string, unknown>): Promise<T>;
|
|
444
|
+
/**
|
|
445
|
+
* Update a record.
|
|
446
|
+
*
|
|
447
|
+
* @param table - The table to update
|
|
448
|
+
* @param id - The record ID
|
|
449
|
+
* @param data - The fields to update
|
|
450
|
+
* @returns The updated record
|
|
451
|
+
*/
|
|
452
|
+
update<T>(table: string, id: string | number, data: Record<string, unknown>): Promise<T>;
|
|
453
|
+
/**
|
|
454
|
+
* Upsert a record (insert or update).
|
|
455
|
+
*
|
|
456
|
+
* @param table - The table to upsert into
|
|
457
|
+
* @param data - The record data (must include ID for update)
|
|
458
|
+
* @returns The upserted record
|
|
459
|
+
*/
|
|
460
|
+
upsert<T>(table: string, data: Record<string, unknown>): Promise<T>;
|
|
461
|
+
/**
|
|
462
|
+
* Delete a record.
|
|
463
|
+
*
|
|
464
|
+
* @param table - The table to delete from
|
|
465
|
+
* @param id - The record ID
|
|
466
|
+
*/
|
|
467
|
+
delete(table: string, id: string | number): Promise<void>;
|
|
468
|
+
/**
|
|
469
|
+
* Query and join relations onto parent records.
|
|
470
|
+
*
|
|
471
|
+
* @param parentTable - The parent table name
|
|
472
|
+
* @param parentRecords - Parent records to add relations to
|
|
473
|
+
* @param relations - Relations to query and join
|
|
474
|
+
* @returns Parent records with relations attached
|
|
475
|
+
*/
|
|
476
|
+
private queryAndJoinRelations;
|
|
477
|
+
/**
|
|
478
|
+
* Get parent IDs needed for a relation query.
|
|
479
|
+
*/
|
|
480
|
+
private getParentIdsForRelation;
|
|
481
|
+
/**
|
|
482
|
+
* Build a query for related records.
|
|
483
|
+
*/
|
|
484
|
+
private buildRelatedQuery;
|
|
485
|
+
/**
|
|
486
|
+
* Get the relationship resolver (for advanced use).
|
|
487
|
+
*/
|
|
488
|
+
getResolver(): RelationshipResolver;
|
|
489
|
+
/**
|
|
490
|
+
* Get the SQL builder (for advanced use).
|
|
491
|
+
*/
|
|
492
|
+
getBuilder(): SQLBuilder;
|
|
493
|
+
/**
|
|
494
|
+
* Get the result joiner (for advanced use).
|
|
495
|
+
*/
|
|
496
|
+
getJoiner(): ResultJoiner;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Create a query executor instance.
|
|
500
|
+
*
|
|
501
|
+
* @param db - PowerSync database instance
|
|
502
|
+
* @param schema - Database schema
|
|
503
|
+
* @returns QueryExecutor instance
|
|
504
|
+
*/
|
|
505
|
+
declare function createQueryExecutor(db: PowerSyncDatabase, schema: DatabaseSchema): QueryExecutor;
|
|
506
|
+
|
|
507
|
+
export { type PowerSyncDatabase as P, QueryExecutor as Q, RelationshipResolver as R, SQLBuilder as S, createSQLBuilder as a, ResultJoiner as b, createRelationshipResolver as c, createResultJoiner as d, type RelationJoinData as e, createQueryExecutor as f };
|