@promakeai/dbreact 1.0.1 → 1.0.4
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 +122 -106
- package/dist/adapters/RestAdapter.d.ts +83 -0
- package/dist/adapters/SqliteAdapter.d.ts +169 -0
- package/dist/adapters/SqliteAdapter.d.ts.map +1 -1
- package/dist/core/DataManager.d.ts +147 -0
- package/dist/hooks/useDataManager.d.ts +7 -0
- package/dist/hooks/useDbHooks.d.ts +132 -0
- package/dist/hooks/useDbHooks.d.ts.map +1 -1
- package/dist/hooks/useDbLang.d.ts +7 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +61 -12
- package/dist/providers/DbProvider.d.ts +47 -0
- package/dist/providers/DbProvider.d.ts.map +1 -1
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/whereBuilder.d.ts +39 -0
- package/package.json +5 -2
- package/SKILL.md +0 -311
- package/providers/DbProvider.tsx +0 -191
package/README.md
CHANGED
|
@@ -4,12 +4,12 @@ React hooks and providers for schema-driven, multi-language databases. Type-safe
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **Type-Safe Hooks** -
|
|
7
|
+
- **Type-Safe Hooks** - Generic React hooks with generated TypeScript types
|
|
8
8
|
- **Multi-Language Support** - Automatic translation queries with fallback
|
|
9
9
|
- **Browser SQLite** - sql.js WASM adapter for offline-first apps
|
|
10
|
-
- **React Query Integration** - Built-in caching, loading states, optimistic updates
|
|
11
|
-
- **Zero-Config Language Switching** - Change language, queries refetch automatically
|
|
12
|
-
- **MongoDB-Style Queries** - Intuitive filter syntax (`$gt`, `$in`, `$like`, etc.)
|
|
10
|
+
- **React Query Integration** - Built-in caching, loading states, optimistic updates
|
|
11
|
+
- **Zero-Config Language Switching** - Change language, queries refetch automatically
|
|
12
|
+
- **MongoDB-Style Queries** - Intuitive filter syntax (`$gt`, `$in`, `$like`, `$contains`, etc.)
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -26,11 +26,16 @@ npm install @promakeai/dbreact @tanstack/react-query
|
|
|
26
26
|
### 1. Setup Adapter
|
|
27
27
|
|
|
28
28
|
```tsx
|
|
29
|
-
import { SqliteAdapter } from '@promakeai/dbreact';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
import { SqliteAdapter } from '@promakeai/dbreact';
|
|
30
|
+
import { parseJSONSchema } from '@promakeai/dbreact';
|
|
31
|
+
import schemaJson from './schema.json';
|
|
32
|
+
|
|
33
|
+
const schema = parseJSONSchema(schemaJson as any);
|
|
34
|
+
|
|
35
|
+
const adapter = new SqliteAdapter({
|
|
36
|
+
storageKey: 'myapp-db', // localStorage key for persistence
|
|
37
|
+
schema,
|
|
38
|
+
});
|
|
34
39
|
```
|
|
35
40
|
|
|
36
41
|
### 2. Wrap App with Provider
|
|
@@ -98,24 +103,27 @@ Main provider component that wraps your application.
|
|
|
98
103
|
|
|
99
104
|
```tsx
|
|
100
105
|
<DbProvider
|
|
101
|
-
adapter={adapter}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
adapter={adapter}
|
|
107
|
+
schema={schema}
|
|
108
|
+
lang="tr"
|
|
109
|
+
fallbackLang="en"
|
|
110
|
+
autoConnect={true}
|
|
111
|
+
>
|
|
106
112
|
<App />
|
|
107
113
|
</DbProvider>
|
|
108
114
|
```
|
|
109
115
|
|
|
110
116
|
**Props:**
|
|
111
117
|
|
|
112
|
-
| Prop | Type | Required | Default | Description |
|
|
113
|
-
|------|------|----------|---------|-------------|
|
|
114
|
-
| `adapter` | `IDataAdapter` | Yes | - | Database adapter instance |
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
118
|
+
| Prop | Type | Required | Default | Description |
|
|
119
|
+
|------|------|----------|---------|-------------|
|
|
120
|
+
| `adapter` | `IDataAdapter` | Yes | - | Database adapter instance |
|
|
121
|
+
| `schema` | `SchemaDefinition` | No | - | Enables populate + typed serialization |
|
|
122
|
+
| `lang` | `string` | No | `'en'` | Current language code |
|
|
123
|
+
| `fallbackLang` | `string` | No | `'en'` | Fallback language |
|
|
124
|
+
| `autoConnect` | `boolean` | No | `true` | Auto-connect on mount |
|
|
125
|
+
| `queryClient` | `QueryClient` | No | Internal | Provide a custom React Query client |
|
|
126
|
+
| `children` | `ReactNode` | Yes | - | Child components |
|
|
119
127
|
|
|
120
128
|
---
|
|
121
129
|
|
|
@@ -143,19 +151,29 @@ const { data, isLoading, error, refetch } = useDbList<Product>('products', {
|
|
|
143
151
|
| `orderBy` | `array` | Sort order `[{ field, direction }]` |
|
|
144
152
|
| `limit` | `number` | Max records to return |
|
|
145
153
|
| `offset` | `number` | Skip records |
|
|
146
|
-
| `populate` | `
|
|
154
|
+
| `populate` | `PopulateOption` | Resolve foreign key references (string, array, or object) |
|
|
147
155
|
| `enabled` | `boolean` | Enable/disable query |
|
|
148
156
|
|
|
149
|
-
#### useDbGet
|
|
150
|
-
|
|
151
|
-
Fetch single record by ID.
|
|
152
|
-
|
|
153
|
-
```tsx
|
|
154
|
-
const { data: product, isLoading } = useDbGet<Product>('products', productId, {
|
|
155
|
-
populate: ['categoryId'],
|
|
156
|
-
enabled: !!productId,
|
|
157
|
-
});
|
|
158
|
-
```
|
|
157
|
+
#### useDbGet
|
|
158
|
+
|
|
159
|
+
Fetch single record by ID.
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
const { data: product, isLoading } = useDbGet<Product>('products', productId, {
|
|
163
|
+
populate: ['categoryId'],
|
|
164
|
+
enabled: !!productId,
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Find-one style (by where clause):
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
const { data: product } = useDbGet<Product>('products', {
|
|
172
|
+
where: { slug: 'my-product' },
|
|
173
|
+
enabled: !!slug,
|
|
174
|
+
populate: { categoryId: true },
|
|
175
|
+
});
|
|
176
|
+
```
|
|
159
177
|
|
|
160
178
|
---
|
|
161
179
|
|
|
@@ -182,13 +200,13 @@ createProduct.mutate(
|
|
|
182
200
|
Update an existing record.
|
|
183
201
|
|
|
184
202
|
```tsx
|
|
185
|
-
const updateProduct = useDbUpdate<Product>('products'
|
|
186
|
-
|
|
187
|
-
updateProduct.mutate(
|
|
188
|
-
{ price: 89.99 },
|
|
189
|
-
{
|
|
190
|
-
onSuccess: () => console.log('Updated'),
|
|
191
|
-
}
|
|
203
|
+
const updateProduct = useDbUpdate<Product>('products');
|
|
204
|
+
|
|
205
|
+
updateProduct.mutate(
|
|
206
|
+
{ id: productId, data: { price: 89.99 } },
|
|
207
|
+
{
|
|
208
|
+
onSuccess: () => console.log('Updated'),
|
|
209
|
+
}
|
|
192
210
|
);
|
|
193
211
|
```
|
|
194
212
|
|
|
@@ -197,11 +215,11 @@ updateProduct.mutate(
|
|
|
197
215
|
Delete a record.
|
|
198
216
|
|
|
199
217
|
```tsx
|
|
200
|
-
const deleteProduct = useDbDelete('products'
|
|
201
|
-
|
|
202
|
-
deleteProduct.mutate(
|
|
203
|
-
onSuccess: () => console.log('Deleted'),
|
|
204
|
-
});
|
|
218
|
+
const deleteProduct = useDbDelete('products');
|
|
219
|
+
|
|
220
|
+
deleteProduct.mutate(productId, {
|
|
221
|
+
onSuccess: () => console.log('Deleted'),
|
|
222
|
+
});
|
|
205
223
|
```
|
|
206
224
|
|
|
207
225
|
---
|
|
@@ -294,12 +312,16 @@ const adapter = new SqliteAdapter({
|
|
|
294
312
|
{ name: { $like: '%shirt%' } } // LIKE '%shirt%'
|
|
295
313
|
{ name: { $notLike: '%test%' } } // NOT LIKE '%test%'
|
|
296
314
|
|
|
297
|
-
// Range
|
|
298
|
-
{ price: { $between: [10, 100] } } // BETWEEN 10 AND 100
|
|
299
|
-
|
|
300
|
-
// Null
|
|
301
|
-
{ description: { $isNull: true } } // IS NULL
|
|
302
|
-
{ description: { $isNull: false } } // IS NOT NULL
|
|
315
|
+
// Range
|
|
316
|
+
{ price: { $between: [10, 100] } } // BETWEEN 10 AND 100
|
|
317
|
+
|
|
318
|
+
// Null
|
|
319
|
+
{ description: { $isNull: true } } // IS NULL
|
|
320
|
+
{ description: { $isNull: false } } // IS NOT NULL
|
|
321
|
+
|
|
322
|
+
// JSON array contains
|
|
323
|
+
{ tags: { $contains: "sale" } }
|
|
324
|
+
{ tags: { $containsAny: ["sale", "new"] } }
|
|
303
325
|
|
|
304
326
|
// Logical
|
|
305
327
|
{ $and: [
|
|
@@ -318,18 +340,18 @@ const adapter = new SqliteAdapter({
|
|
|
318
340
|
### Query Interface
|
|
319
341
|
|
|
320
342
|
```typescript
|
|
321
|
-
interface QueryOptions {
|
|
322
|
-
where?: Record<string, unknown>;
|
|
323
|
-
orderBy?: Array<{
|
|
324
|
-
field: string;
|
|
325
|
-
direction: 'ASC' | 'DESC';
|
|
326
|
-
}>;
|
|
327
|
-
limit?: number;
|
|
328
|
-
offset?: number;
|
|
329
|
-
populate?:
|
|
330
|
-
lang?: string;
|
|
331
|
-
fallbackLang?: string;
|
|
332
|
-
}
|
|
343
|
+
interface QueryOptions {
|
|
344
|
+
where?: Record<string, unknown>;
|
|
345
|
+
orderBy?: Array<{
|
|
346
|
+
field: string;
|
|
347
|
+
direction: 'ASC' | 'DESC';
|
|
348
|
+
}>;
|
|
349
|
+
limit?: number;
|
|
350
|
+
offset?: number;
|
|
351
|
+
populate?: PopulateOption;
|
|
352
|
+
lang?: string;
|
|
353
|
+
fallbackLang?: string;
|
|
354
|
+
}
|
|
333
355
|
```
|
|
334
356
|
|
|
335
357
|
---
|
|
@@ -387,36 +409,32 @@ function LanguageSwitcher() {
|
|
|
387
409
|
|
|
388
410
|
---
|
|
389
411
|
|
|
390
|
-
## Generated Hooks
|
|
391
|
-
|
|
392
|
-
Generate
|
|
393
|
-
|
|
394
|
-
```bash
|
|
395
|
-
dbcli generate --schema ./schema.
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
// ...
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
```
|
|
412
|
+
## Generated Types + Generic Hooks
|
|
413
|
+
|
|
414
|
+
Generate runtime schema and TypeScript interfaces:
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
dbcli generate --schema ./schema.json --output ./src/db
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
`dbcli generate` writes `schema.json` and `types.ts`. React hooks are imported from `@promakeai/dbreact`:
|
|
421
|
+
|
|
422
|
+
```tsx
|
|
423
|
+
import { useDbList, useDbGet, useDbCreate } from '@promakeai/dbreact';
|
|
424
|
+
import type { DbProduct, DbProductInput } from './db/types';
|
|
425
|
+
|
|
426
|
+
function ProductManager() {
|
|
427
|
+
const { data: products } = useDbList<DbProduct>('products', {
|
|
428
|
+
where: { stock: { $gt: 0 } },
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
const { data: product } = useDbGet<DbProduct>('products', 1);
|
|
432
|
+
|
|
433
|
+
const createProduct = useDbCreate<DbProduct, DbProductInput>('products');
|
|
434
|
+
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
```
|
|
420
438
|
|
|
421
439
|
---
|
|
422
440
|
|
|
@@ -425,15 +443,10 @@ function ProductManager() {
|
|
|
425
443
|
### Custom React Query Options
|
|
426
444
|
|
|
427
445
|
```tsx
|
|
428
|
-
const { data } = useDbList('products', {
|
|
429
|
-
where: { active: true },
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
433
|
-
gcTime: 1000 * 60 * 30, // 30 minutes
|
|
434
|
-
refetchOnWindowFocus: false,
|
|
435
|
-
retry: 3,
|
|
436
|
-
});
|
|
446
|
+
const { data } = useDbList('products', {
|
|
447
|
+
where: { active: true },
|
|
448
|
+
limit: 50,
|
|
449
|
+
});
|
|
437
450
|
```
|
|
438
451
|
|
|
439
452
|
### Direct Adapter Access
|
|
@@ -467,7 +480,7 @@ function AdvancedSearch() {
|
|
|
467
480
|
```tsx
|
|
468
481
|
function ProductPrice({ product }) {
|
|
469
482
|
const queryClient = useQueryClient();
|
|
470
|
-
const updateProduct = useDbUpdate('products'
|
|
483
|
+
const updateProduct = useDbUpdate('products');
|
|
471
484
|
|
|
472
485
|
const handlePriceChange = async (newPrice: number) => {
|
|
473
486
|
// Optimistic update
|
|
@@ -476,7 +489,10 @@ function ProductPrice({ product }) {
|
|
|
476
489
|
{ ...product, price: newPrice }
|
|
477
490
|
);
|
|
478
491
|
|
|
479
|
-
await updateProduct.mutateAsync({
|
|
492
|
+
await updateProduct.mutateAsync({
|
|
493
|
+
id: product.id,
|
|
494
|
+
data: { price: newPrice },
|
|
495
|
+
});
|
|
480
496
|
};
|
|
481
497
|
|
|
482
498
|
return <PriceInput value={product.price} onChange={handlePriceChange} />;
|
|
@@ -568,13 +584,13 @@ function ProductSearch() {
|
|
|
568
584
|
Full TypeScript support with generated types:
|
|
569
585
|
|
|
570
586
|
```typescript
|
|
571
|
-
import type {
|
|
587
|
+
import type { DbProduct, DbProductInput } from './db/types';
|
|
572
588
|
|
|
573
589
|
// Type-safe queries
|
|
574
|
-
const products:
|
|
590
|
+
const products: DbProduct[] = await adapter.list('products');
|
|
575
591
|
|
|
576
592
|
// Type-safe creates
|
|
577
|
-
const newProduct:
|
|
593
|
+
const newProduct: DbProductInput = {
|
|
578
594
|
sku: 'SHIRT-001',
|
|
579
595
|
price: 99.99,
|
|
580
596
|
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REST API Adapter
|
|
3
|
+
*
|
|
4
|
+
* Fetches data from a REST API backend.
|
|
5
|
+
* Sends Accept-Language header for multi-language support.
|
|
6
|
+
*/
|
|
7
|
+
import type { IDataAdapter, QueryOptions, PaginatedResult } from "../types";
|
|
8
|
+
export interface RestAdapterConfig {
|
|
9
|
+
/** Base URL for API (e.g., "https://api.example.com") */
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
/** Language code for Accept-Language header */
|
|
12
|
+
lang?: string;
|
|
13
|
+
/** Custom headers to include in all requests */
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
/** Custom fetch function (for testing/SSR) */
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* REST API Adapter
|
|
20
|
+
*
|
|
21
|
+
* Makes HTTP requests to a REST API backend.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const adapter = new RestAdapter({
|
|
26
|
+
* baseUrl: 'https://api.example.com',
|
|
27
|
+
* lang: 'tr'
|
|
28
|
+
* });
|
|
29
|
+
* const users = await adapter.findMany('users');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class RestAdapter implements IDataAdapter {
|
|
33
|
+
private config;
|
|
34
|
+
constructor(config: RestAdapterConfig);
|
|
35
|
+
connect(): Promise<void>;
|
|
36
|
+
private buildUrl;
|
|
37
|
+
private getHeaders;
|
|
38
|
+
private request;
|
|
39
|
+
private buildQueryParams;
|
|
40
|
+
findMany<T = unknown>(table: string, options?: QueryOptions): Promise<T[]>;
|
|
41
|
+
findOne<T = unknown>(table: string, options?: QueryOptions): Promise<T | null>;
|
|
42
|
+
findById<T = unknown>(table: string, id: number | string): Promise<T | null>;
|
|
43
|
+
count(table: string, options?: QueryOptions): Promise<number>;
|
|
44
|
+
paginate<T = unknown>(table: string, page: number, limit: number, options?: QueryOptions): Promise<PaginatedResult<T>>;
|
|
45
|
+
create<T = unknown>(table: string, data: Record<string, unknown>): Promise<T>;
|
|
46
|
+
update<T = unknown>(table: string, id: number | string, data: Record<string, unknown>): Promise<T>;
|
|
47
|
+
delete(table: string, id: number | string): Promise<boolean>;
|
|
48
|
+
execute(_query: string, _params?: unknown[]): Promise<void>;
|
|
49
|
+
executeQuery<T = unknown>(_query: string, _params?: unknown[]): Promise<T[]>;
|
|
50
|
+
seed(data: Record<string, Record<string, unknown>[]>): Promise<void>;
|
|
51
|
+
getTables(): Promise<string[]>;
|
|
52
|
+
getTableSchema(table: string): Promise<{
|
|
53
|
+
name: string;
|
|
54
|
+
type: string;
|
|
55
|
+
notnull: number;
|
|
56
|
+
pk: number;
|
|
57
|
+
}[]>;
|
|
58
|
+
close(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Update language for subsequent requests
|
|
61
|
+
*/
|
|
62
|
+
setLang(lang: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get current language
|
|
65
|
+
*/
|
|
66
|
+
getLang(): string;
|
|
67
|
+
createMany<T = unknown>(table: string, records: Record<string, unknown>[], options?: {
|
|
68
|
+
ignore?: boolean;
|
|
69
|
+
}): Promise<{
|
|
70
|
+
created: number;
|
|
71
|
+
ids: (number | bigint)[];
|
|
72
|
+
}>;
|
|
73
|
+
updateMany(table: string, updates: {
|
|
74
|
+
id: number | string;
|
|
75
|
+
data: Record<string, unknown>;
|
|
76
|
+
}[]): Promise<{
|
|
77
|
+
updated: number;
|
|
78
|
+
}>;
|
|
79
|
+
deleteMany(table: string, ids: (number | string)[]): Promise<{
|
|
80
|
+
deleted: number;
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=RestAdapter.d.ts.map
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser SQLite Adapter
|
|
3
|
+
*
|
|
4
|
+
* Uses sql.js (WASM) for in-browser SQLite database.
|
|
5
|
+
* Persists to localStorage for offline support.
|
|
6
|
+
*/
|
|
7
|
+
import type { IDataAdapter, QueryOptions, PaginatedResult, SchemaDefinition } from "@promakeai/orm";
|
|
8
|
+
export interface SqliteAdapterConfig {
|
|
9
|
+
/** localStorage key for persistence (default: "dbreact_db") */
|
|
10
|
+
storageKey?: string;
|
|
11
|
+
/** sql.js WASM path (default: CDN) */
|
|
12
|
+
wasmPath?: string;
|
|
13
|
+
/** Initial data to seed if database is empty */
|
|
14
|
+
initialData?: Uint8Array;
|
|
15
|
+
/** Schema definition for translation support */
|
|
16
|
+
schema?: SchemaDefinition;
|
|
17
|
+
/** Default language for translations */
|
|
18
|
+
defaultLang?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Browser SQLite Adapter
|
|
22
|
+
*
|
|
23
|
+
* Provides SQLite database in the browser using sql.js WASM.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const adapter = new SqliteAdapter({ storageKey: 'myapp' });
|
|
28
|
+
* await adapter.connect();
|
|
29
|
+
* const users = await adapter.list('users');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class SqliteAdapter implements IDataAdapter {
|
|
33
|
+
private db;
|
|
34
|
+
private SQL;
|
|
35
|
+
private tableColumnsCache;
|
|
36
|
+
private config;
|
|
37
|
+
schema?: SchemaDefinition;
|
|
38
|
+
defaultLang?: string;
|
|
39
|
+
constructor(config?: SqliteAdapterConfig);
|
|
40
|
+
setSchema(schema: SchemaDefinition): void;
|
|
41
|
+
connect(): Promise<void>;
|
|
42
|
+
private persist;
|
|
43
|
+
private getDb;
|
|
44
|
+
private runQuery;
|
|
45
|
+
/**
|
|
46
|
+
* Deserialize rows using schema field definitions (bool 0/1 → boolean, json TEXT → parsed)
|
|
47
|
+
*/
|
|
48
|
+
private deserializeResults;
|
|
49
|
+
/**
|
|
50
|
+
* Serialize data for DB storage (bool → 0/1, json → TEXT)
|
|
51
|
+
*/
|
|
52
|
+
private serializeData;
|
|
53
|
+
private buildSelectQuery;
|
|
54
|
+
/**
|
|
55
|
+
* List records from a table
|
|
56
|
+
*/
|
|
57
|
+
list<T = unknown>(table: string, options?: QueryOptions): Promise<T[]>;
|
|
58
|
+
private listWithLang;
|
|
59
|
+
/**
|
|
60
|
+
* Get a single record by ID
|
|
61
|
+
*/
|
|
62
|
+
get<T = unknown>(table: string, id: number | string, options?: {
|
|
63
|
+
lang?: string;
|
|
64
|
+
fallbackLang?: string;
|
|
65
|
+
}): Promise<T | null>;
|
|
66
|
+
findOne<T = unknown>(table: string, options?: {
|
|
67
|
+
where?: Record<string, unknown>;
|
|
68
|
+
lang?: string;
|
|
69
|
+
fallbackLang?: string;
|
|
70
|
+
}): Promise<T | null>;
|
|
71
|
+
private getWithLang;
|
|
72
|
+
/**
|
|
73
|
+
* Count records in a table
|
|
74
|
+
*/
|
|
75
|
+
count(table: string, options?: QueryOptions): Promise<number>;
|
|
76
|
+
/**
|
|
77
|
+
* Paginate records
|
|
78
|
+
*/
|
|
79
|
+
paginate<T = unknown>(table: string, page: number, limit: number, options?: QueryOptions): Promise<PaginatedResult<T>>;
|
|
80
|
+
/**
|
|
81
|
+
* Create a new record
|
|
82
|
+
*/
|
|
83
|
+
create<T = unknown>(table: string, data: Record<string, unknown>): Promise<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Create a record with explicit translations
|
|
86
|
+
*/
|
|
87
|
+
createWithTranslations<T = unknown>(table: string, data: Record<string, unknown>, translations?: Record<string, Record<string, unknown>>): Promise<T>;
|
|
88
|
+
/**
|
|
89
|
+
* Update a record by ID
|
|
90
|
+
*/
|
|
91
|
+
update<T = unknown>(table: string, id: number | string, data: Record<string, unknown>): Promise<T>;
|
|
92
|
+
/**
|
|
93
|
+
* Upsert a translation for a record
|
|
94
|
+
*/
|
|
95
|
+
upsertTranslation(table: string, id: number | string, lang: string, data: Record<string, unknown>): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Get all translations for a record
|
|
98
|
+
*/
|
|
99
|
+
getTranslations<T = unknown>(table: string, id: number | string): Promise<T[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Delete a record by ID
|
|
102
|
+
*/
|
|
103
|
+
delete(table: string, id: number | string): Promise<boolean>;
|
|
104
|
+
/**
|
|
105
|
+
* Execute a raw SQL statement
|
|
106
|
+
*/
|
|
107
|
+
execute(query: string, params?: unknown[]): Promise<{
|
|
108
|
+
changes: number;
|
|
109
|
+
lastInsertRowid: number | bigint;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Execute a raw SQL query and return results
|
|
113
|
+
*/
|
|
114
|
+
raw<T = unknown>(query: string, params?: unknown[]): Promise<T[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Seed database with initial data
|
|
117
|
+
*/
|
|
118
|
+
seed(data: Record<string, Record<string, unknown>[]>): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Get all table names
|
|
121
|
+
*/
|
|
122
|
+
getTables(): Promise<string[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Get table schema
|
|
125
|
+
*/
|
|
126
|
+
getTableSchema(table: string): Promise<{
|
|
127
|
+
name: string;
|
|
128
|
+
type: string;
|
|
129
|
+
notnull: number;
|
|
130
|
+
pk: number;
|
|
131
|
+
}[]>;
|
|
132
|
+
/**
|
|
133
|
+
* Close the database connection
|
|
134
|
+
*/
|
|
135
|
+
close(): void;
|
|
136
|
+
beginTransaction(): Promise<void>;
|
|
137
|
+
commit(): Promise<void>;
|
|
138
|
+
rollback(): Promise<void>;
|
|
139
|
+
createMany<T = unknown>(table: string, records: Record<string, unknown>[], options?: {
|
|
140
|
+
ignore?: boolean;
|
|
141
|
+
}): Promise<{
|
|
142
|
+
created: number;
|
|
143
|
+
ids: (number | bigint)[];
|
|
144
|
+
}>;
|
|
145
|
+
private getAvailableMainFallbackFields;
|
|
146
|
+
private getTableColumns;
|
|
147
|
+
updateMany(table: string, updates: {
|
|
148
|
+
id: number | string;
|
|
149
|
+
data: Record<string, unknown>;
|
|
150
|
+
}[]): Promise<{
|
|
151
|
+
updated: number;
|
|
152
|
+
}>;
|
|
153
|
+
deleteMany(table: string, ids: (number | string)[]): Promise<{
|
|
154
|
+
deleted: number;
|
|
155
|
+
}>;
|
|
156
|
+
/**
|
|
157
|
+
* Export database as Uint8Array
|
|
158
|
+
*/
|
|
159
|
+
export(): Uint8Array;
|
|
160
|
+
/**
|
|
161
|
+
* Import database from Uint8Array
|
|
162
|
+
*/
|
|
163
|
+
import(data: Uint8Array): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Clear all data and reset database
|
|
166
|
+
*/
|
|
167
|
+
clear(): void;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=SqliteAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteAdapter.d.ts","sourceRoot":"","sources":["../../adapters/SqliteAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAepG,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,gDAAgD;IAChD,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,YAAW,YAAY;IAChD,OAAO,CAAC,EAAE,CAAyB;IACnC,OAAO,CAAC,GAAG,CAA4B;IACvC,OAAO,CAAC,MAAM,CAGZ;IAEF,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;gBAET,MAAM,GAAE,mBAAwB;IAc5C,SAAS,CAAC,MAAM,EAAE,gBAAgB,G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