driftsql 1.0.12 → 1.0.13
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 +203 -118
- package/dist/index.d.mts +105 -46
- package/dist/index.d.ts +105 -46
- package/dist/index.mjs +308 -402
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,74 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface QueryResult<T = any> {
|
|
2
|
+
rows: T[];
|
|
3
|
+
rowCount: number;
|
|
4
|
+
command?: string;
|
|
5
|
+
fields?: QueryField[];
|
|
6
|
+
}
|
|
7
|
+
interface QueryField {
|
|
8
|
+
name: string;
|
|
9
|
+
dataTypeID: number;
|
|
10
|
+
}
|
|
11
|
+
interface DatabaseDriver {
|
|
12
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
interface TransactionCapable {
|
|
16
|
+
transaction<T>(callback: (driver: DatabaseDriver) => Promise<T>): Promise<T>;
|
|
17
|
+
}
|
|
18
|
+
interface PreparedStatementCapable {
|
|
19
|
+
prepare(sql: string): Promise<PreparedStatement>;
|
|
20
|
+
}
|
|
21
|
+
interface PreparedStatement {
|
|
22
|
+
execute<T = any>(params?: any[]): Promise<QueryResult<T>>;
|
|
23
|
+
finalize(): Promise<void>;
|
|
24
|
+
}
|
|
4
25
|
|
|
5
26
|
interface PostgresConfig {
|
|
6
27
|
connectionString?: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
http?: {
|
|
13
|
-
url: string;
|
|
14
|
-
apiKey?: string;
|
|
15
|
-
};
|
|
28
|
+
experimental?: {
|
|
29
|
+
http?: {
|
|
30
|
+
url: string;
|
|
31
|
+
apiKey?: string;
|
|
16
32
|
};
|
|
17
|
-
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
declare class PostgresDriver implements DatabaseDriver, TransactionCapable {
|
|
36
|
+
private client;
|
|
37
|
+
constructor(config: PostgresConfig);
|
|
38
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
39
|
+
transaction<T>(callback: (driver: DatabaseDriver) => Promise<T>): Promise<T>;
|
|
40
|
+
close(): Promise<void>;
|
|
18
41
|
}
|
|
19
42
|
|
|
20
43
|
interface LibSQLConfig {
|
|
21
44
|
url: string;
|
|
22
45
|
authToken?: string;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
46
|
+
useTursoServerlessDriver?: boolean;
|
|
47
|
+
}
|
|
48
|
+
declare class LibSQLDriver implements DatabaseDriver, TransactionCapable {
|
|
49
|
+
private client;
|
|
50
|
+
constructor(config: LibSQLConfig);
|
|
51
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
52
|
+
transaction<T>(callback: (driver: DatabaseDriver) => Promise<T>): Promise<T>;
|
|
53
|
+
close(): Promise<void>;
|
|
54
|
+
private convertLibsqlResult;
|
|
28
55
|
}
|
|
29
56
|
|
|
30
57
|
interface MySQLConfig {
|
|
31
58
|
connectionString: string;
|
|
32
59
|
}
|
|
60
|
+
declare class MySQLDriver implements DatabaseDriver, TransactionCapable {
|
|
61
|
+
private client;
|
|
62
|
+
constructor(config: MySQLConfig);
|
|
63
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
64
|
+
transaction<T>(callback: (driver: DatabaseDriver) => Promise<T>): Promise<T>;
|
|
65
|
+
close(): Promise<void>;
|
|
66
|
+
}
|
|
33
67
|
|
|
34
|
-
|
|
35
|
-
|
|
68
|
+
interface SqliteConfig {
|
|
69
|
+
filename: string;
|
|
70
|
+
readonly?: boolean;
|
|
71
|
+
}
|
|
72
|
+
declare class SqliteDriver implements DatabaseDriver, TransactionCapable, PreparedStatementCapable {
|
|
73
|
+
private client;
|
|
74
|
+
constructor(config: SqliteConfig);
|
|
75
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
76
|
+
transaction<T>(callback: (driver: DatabaseDriver) => Promise<T>): Promise<T>;
|
|
77
|
+
prepare(sql: string): Promise<PreparedStatement>;
|
|
78
|
+
close(): Promise<void>;
|
|
79
|
+
exec(sql: string): void;
|
|
80
|
+
backup(filename: string): Promise<void>;
|
|
81
|
+
pragma(pragma: string): any;
|
|
82
|
+
}
|
|
36
83
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
command?: string;
|
|
41
|
-
fields?: Array<{
|
|
42
|
-
name: string;
|
|
43
|
-
dataTypeID: number;
|
|
44
|
-
}>;
|
|
45
|
-
};
|
|
46
|
-
interface ClientOptions {
|
|
47
|
-
drivers: {
|
|
48
|
-
libsql?: LibSQLConfig;
|
|
49
|
-
postgres?: PostgresConfig;
|
|
50
|
-
mysql?: MySQLConfig;
|
|
51
|
-
};
|
|
84
|
+
interface ClientOptions<T extends DatabaseDriver = DatabaseDriver> {
|
|
85
|
+
driver: T;
|
|
86
|
+
fallbackDrivers?: DatabaseDriver[];
|
|
52
87
|
}
|
|
53
|
-
declare class
|
|
54
|
-
private
|
|
55
|
-
private
|
|
56
|
-
private mysql?;
|
|
57
|
-
private drivers;
|
|
88
|
+
declare class SQLClient<DT = any> {
|
|
89
|
+
private primaryDriver;
|
|
90
|
+
private fallbackDrivers;
|
|
58
91
|
constructor(options: ClientOptions);
|
|
59
|
-
|
|
60
|
-
|
|
92
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
93
|
+
transaction<T>(callback: (client: SQLClient<DT>) => Promise<T>): Promise<T>;
|
|
94
|
+
prepare(sql: string): Promise<PreparedStatement>;
|
|
61
95
|
findFirst<K extends keyof DT>(table: K, where?: Partial<DT[K]>): Promise<DT[K] | null>;
|
|
62
96
|
findMany<K extends keyof DT>(table: K, options?: {
|
|
63
97
|
where?: Partial<DT[K]>;
|
|
64
98
|
limit?: number;
|
|
99
|
+
offset?: number;
|
|
65
100
|
}): Promise<DT[K][]>;
|
|
66
101
|
insert<K extends keyof DT>(table: K, data: Partial<DT[K]>): Promise<DT[K]>;
|
|
67
102
|
update<K extends keyof DT>(table: K, data: Partial<DT[K]>, where: Partial<DT[K]>): Promise<DT[K] | null>;
|
|
68
|
-
delete<K extends keyof DT>(table: K, where: Partial<DT[K]>): Promise<
|
|
69
|
-
|
|
103
|
+
delete<K extends keyof DT>(table: K, where: Partial<DT[K]>): Promise<number>;
|
|
104
|
+
getDriver(): DatabaseDriver;
|
|
105
|
+
supportsTransactions(): boolean;
|
|
106
|
+
supportsPreparedStatements(): boolean;
|
|
70
107
|
close(): Promise<void>;
|
|
71
108
|
}
|
|
109
|
+
declare function createPostgresClient<DT = any>(config: {
|
|
110
|
+
connectionString?: string;
|
|
111
|
+
experimental?: {
|
|
112
|
+
http?: {
|
|
113
|
+
url: string;
|
|
114
|
+
apiKey?: string;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
}): SQLClient<DT>;
|
|
118
|
+
declare function createLibSQLClient<DT = any>(config: {
|
|
119
|
+
url: string;
|
|
120
|
+
authToken?: string;
|
|
121
|
+
useTursoServerlessDriver?: boolean;
|
|
122
|
+
}): SQLClient<DT>;
|
|
123
|
+
declare function createMySQLClient<DT = any>(config: {
|
|
124
|
+
connectionString: string;
|
|
125
|
+
}): SQLClient<DT>;
|
|
126
|
+
declare function createSqliteClient<DT = any>(config: {
|
|
127
|
+
filename: string;
|
|
128
|
+
readonly?: boolean;
|
|
129
|
+
}): SQLClient<DT>;
|
|
130
|
+
declare const DriftSQLClient: typeof SQLClient;
|
|
72
131
|
|
|
73
|
-
export { DriftSQLClient,
|
|
74
|
-
export type { ClientOptions,
|
|
132
|
+
export { DriftSQLClient, LibSQLDriver, MySQLDriver, PostgresDriver, SQLClient, SqliteDriver, createLibSQLClient, createMySQLClient, createPostgresClient, createSqliteClient };
|
|
133
|
+
export type { ClientOptions, DatabaseDriver, QueryResult };
|