Skip to content

Commit

Permalink
Release v0.5.1, create database file based on env var
Browse files Browse the repository at this point in the history
  • Loading branch information
nullxone committed Oct 31, 2024
1 parent db57f6c commit 87de878
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ndc-duckduckapi/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ndc-duckduckapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hasura/ndc-duckduckapi",
"version": "0.5.0",
"version": "0.5.1",
"description": "SDK for the Hasura DDN DuckDuckAPI connector. Easily build a data API from any existing API by ETLing data into DuckDB.",
"author": "Hasura",
"license": "Apache-2.0",
Expand Down
10 changes: 9 additions & 1 deletion ndc-duckduckapi/src/duckduckapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ import { do_explain } from "./handlers/explain";
import { perform_query, plan_queries } from "./handlers/query";
import { generateConfig } from "./generate-config";
import { Connection, Database } from "duckdb-async";
import fs from "fs-extra";
import path from "path";

// Make a connection manager
const DUCKDB_URL = "duck.db";
let db: Database;
export async function getDB() {
if (!db) {
const duckDBUrl = (process.env["DUCKDB_URL"] as string) ?? DUCKDB_URL;

const dirPath = path.dirname(duckDBUrl);
if (dirPath !== ".") {
await fs.ensureDir(dirPath);
}

db = await Database.create(duckDBUrl);
console.log("Created duckdb at", duckDBUrl);
console.log("Database file at", duckDBUrl);
}
return db;
}
Expand Down

0 comments on commit 87de878

Please sign in to comment.