driftsql 1.0.12 → 1.0.14

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/index.d.ts CHANGED
@@ -1,74 +1,160 @@
1
- type DriverOptions<T = object> = T & {
2
- experimental?: Record<string, any>;
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
- options?: DriverOptions<{
8
- experimental?: {
9
- /**
10
- * Enable experimental postgres http support. Using github.com/lassejlv/postgres_http
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
- options?: DriverOptions<{
24
- experimental?: {
25
- useTursoServerlessDriver?: boolean;
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
- type Drivers = ClientOptions['drivers'];
35
- declare const inspectDB: (drivers: Drivers) => Promise<never>;
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
- type UnifiedQueryResult<T extends Record<string, any>> = {
38
- rows: T[];
39
- rowCount: number;
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;
84
+ interface InspectOptions {
85
+ driver: DatabaseDriver;
86
+ outputFile?: string;
87
+ }
88
+ declare const inspectDB: (options: InspectOptions) => Promise<void>;
89
+ declare const inspectPostgres: (config: {
90
+ connectionString?: string;
91
+ experimental?: {
92
+ http?: {
93
+ url: string;
94
+ apiKey?: string;
95
+ };
51
96
  };
97
+ }, outputFile?: string) => Promise<void>;
98
+ declare const inspectLibSQL: (config: {
99
+ url: string;
100
+ authToken?: string;
101
+ useTursoServerlessDriver?: boolean;
102
+ }, outputFile?: string) => Promise<void>;
103
+ declare const inspectMySQL: (config: {
104
+ connectionString: string;
105
+ }, outputFile?: string) => Promise<void>;
106
+ declare const inspectSQLite: (config: {
107
+ filename: string;
108
+ readonly?: boolean;
109
+ }, outputFile?: string) => Promise<void>;
110
+
111
+ interface ClientOptions<T extends DatabaseDriver = DatabaseDriver> {
112
+ driver: T;
113
+ fallbackDrivers?: DatabaseDriver[];
52
114
  }
53
- declare class DriftSQLClient<DT> {
54
- private postgres?;
55
- private libsql?;
56
- private mysql?;
57
- private drivers;
115
+ declare class SQLClient<DT = any> {
116
+ private primaryDriver;
117
+ private fallbackDrivers;
58
118
  constructor(options: ClientOptions);
59
- readonly inspect: () => Promise<void>;
60
- query<T extends Record<string, any>>(query: string, args?: (string | number | boolean | null)[]): Promise<UnifiedQueryResult<T>>;
119
+ query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
120
+ transaction<T>(callback: (client: SQLClient<DT>) => Promise<T>): Promise<T>;
121
+ prepare(sql: string): Promise<PreparedStatement>;
61
122
  findFirst<K extends keyof DT>(table: K, where?: Partial<DT[K]>): Promise<DT[K] | null>;
62
123
  findMany<K extends keyof DT>(table: K, options?: {
63
124
  where?: Partial<DT[K]>;
64
125
  limit?: number;
126
+ offset?: number;
65
127
  }): Promise<DT[K][]>;
66
128
  insert<K extends keyof DT>(table: K, data: Partial<DT[K]>): Promise<DT[K]>;
67
129
  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<boolean>;
69
- deleteFirst<K extends keyof DT>(table: K, where: Partial<DT[K]>): Promise<boolean>;
130
+ delete<K extends keyof DT>(table: K, where: Partial<DT[K]>): Promise<number>;
131
+ getDriver(): DatabaseDriver;
132
+ supportsTransactions(): boolean;
133
+ supportsPreparedStatements(): boolean;
70
134
  close(): Promise<void>;
71
135
  }
136
+ declare function createPostgresClient<DT = any>(config: {
137
+ connectionString?: string;
138
+ experimental?: {
139
+ http?: {
140
+ url: string;
141
+ apiKey?: string;
142
+ };
143
+ };
144
+ }): SQLClient<DT>;
145
+ declare function createLibSQLClient<DT = any>(config: {
146
+ url: string;
147
+ authToken?: string;
148
+ useTursoServerlessDriver?: boolean;
149
+ }): SQLClient<DT>;
150
+ declare function createMySQLClient<DT = any>(config: {
151
+ connectionString: string;
152
+ }): SQLClient<DT>;
153
+ declare function createSqliteClient<DT = any>(config: {
154
+ filename: string;
155
+ readonly?: boolean;
156
+ }): SQLClient<DT>;
157
+ declare const DriftSQLClient: typeof SQLClient;
72
158
 
73
- export { DriftSQLClient, inspectDB };
74
- export type { ClientOptions, UnifiedQueryResult };
159
+ export { DriftSQLClient, LibSQLDriver, MySQLDriver, PostgresDriver, SQLClient, SqliteDriver, createLibSQLClient, createMySQLClient, createPostgresClient, createSqliteClient, inspectDB, inspectLibSQL, inspectMySQL, inspectPostgres, inspectSQLite };
160
+ export type { ClientOptions, DatabaseDriver, QueryResult };