Skip to content

Commit 04613f1

Browse files
committed
Added SQLite exports for Dumbo
1 parent da27f62 commit 04613f1

File tree

7 files changed

+73
-43
lines changed

7 files changed

+73
-43
lines changed

src/packages/dumbo/src/sqlite3.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './core';
12
export * from './storage/sqlite/core';
23
export * from './storage/sqlite/sqlite3';

src/packages/dumbo/src/storage/postgresql/pg/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ export type PostgresPoolOptions = DumboOptions<NodePostgresConnector> &
1515
NodePostgresPoolOptions;
1616
export const postgresPool = nodePostgresPool;
1717

18-
export const connectionPool = <PoolOptionsType extends DumboOptions>(
19-
options: PoolOptionsType,
20-
) =>
21-
// TODO: this should have the pattern matching and verification
22-
postgresPool(options as unknown as PostgresPoolOptions);
18+
export const connectionPool = postgresPool;
2319

2420
export const dumbo = <
2521
DumboOptionsType extends PostgresPoolOptions = PostgresPoolOptions,

src/packages/dumbo/src/storage/sqlite/core/connections/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ export type SQLitePoolClientConnection<
6262
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
6363
> = Connection<ConnectorType, SQLitePoolClient>;
6464

65-
export type SQLiteConnection =
66-
| SQLiteClientConnection
67-
| SQLitePoolClientConnection;
65+
export type SQLiteConnection<
66+
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
67+
> =
68+
| SQLiteClientConnection<ConnectorType>
69+
| SQLitePoolClientConnection<ConnectorType>;
6870

6971
export const sqliteClientConnection = <
7072
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,

src/packages/dumbo/src/storage/sqlite/core/index.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { ConnectorType } from '../../..';
1+
import { getDriverName, type ConnectorType } from '../../..';
2+
import type { SQLiteClientFactory } from './connections';
23

34
export * from './connections';
45
export * from './execute';
@@ -10,3 +11,23 @@ export const SQLiteConnector = 'SQLite';
1011

1112
export type SQLiteConnectorType<DriverName extends string = string> =
1213
ConnectorType<SQLiteConnector, DriverName>;
14+
15+
export type SQLiteDatabaseType = 'SQLite';
16+
17+
export const sqliteClientProvider = async <
18+
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
19+
>(
20+
connector: ConnectorType,
21+
): Promise<SQLiteClientFactory> => {
22+
const driverName = getDriverName(connector);
23+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
24+
const driverModule = await import(`../${driverName.toLowerCase()}`);
25+
26+
if (!('sqliteClient' in driverModule))
27+
throw new Error(
28+
`The connector module "${connector}" does not export a sqliteClient`,
29+
);
30+
31+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
32+
return driverModule.sqliteClient as SQLiteClientFactory;
33+
};

src/packages/dumbo/src/storage/sqlite/core/pool/pool.ts

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
import {
22
InMemorySQLiteDatabase,
3+
sqliteClientProvider,
34
sqliteConnection,
45
type SQLiteClient,
56
type SQLiteClientConnection,
67
type SQLiteConnectorType,
78
type SQLitePoolClientConnection,
89
} from '..';
9-
import { sqliteClientProvider } from '../..';
1010
import {
1111
createConnectionPool,
1212
JSONSerializer,
1313
type ConnectionPool,
1414
} from '../../../../core';
1515

16-
export type SQLiteAmbientClientPool = ConnectionPool<SQLiteClientConnection>;
16+
export type SQLiteAmbientClientPool<
17+
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
18+
> = ConnectionPool<SQLiteClientConnection<ConnectorType>>;
1719

18-
export type SQLiteAmbientConnectionPool = ConnectionPool<
19-
SQLitePoolClientConnection | SQLiteClientConnection
20+
export type SQLiteAmbientConnectionPool<
21+
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
22+
> = ConnectionPool<
23+
| SQLitePoolClientConnection<ConnectorType>
24+
| SQLiteClientConnection<ConnectorType>
2025
>;
2126

22-
export type SQLitePool = SQLiteAmbientClientPool | SQLiteAmbientConnectionPool;
27+
export type SQLitePool<
28+
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
29+
> =
30+
| SQLiteAmbientClientPool<ConnectorType>
31+
| SQLiteAmbientConnectionPool<ConnectorType>;
2332

2433
// TODO: Add connection pool handling
2534

@@ -30,7 +39,7 @@ export const sqliteAmbientConnectionPool = <
3039
connection:
3140
| SQLitePoolClientConnection<ConnectorType>
3241
| SQLiteClientConnection<ConnectorType>;
33-
}): SQLiteAmbientConnectionPool => {
42+
}): SQLiteAmbientConnectionPool<ConnectorType> => {
3443
const { connection, connector: connectorType } = options;
3544

3645
return createConnectionPool({
@@ -48,7 +57,7 @@ export const sqliteSingletonClientPool = <
4857
connector: ConnectorType;
4958
fileName: string;
5059
database?: string | undefined;
51-
}): SQLiteAmbientClientPool => {
60+
}): SQLiteAmbientClientPool<ConnectorType> => {
5261
const { connector, fileName } = options;
5362
let connection: SQLiteClientConnection | undefined = undefined;
5463

@@ -86,7 +95,7 @@ export const sqliteAlwaysNewClientPool = <
8695
connector: ConnectorType;
8796
fileName: string;
8897
database?: string | undefined;
89-
}): SQLiteAmbientClientPool => {
98+
}): SQLiteAmbientClientPool<ConnectorType> => {
9099
const { connector, fileName } = options;
91100

92101
return createConnectionPool({
@@ -111,7 +120,7 @@ export const sqliteAmbientClientPool = <
111120
>(options: {
112121
connector: ConnectorType;
113122
client: SQLiteClient;
114-
}): SQLiteAmbientClientPool => {
123+
}): SQLiteAmbientClientPool<ConnectorType> => {
115124
const { client, connector } = options;
116125

117126
const getConnection = () => {
@@ -182,12 +191,16 @@ export type SQLitePoolOptions<
182191

183192
export function sqlitePool<
184193
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
185-
>(options: SQLitePoolNotPooledOptions<ConnectorType>): SQLiteAmbientClientPool;
194+
>(
195+
options: SQLitePoolNotPooledOptions<ConnectorType>,
196+
): SQLiteAmbientClientPool<ConnectorType>;
186197
export function sqlitePool<
187198
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
188199
>(
189200
options: SQLitePoolOptions<ConnectorType>,
190-
): SQLiteAmbientClientPool | SQLiteAmbientConnectionPool {
201+
):
202+
| SQLiteAmbientClientPool<ConnectorType>
203+
| SQLiteAmbientConnectionPool<ConnectorType> {
191204
const { fileName, connector } = options;
192205

193206
// TODO: Handle dates and bigints

src/packages/dumbo/src/storage/sqlite/index.ts

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
export * from './connections';
2-
import { sqlite3Client as sqliteClient } from './connections';
2+
import type { Dumbo } from '../../../core';
3+
import {
4+
sqlitePool,
5+
type SQLiteConnection,
6+
type SQLitePoolOptions,
7+
} from '../core';
8+
import {
9+
sqlite3Client as sqliteClient,
10+
type SQLite3Connector,
11+
} from './connections';
312

413
export { sqliteClient };
14+
15+
export const connectionPool = sqlitePool;
16+
17+
export const dumbo = <
18+
DumboOptionsType extends
19+
SQLitePoolOptions<SQLite3Connector> = SQLitePoolOptions<SQLite3Connector>,
20+
>(
21+
options: DumboOptionsType,
22+
): Dumbo<SQLite3Connector, SQLiteConnection<SQLite3Connector>> =>
23+
sqlitePool(options);

0 commit comments

Comments
 (0)