{
const date = new Date("2023-02-01T12:34:56Z");
const duckdb = await import(`https://cdn.observableusercontent.com/npm/@duckdb/duckdb-wasm@${version.duckdb}/+esm`);
const arrow = await import(`https://cdn.observableusercontent.com/npm/apache-arrow@${version.arrow}/+esm`);
const db = await initDB(duckdb);
const conn = await db.connect();
const table = arrow.tableFromJSON([{date}]);
await conn.insertArrowTable(table, {name: "t"});
const result = toJSON(await conn.query("select date d from t"))[0].d;
conn.close();
const type = table.schema.fields[0].type;
return {result, type, typeId: type.typeId};
async function initDB(duckdb) {
const bundle = await duckdb.selectBundle(duckdb.getJsDelivrBundles());
const workerUrl = URL.createObjectURL(new Blob([`importScripts("${bundle.mainWorker}");`], {type: "text/javascript"}));
const worker = new Worker(workerUrl);
const logger = new duckdb.ConsoleLogger();
const db = new duckdb.AsyncDuckDB(logger, worker);
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
URL.revokeObjectURL(workerUrl);
return db;
}
function toJSON(result) {
return result.toArray().map(row => row.toJSON());
}
}