-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.d.ts
84 lines (73 loc) · 2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
interface QueryOptions {
parse: boolean;
}
interface DatabaseConfig {
debug?: boolean;
}
interface SQLiteConfig extends DatabaseConfig {
db: string | URL;
sql: string | URL;
tables: string | URL;
views: string | URL;
extensions?: string | URL | Array<string | URL>;
adaptor: any;
}
interface TursoConfig extends DatabaseConfig {
db: any;
files: any;
}
interface D1Config extends DatabaseConfig {
db: any;
files: any;
}
interface FileSystem {
readFile: (path: string, encoding: string) => Promise<string>;
writeFile: (path: string, content: string) => Promise<void>;
readdir: (path: string) => Promise<string[]>;
join: (...paths: string[]) => string;
readSql: (path: string) => Promise<string>;
}
interface Paths {
tables: string;
views: string;
sql: string;
types: string;
migrations: string;
wrangler?: string;
files?: string;
}
declare class Database {
constructor(options: DatabaseConfig);
runMigration(sql: string): Promise<void>;
makeTypes(fileSystem: FileSystem, paths: Paths): Promise<void>;
getClient<T>(): T;
getTables(): Promise<string>;
createMigration(fileSystem: FileSystem, paths: Paths, name: string, reset?: boolean): Promise<string>;
run(args: { query: any, params?: any }): Promise<number>;
all<T>(args: { query: any, params?: any, options?: QueryOptions }): Promise<Array<T>>;
exec(query: string): Promise<void>;
}
declare class SQLiteDatabase extends Database {
constructor(options: SQLiteConfig);
begin(): Promise<void>;
commit(): Promise<void>;
rollback(): Promise<void>;
close(): Promise<void>;
}
declare class TursoDatabase extends Database {
constructor(options: TursoConfig);
begin(): Promise<void>;
commit(): Promise<void>;
rollback(): Promise<void>;
batch(handler: (batcher: any) => any[]): Promise<any[]>;
}
declare class D1Database extends Database {
constructor(options: D1Config);
batch(handler: (batcher: any) => any[]): Promise<any[]>;
}
export {
Database,
SQLiteDatabase,
TursoDatabase,
D1Database
}