Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 18, 2024
1 parent 425e518 commit e8a678f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
16 changes: 4 additions & 12 deletions src/client/stdlib/duckdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,30 +186,22 @@ async function insertSource(database, name, source) {
if (Array.isArray(source)) return insertArray(database, name, source);
if (isArqueroTable(source)) return insertArqueroTable(database, name, source);
if (typeof source === "string") return insertUrl(database, name, source);
if (source == null) return; // ignore nullish data
if (source && typeof source === "object") {
if ("data" in source) {
// data + options
const {data, ...options} = source;
if (isArrowTable(data)) {
return insertArrowTable(database, name, data, options);
} else {
return insertArray(database, name, data, options);
}
} else if ("file" in source) {
if (isArrowTable(data)) return insertArrowTable(database, name, data, options);
return insertArray(database, name, data, options);
}
if ("file" in source) {
// file + options
const {file, ...options} = source;
return insertFile(database, name, file, options);
} else if ("url" in source) {
// url + options
const {url, ...options} = source;
return insertUrl(database, name, url, options);
}
}
throw new Error(`invalid source: ${source}`);
}

// TODO options to specify type?
async function insertUrl(database, name, url) {
const connection = await database.connect();
try {
Expand Down
7 changes: 0 additions & 7 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ function registerTables(sql: Record<string, any>, options: RenderOptions): strin
.join("\n");
}

// const source = node.arguments[0];
// output.replaceLeft(source.start, source.end, JSON.stringify(resolved));

function registerTable(name: string, source: any, {path}: RenderOptions): string {
return `registerTable(${JSON.stringify(name)}, ${
isAssetPath(source)
Expand All @@ -103,10 +100,6 @@ function registerTable(name: string, source: any, {path}: RenderOptions): string
});`;
}

// function normalizeTableSource(path: string, name: string): string {
// return relativePath(path, resolvePath(path, name));
// }

function registerFiles(
files: Iterable<string>,
resolve: (name: string) => string,
Expand Down

0 comments on commit e8a678f

Please sign in to comment.