Skip to content

Commit 584d57a

Browse files
committed
colocate config types with connectors
1 parent 3c0d1d5 commit 584d57a

File tree

9 files changed

+64
-56
lines changed

9 files changed

+64
-56
lines changed

src/databases/bigquery.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import {BigQuery} from "@google-cloud/bigquery";
22
import {BigQueryDate, BigQueryDatetime, BigQueryTimestamp} from "@google-cloud/bigquery";
33
import type {TableField, TableSchema} from "@google-cloud/bigquery";
4-
import type {BigQueryConfig, QueryTemplateFunction} from "./index.js";
4+
import type {QueryTemplateFunction} from "./index.js";
55
import type {ColumnSchema} from "../runtime/index.js";
66

7+
export type BigQueryConfig = {
8+
type: "bigquery";
9+
apiKey?: string;
10+
keyFilename?: string;
11+
keyFile?: string;
12+
projectId?: string;
13+
};
14+
715
// eslint-disable-next-line @typescript-eslint/no-unused-vars
816
export default function bigquery({type, ...options}: BigQueryConfig): QueryTemplateFunction {
917
return async (strings, ...params) => {

src/databases/databricks.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {DBSQLClient, DBSQLLogger, LogLevel, thrift} from "@databricks/sql";
22
import type {DBSQLSession} from "@databricks/sql";
3-
import type {DatabricksConfig, QueryTemplateFunction} from "./index.js";
3+
import type {QueryTemplateFunction} from "./index.js";
44
import {ColumnSchema} from "../runtime/index.js";
55

66
type IOperation = Awaited<ReturnType<DBSQLSession["executeStatement"]>>;
@@ -9,6 +9,15 @@ type TColumnDesc = TTableSchema["columns"][0];
99
type TTypeDesc = TColumnDesc["typeDesc"];
1010
const TTypeId = thrift.TCLIService_types.TTypeId;
1111

12+
export type DatabricksConfig = {
13+
type: "databricks";
14+
host: string;
15+
path: string;
16+
} & (
17+
| {authType?: "access-token"; token: string}
18+
| {authType: "databricks-oauth"; oauthClientId?: string; oauthClientSecret?: string}
19+
);
20+
1221
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1322
export default function databricks({type, ...options}: DatabricksConfig): QueryTemplateFunction {
1423
return async (strings, ...params) => {

src/databases/duckdb.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import type {DuckDBResult, DuckDBType, Json} from "@duckdb/node-api";
22
import {DuckDBConnection, DuckDBInstance} from "@duckdb/node-api";
33
import {BIGINT, BIT, BLOB, BOOLEAN, DATE, DOUBLE, FLOAT, HUGEINT, INTEGER, INTERVAL, SMALLINT, TIME, TIMESTAMP, TIMESTAMP_MS, TIMESTAMP_NS, TIMESTAMP_S, TIMESTAMPTZ, TINYINT, UBIGINT, UHUGEINT, UINTEGER, USMALLINT, UTINYINT, UUID, VARCHAR, VARINT} from "@duckdb/node-api"; // prettier-ignore
4-
import type {DuckDBConfig, QueryTemplateFunction} from "./index.js";
4+
import type {QueryTemplateFunction} from "./index.js";
55
import type {ColumnSchema} from "../runtime/index.js";
66

7+
export type DuckDBConfig = {
8+
type: "duckdb";
9+
path?: string;
10+
options?: {[key: string]: string}; // https://duckdb.org/docs/stable/configuration/overview.html
11+
};
12+
713
export default function duckdb({path, options}: DuckDBConfig): QueryTemplateFunction {
814
return async (strings, ...params) => {
915
const instance = await DuckDBInstance.create(path, options);

src/databases/index.ts

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import {json} from "node:stream/consumers";
44
import {isEnoent} from "../lib/error.js";
55
import {hash as getQueryHash, nameHash as getNameHash} from "../lib/hash.js";
66
import type {ColumnSchema, QueryParam} from "../runtime/index.js";
7+
import type {BigQueryConfig} from "./bigquery.js";
8+
import type {DatabricksConfig} from "./databricks.js";
9+
import type {DuckDBConfig} from "./duckdb.js";
10+
import type {SQLiteConfig} from "./sqlite.js";
11+
import type {SnowflakeConfig} from "./snowflake.js";
12+
import type {PostgresConfig} from "./postgres.js";
713

814
export type DatabaseConfig =
915
| BigQueryConfig
@@ -13,55 +19,6 @@ export type DatabaseConfig =
1319
| SnowflakeConfig
1420
| PostgresConfig;
1521

16-
export type BigQueryConfig = {
17-
type: "bigquery";
18-
apiKey?: string;
19-
keyFilename?: string;
20-
keyFile?: string;
21-
projectId?: string;
22-
};
23-
24-
export type DatabricksConfig = {
25-
type: "databricks";
26-
host: string;
27-
path: string;
28-
} & (
29-
| {authType?: "access-token"; token: string}
30-
| {authType: "databricks-oauth"; oauthClientId?: string; oauthClientSecret?: string}
31-
);
32-
33-
export type DuckDBConfig = {
34-
type: "duckdb";
35-
path?: string;
36-
options?: {[key: string]: string}; // https://duckdb.org/docs/stable/configuration/overview.html
37-
};
38-
39-
export type SQLiteConfig = {
40-
type: "sqlite";
41-
path?: string;
42-
};
43-
44-
export type SnowflakeConfig = {
45-
type: "snowflake";
46-
account: string;
47-
database?: string;
48-
role?: string;
49-
schema?: string;
50-
username?: string;
51-
warehouse?: string;
52-
password?: string;
53-
};
54-
55-
export type PostgresConfig = {
56-
type: "postgres";
57-
host?: string;
58-
port?: string | number;
59-
username?: string;
60-
password?: string;
61-
database?: string;
62-
ssl?: boolean;
63-
};
64-
6522
export type QueryTemplateFunction = (
6623
strings: readonly string[],
6724
...params: QueryParam[]

src/databases/postgres.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import type {Column, RowList} from "postgres";
22
import Postgres from "postgres";
33
import type {ColumnSchema} from "../runtime/index.js";
4-
import type {PostgresConfig, QueryTemplateFunction} from "./index.js";
4+
import type {QueryTemplateFunction} from "./index.js";
55
import {optionalBoolean, optionalNumber, optionalString} from "./options.js";
66

7+
export type PostgresConfig = {
8+
type: "postgres";
9+
host?: string;
10+
port?: string | number;
11+
username?: string;
12+
password?: string;
13+
database?: string;
14+
ssl?: boolean;
15+
};
16+
717
export default function postgres(options: PostgresConfig): QueryTemplateFunction {
818
return async (strings, ...params) => {
919
const sql = Postgres({

src/databases/snowflake.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import type {Column, Connection, ConnectionOptions, RowStatement} from "snowflake-sdk";
22
import Snowflake from "snowflake-sdk";
33
import type {ColumnSchema, QueryParam} from "../runtime/index.js";
4-
import {QueryTemplateFunction, SerializableQueryResult, SnowflakeConfig} from "./index.js";
4+
import {QueryTemplateFunction, SerializableQueryResult} from "./index.js";
55
import {optionalString} from "./options.js";
66

77
Snowflake.configure({logLevel: "OFF"});
88

9+
export type SnowflakeConfig = {
10+
type: "snowflake";
11+
account: string;
12+
database?: string;
13+
role?: string;
14+
schema?: string;
15+
username?: string;
16+
warehouse?: string;
17+
password?: string;
18+
};
19+
920
export default function snowflake(options: SnowflakeConfig): QueryTemplateFunction {
1021
return async (strings, ...params) => {
1122
const connection = await connect({

src/databases/sqlite-bun.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type {Statement} from "bun:sqlite";
22
import {Database} from "bun:sqlite";
3-
import type {SQLiteConfig, QueryTemplateFunction} from "./index.js";
3+
import type {QueryTemplateFunction} from "./index.js";
44
import type {ColumnSchema} from "../runtime/index.js";
5+
import type {SQLiteConfig} from "./sqlite.js";
56
import {getColumnType} from "./sqlite.js";
67

78
export default function sqlite({path = ":memory:"}: SQLiteConfig): QueryTemplateFunction {

src/databases/sqlite-node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type {StatementSync} from "node:sqlite";
22
import {DatabaseSync} from "node:sqlite";
3-
import type {SQLiteConfig, QueryTemplateFunction} from "./index.js";
3+
import type {QueryTemplateFunction} from "./index.js";
44
import type {ColumnSchema} from "../runtime/index.js";
5+
import type {SQLiteConfig} from "./sqlite.js";
56
import {getColumnType} from "./sqlite.js";
67

78
export default function sqlite({path = ":memory:"}: SQLiteConfig): QueryTemplateFunction {

src/databases/sqlite.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type {ColumnSchema} from "../runtime/index.js";
22

3+
export type SQLiteConfig = {
4+
type: "sqlite";
5+
path?: string;
6+
};
7+
38
export function getColumnType(type: string | null): ColumnSchema["type"] {
49
switch (type) {
510
case "INT":

0 commit comments

Comments
 (0)