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/dist/index.d.ts CHANGED
@@ -1,74 +1,133 @@
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;
51
- };
84
+ interface ClientOptions<T extends DatabaseDriver = DatabaseDriver> {
85
+ driver: T;
86
+ fallbackDrivers?: DatabaseDriver[];
52
87
  }
53
- declare class DriftSQLClient<DT> {
54
- private postgres?;
55
- private libsql?;
56
- private mysql?;
57
- private drivers;
88
+ declare class SQLClient<DT = any> {
89
+ private primaryDriver;
90
+ private fallbackDrivers;
58
91
  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>>;
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<boolean>;
69
- deleteFirst<K extends keyof DT>(table: K, where: Partial<DT[K]>): Promise<boolean>;
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, inspectDB };
74
- export type { ClientOptions, UnifiedQueryResult };
132
+ export { DriftSQLClient, LibSQLDriver, MySQLDriver, PostgresDriver, SQLClient, SqliteDriver, createLibSQLClient, createMySQLClient, createPostgresClient, createSqliteClient };
133
+ export type { ClientOptions, DatabaseDriver, QueryResult };