Skip to content

Commit 3cc4ea7

Browse files
authored
Simplify driver API (#5)
* Refactor driver api. * Update tests. * Update better-sqlite3-driver. * Update high-level API implementation. * Document APIs.
1 parent 6672b66 commit 3cc4ea7

File tree

11 files changed

+473
-648
lines changed

11 files changed

+473
-648
lines changed

DRIVER-API.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ Returning an array of cells for each row, along with a separate "columns" array,
110110

111111
However, many current SQLite bindings do not expose the raw array calls. Even if they do, this path may be slower than using objects from the start. Since using the results as an array is quite rare in practice, this is left as an optional configuration, rather than a requirement for the all queries.
112112

113-
### Separate bind/step/reset
114-
115-
This allows a lot of flexibility, for example partial rebinding of parameters instead of specifying all parameters each time a prepared statement is used. However, those type of use cases are rare, and this is not important in the overall architecture. These could all be combined into a single "query with parameters" call, but would need to take into account optional streaming of results.
116-
117113
### bigint
118114

119115
SQLite supports up to 8-byte signed integers (up to 2^64-1), while JavaScript's number is limited to 2^53-1. General approaches include:

packages/api/src/api.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SqliteArguments, SqliteRowObject } from '@sqlite-js/driver';
1+
import { SqliteArguments, SqliteObjectRow } from '@sqlite-js/driver';
22

33
export type SqliteDatabase = SqliteConnectionPool & SqliteConnection;
44

@@ -61,19 +61,15 @@ export interface ReservedSqliteConnection extends SqliteConnection {
6161
}
6262

6363
export interface QueryInterface {
64-
prepare<T extends SqliteRowObject>(
65-
query: string,
66-
args?: SqliteArguments,
67-
options?: QueryOptions
68-
): PreparedQuery<T>;
64+
prepare<T extends SqliteObjectRow>(query: string): PreparedQuery<T>;
6965

7066
run(
7167
query: string,
7268
args?: SqliteArguments,
7369
options?: ReserveConnectionOptions
7470
): Promise<RunResult>;
7571

76-
stream<T extends SqliteRowObject>(
72+
stream<T extends SqliteObjectRow>(
7773
query: string,
7874
args: SqliteArguments,
7975
options?: StreamOptions & ReserveConnectionOptions
@@ -84,7 +80,7 @@ export interface QueryInterface {
8480
*
8581
* When called on a connection pool, uses readonly: true by default.
8682
*/
87-
select<T extends SqliteRowObject>(
83+
select<T extends SqliteObjectRow>(
8884
query: string,
8985
args?: SqliteArguments,
9086
options?: QueryOptions & ReserveConnectionOptions
@@ -99,7 +95,7 @@ export interface QueryInterface {
9995
* @param args
10096
* @param options
10197
*/
102-
get<T extends SqliteRowObject>(
98+
get<T extends SqliteObjectRow>(
10399
query: string,
104100
args?: SqliteArguments,
105101
options?: QueryOptions & ReserveConnectionOptions
@@ -114,7 +110,7 @@ export interface QueryInterface {
114110
* @param args
115111
* @param options
116112
*/
117-
getOptional<T extends SqliteRowObject>(
113+
getOptional<T extends SqliteObjectRow>(
118114
query: string,
119115
args?: SqliteArguments,
120116
options?: QueryOptions & ReserveConnectionOptions
@@ -236,7 +232,7 @@ export interface RunResult {
236232
lastInsertRowId: bigint;
237233
}
238234

239-
export interface PreparedQuery<T extends SqliteRowObject> {
235+
export interface PreparedQuery<T extends SqliteObjectRow> {
240236
parse(): Promise<{ columns: string[] }>;
241237

242238
/**

0 commit comments

Comments
 (0)