@observablehq/notebook-kit 1.2.0-rc.1 → 1.2.0-rc.2

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "1.2.0-rc.1",
8
+ "version": "1.2.0-rc.2",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -63,6 +63,7 @@
63
63
  "vite": "^7.0.0"
64
64
  },
65
65
  "devDependencies": {
66
+ "@databricks/sql": "^1.11.0",
66
67
  "@duckdb/node-api": "^1.3.2-alpha.26",
67
68
  "@eslint/js": "^9.29.0",
68
69
  "@google-cloud/bigquery": "^8.1.1",
@@ -80,12 +81,16 @@
80
81
  "vitest": "^3.2.4"
81
82
  },
82
83
  "peerDependencies": {
84
+ "@databricks/sql": "^1.11.0",
83
85
  "@duckdb/node-api": "^1.3.2-alpha.26",
84
86
  "@google-cloud/bigquery": "^8.1.1",
85
87
  "postgres": "^3.4.7",
86
88
  "snowflake-sdk": "^2.1.3"
87
89
  },
88
90
  "peerDependenciesMeta": {
91
+ "@databricks/sql": {
92
+ "optional": true
93
+ },
89
94
  "@duckdb/node-api": {
90
95
  "optional": true
91
96
  },
@@ -0,0 +1,2 @@
1
+ import type { DatabricksConfig, QueryTemplateFunction } from "./index.js";
2
+ export default function databricks({ type, ...options }: DatabricksConfig): QueryTemplateFunction;
@@ -0,0 +1,65 @@
1
+ import { DBSQLClient, DBSQLLogger, LogLevel, thrift } from "@databricks/sql";
2
+ const TTypeId = thrift.TCLIService_types.TTypeId;
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ export default function databricks({ type, ...options }) {
5
+ return async (strings, ...params) => {
6
+ const logger = new DBSQLLogger({ level: LogLevel.error });
7
+ const client = new DBSQLClient({ logger });
8
+ await client.connect(options);
9
+ try {
10
+ const session = await client.openSession();
11
+ try {
12
+ const date = new Date();
13
+ const operation = await session.executeStatement(strings.join("?"), {
14
+ runAsync: true,
15
+ ordinalParameters: params,
16
+ maxRows: 10000
17
+ });
18
+ try {
19
+ const rows = (await operation.fetchAll());
20
+ const schema = await operation.getSchema();
21
+ return { rows, schema: getTableSchema(schema), duration: Date.now() - +date, date };
22
+ }
23
+ finally {
24
+ await operation.close();
25
+ }
26
+ }
27
+ finally {
28
+ await session.close();
29
+ }
30
+ }
31
+ finally {
32
+ await client.close();
33
+ }
34
+ };
35
+ }
36
+ function getTableSchema({ columns }) {
37
+ return columns.map(getColumnSchema);
38
+ }
39
+ function getColumnSchema(column) {
40
+ return { name: column.columnName, type: getColumnType(column.typeDesc) };
41
+ }
42
+ function getColumnType({ types: [type] }) {
43
+ switch (type.primitiveEntry?.type) {
44
+ case TTypeId.BINARY_TYPE:
45
+ return "buffer";
46
+ case TTypeId.BOOLEAN_TYPE:
47
+ return "boolean";
48
+ case TTypeId.BIGINT_TYPE:
49
+ case TTypeId.TINYINT_TYPE:
50
+ case TTypeId.SMALLINT_TYPE:
51
+ case TTypeId.INT_TYPE:
52
+ case TTypeId.DECIMAL_TYPE:
53
+ return "integer";
54
+ case TTypeId.DOUBLE_TYPE:
55
+ case TTypeId.FLOAT_TYPE:
56
+ return "number";
57
+ case TTypeId.DATE_TYPE:
58
+ case TTypeId.TIMESTAMP_TYPE:
59
+ case TTypeId.INTERVAL_DAY_TIME_TYPE:
60
+ case TTypeId.INTERVAL_YEAR_MONTH_TYPE:
61
+ return "date";
62
+ default:
63
+ return "string";
64
+ }
65
+ }
@@ -1,5 +1,5 @@
1
1
  import type { ColumnSchema, QueryParam } from "../runtime/index.js";
2
- export type DatabaseConfig = BigQueryConfig | DuckDBConfig | SQLiteConfig | SnowflakeConfig | PostgresConfig;
2
+ export type DatabaseConfig = BigQueryConfig | DatabricksConfig | DuckDBConfig | SQLiteConfig | SnowflakeConfig | PostgresConfig;
3
3
  export type BigQueryConfig = {
4
4
  type: "bigquery";
5
5
  apiKey?: string;
@@ -7,6 +7,18 @@ export type BigQueryConfig = {
7
7
  keyFile?: string;
8
8
  projectId?: string;
9
9
  };
10
+ export type DatabricksConfig = {
11
+ type: "databricks";
12
+ host: string;
13
+ path: string;
14
+ } & ({
15
+ authType?: "access-token";
16
+ token: string;
17
+ } | {
18
+ authType: "databricks-oauth";
19
+ oauthClientId?: string;
20
+ oauthClientSecret?: string;
21
+ });
10
22
  export type DuckDBConfig = {
11
23
  type: "duckdb";
12
24
  path?: string;
@@ -26,7 +26,7 @@ export async function getDatabaseConfig(sourcePath, databaseName) {
26
26
  else if (/\.duckdb$/i.test(databaseName))
27
27
  config = { type: "duckdb", path: databaseName };
28
28
  else if (/\.db$/i.test(databaseName))
29
- config = { type: "sqlite", path: databaseName }; // TODO disambiguate
29
+ config = { type: "sqlite", path: databaseName };
30
30
  else
31
31
  throw new Error(`database not found: ${databaseName}`);
32
32
  }
@@ -36,10 +36,12 @@ export async function getDatabase(config) {
36
36
  switch (config.type) {
37
37
  case "bigquery":
38
38
  return (await import("./bigquery.js")).default(config);
39
+ case "databricks":
40
+ return (await import("./databricks.js")).default(config);
39
41
  case "duckdb":
40
42
  return (await import("./duckdb.js")).default(config);
41
43
  case "sqlite":
42
- return (await import(process.versions.bun ? "./sqlite-bun.js" : "./sqlite-node.js")).default(config);
44
+ return (await import(process.versions.bun ? "./sqlite-bun.js" : "./sqlite-node.js")).default(config); // prettier-ignore
43
45
  case "snowflake":
44
46
  return (await import("./snowflake.js")).default(config);
45
47
  case "postgres":
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "1.2.0-rc.1",
8
+ "version": "1.2.0-rc.2",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -63,6 +63,7 @@
63
63
  "vite": "^7.0.0"
64
64
  },
65
65
  "devDependencies": {
66
+ "@databricks/sql": "^1.11.0",
66
67
  "@duckdb/node-api": "^1.3.2-alpha.26",
67
68
  "@eslint/js": "^9.29.0",
68
69
  "@google-cloud/bigquery": "^8.1.1",
@@ -80,12 +81,16 @@
80
81
  "vitest": "^3.2.4"
81
82
  },
82
83
  "peerDependencies": {
84
+ "@databricks/sql": "^1.11.0",
83
85
  "@duckdb/node-api": "^1.3.2-alpha.26",
84
86
  "@google-cloud/bigquery": "^8.1.1",
85
87
  "postgres": "^3.4.7",
86
88
  "snowflake-sdk": "^2.1.3"
87
89
  },
88
90
  "peerDependenciesMeta": {
91
+ "@databricks/sql": {
92
+ "optional": true
93
+ },
89
94
  "@duckdb/node-api": {
90
95
  "optional": true
91
96
  },