allez-orm 1.0.3 → 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/index.d.ts +41 -0
- package/package.json +10 -4
- package/types/index.d.ts +0 -80
package/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// index.d.ts
|
|
2
|
+
export interface Schema {
|
|
3
|
+
table: string;
|
|
4
|
+
createSQL: string;
|
|
5
|
+
extraSQL?: string[];
|
|
6
|
+
version?: number;
|
|
7
|
+
onUpgrade?(db: any, from: number, to: number): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface InitOptions {
|
|
11
|
+
dbName?: string;
|
|
12
|
+
autoSaveMs?: number;
|
|
13
|
+
wasmLocateFile?(file: string): string;
|
|
14
|
+
schemas?: Schema[];
|
|
15
|
+
schemaModules?: Record<string, { default: Schema }>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type Row = Record<string, any>;
|
|
19
|
+
|
|
20
|
+
export interface TableHelper<T extends Row = Row> {
|
|
21
|
+
insert(obj: Partial<T>): Promise<void>;
|
|
22
|
+
upsert(obj: Partial<T>): Promise<void>;
|
|
23
|
+
update(id: any, patch: Partial<T>): Promise<void>;
|
|
24
|
+
deleteSoft(id: any, ts?: string): Promise<void>;
|
|
25
|
+
remove(id: any): Promise<void>;
|
|
26
|
+
findById(id: any): Promise<T | null>;
|
|
27
|
+
searchLike(q: string, columns: (keyof T | string)[], limit?: number): Promise<T[]>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class AllezORM {
|
|
31
|
+
constructor(SQL: any, db: any, opts: InitOptions);
|
|
32
|
+
static init(opts?: InitOptions): Promise<AllezORM>;
|
|
33
|
+
saveNow(): Promise<void>;
|
|
34
|
+
exec(sql: string, params?: any[]): Promise<boolean>;
|
|
35
|
+
run(sql: string, params?: any[]): Promise<boolean>;
|
|
36
|
+
execute(sql: string, params?: any[]): Promise<void>;
|
|
37
|
+
query<T = Row>(sql: string, params?: any[]): Promise<T[]>;
|
|
38
|
+
get<T = Row>(sql: string, params?: any[]): Promise<T | null>;
|
|
39
|
+
table<T extends Row = Row>(table: string): TableHelper<T>;
|
|
40
|
+
registerSchemas(schemas: Schema[]): Promise<void>;
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "allez-orm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "AllezORM: lightweight browser SQLite ORM (sql.js) + schema generator CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./allez-orm.mjs",
|
|
7
7
|
"module": "./allez-orm.mjs",
|
|
8
8
|
"browser": "./allez-orm.mjs",
|
|
9
|
-
"types": "./
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"typesVersions": {
|
|
11
|
+
"*": {
|
|
12
|
+
"*": [
|
|
13
|
+
"index.d.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
10
17
|
"exports": {
|
|
11
18
|
".": {
|
|
12
|
-
"types": "./types/index.d.ts",
|
|
13
19
|
"import": "./allez-orm.mjs",
|
|
14
20
|
"default": "./allez-orm.mjs"
|
|
15
21
|
},
|
|
@@ -30,7 +36,7 @@
|
|
|
30
36
|
},
|
|
31
37
|
"files": [
|
|
32
38
|
"allez-orm.mjs",
|
|
33
|
-
"
|
|
39
|
+
"index.d.ts",
|
|
34
40
|
"tools/allez-orm.mjs",
|
|
35
41
|
"tools/ddl-audit.mjs",
|
|
36
42
|
"README.md",
|
package/types/index.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// types/index.d.ts
|
|
2
|
-
|
|
3
|
-
// ===== Public model types =====
|
|
4
|
-
export interface Schema {
|
|
5
|
-
/** table name */
|
|
6
|
-
table: string;
|
|
7
|
-
/** CREATE TABLE IF NOT EXISTS ... */
|
|
8
|
-
createSQL: string;
|
|
9
|
-
/** indexes / triggers / FTS setup */
|
|
10
|
-
extraSQL?: string[];
|
|
11
|
-
/** defaults to 1 */
|
|
12
|
-
version?: number;
|
|
13
|
-
/** run when schema version increases */
|
|
14
|
-
onUpgrade?(
|
|
15
|
-
db: any, // low-level sql.js Database (same instance you construct in init)
|
|
16
|
-
from: number,
|
|
17
|
-
to: number
|
|
18
|
-
): void | Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface InitOptions {
|
|
22
|
-
dbName?: string;
|
|
23
|
-
autoSaveMs?: number;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the URL for the sql.js wasm file (e.g. f => `https://sql.js.org/dist/${f}`)
|
|
26
|
-
*/
|
|
27
|
-
wasmLocateFile?(file: string): string;
|
|
28
|
-
/** schema list to create/upgrade */
|
|
29
|
-
schemas?: Schema[];
|
|
30
|
-
/**
|
|
31
|
-
* For bundlers (e.g. Vite import.meta.glob results):
|
|
32
|
-
* { "./schemas/user.js": { default: Schema }, ... }
|
|
33
|
-
*/
|
|
34
|
-
schemaModules?: Record<string, { default: Schema }>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Result rows are plain objects from sql.js getAsObject() */
|
|
38
|
-
export type Row = Record<string, any>;
|
|
39
|
-
|
|
40
|
-
/** Helper interface returned by table('<name>') */
|
|
41
|
-
export interface TableHelper<T extends Row = Row> {
|
|
42
|
-
insert(obj: Partial<T>): Promise<void>;
|
|
43
|
-
upsert(obj: Partial<T>): Promise<void>;
|
|
44
|
-
update(id: any, patch: Partial<T>): Promise<void>;
|
|
45
|
-
/** soft-delete: sets deleted_at */
|
|
46
|
-
deleteSoft(id: any, ts?: string): Promise<void>;
|
|
47
|
-
/** hard delete */
|
|
48
|
-
remove(id: any): Promise<void>;
|
|
49
|
-
findById(id: any): Promise<T | null>;
|
|
50
|
-
/** WHERE col LIKE ? OR ... LIMIT ? */
|
|
51
|
-
searchLike(q: string, columns: (keyof T | string)[], limit?: number): Promise<T[]>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// ===== Main class =====
|
|
55
|
-
export class AllezORM {
|
|
56
|
-
/** Constructed by `init`, but exported for advanced usage */
|
|
57
|
-
constructor(SQL: any, db: any, opts: InitOptions);
|
|
58
|
-
|
|
59
|
-
// ---- lifecycle ----
|
|
60
|
-
static init(opts?: InitOptions): Promise<AllezORM>;
|
|
61
|
-
saveNow(): Promise<void>;
|
|
62
|
-
|
|
63
|
-
// ---- SQL helpers ----
|
|
64
|
-
/** run arbitrary SQL (DDL/DML). Returns true on success. */
|
|
65
|
-
exec(sql: string, params?: any[]): Promise<boolean>;
|
|
66
|
-
/** alias of exec */
|
|
67
|
-
run(sql: string, params?: any[]): Promise<boolean>;
|
|
68
|
-
/** prepared exec that schedules persistence */
|
|
69
|
-
execute(sql: string, params?: any[]): Promise<void>;
|
|
70
|
-
/** SELECT ... -> array of objects */
|
|
71
|
-
query<T = Row>(sql: string, params?: any[]): Promise<T[]>;
|
|
72
|
-
/** SELECT ... LIMIT 1 -> single row or null */
|
|
73
|
-
get<T = Row>(sql: string, params?: any[]): Promise<T | null>;
|
|
74
|
-
|
|
75
|
-
// ---- tables & schemas ----
|
|
76
|
-
/** convenience helpers bound to a single table */
|
|
77
|
-
table<T extends Row = Row>(table: string): TableHelper<T>;
|
|
78
|
-
/** create/upgrade all schemas; persists versions in allez_meta */
|
|
79
|
-
registerSchemas(schemas: Schema[]): Promise<void>;
|
|
80
|
-
}
|