@run-trace/duckdb-wasm 0.0.1
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/README.md +228 -0
- package/dist/duckdb-browser-coi.pthread.worker.js +32 -0
- package/dist/duckdb-browser-coi.worker.js +31 -0
- package/dist/duckdb-browser-eh.worker.js +27 -0
- package/dist/duckdb-browser-mvp.worker.js +27 -0
- package/dist/duckdb-browser.d.ts +1 -0
- package/dist/duckdb-coi.wasm +0 -0
- package/dist/duckdb-eh.wasm +0 -0
- package/dist/duckdb-mvp.wasm +0 -0
- package/dist/duckdb-node-eh.worker.cjs +51 -0
- package/dist/duckdb-node-mvp.worker.cjs +51 -0
- package/dist/duckdb-node.d.ts +1 -0
- package/dist/duckdb-node.mjs +8 -0
- package/dist/duckdb-wasm.mjs +1160 -0
- package/dist/duckdb-wasm.umd.js +1 -0
- package/dist/types/bindings/bindings_base.d.ts +129 -0
- package/dist/types/bindings/bindings_browser_base.d.ts +18 -0
- package/dist/types/bindings/bindings_browser_coi.d.ts +12 -0
- package/dist/types/bindings/bindings_browser_eh.d.ts +12 -0
- package/dist/types/bindings/bindings_browser_mvp.d.ts +11 -0
- package/dist/types/bindings/bindings_interface.d.ts +44 -0
- package/dist/types/bindings/bindings_node_base.d.ts +22 -0
- package/dist/types/bindings/bindings_node_eh.d.ts +12 -0
- package/dist/types/bindings/bindings_node_mvp.d.ts +12 -0
- package/dist/types/bindings/config.d.ts +90 -0
- package/dist/types/bindings/connection.d.ts +62 -0
- package/dist/types/bindings/duckdb_module.d.ts +13 -0
- package/dist/types/bindings/file_stats.d.ts +36 -0
- package/dist/types/bindings/index.d.ts +11 -0
- package/dist/types/bindings/insert_options.d.ts +31 -0
- package/dist/types/bindings/progress.d.ts +9 -0
- package/dist/types/bindings/runtime.d.ts +99 -0
- package/dist/types/bindings/runtime_browser.d.ts +13 -0
- package/dist/types/bindings/runtime_node.d.ts +8 -0
- package/dist/types/bindings/tokens.d.ts +12 -0
- package/dist/types/bindings/udf_function.d.ts +13 -0
- package/dist/types/bindings/udf_runtime.d.ts +3 -0
- package/dist/types/bindings/web_file.d.ts +12 -0
- package/dist/types/duckdb.d.ts +8 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/log.d.ts +61 -0
- package/dist/types/parallel/async_bindings.d.ts +137 -0
- package/dist/types/parallel/async_bindings_interface.d.ts +27 -0
- package/dist/types/parallel/async_connection.d.ts +64 -0
- package/dist/types/parallel/index.d.ts +5 -0
- package/dist/types/parallel/worker_dispatcher.d.ts +22 -0
- package/dist/types/parallel/worker_request.d.ts +101 -0
- package/dist/types/platform.d.ts +38 -0
- package/dist/types/sql_field.d.ts +14 -0
- package/dist/types/status.d.ts +7 -0
- package/dist/types/targets/duckdb-browser-coi.pthread.worker.d.ts +1 -0
- package/dist/types/targets/duckdb-browser-coi.worker.d.ts +2 -0
- package/dist/types/targets/duckdb-browser-eh.worker.d.ts +2 -0
- package/dist/types/targets/duckdb-browser-mvp.worker.d.ts +2 -0
- package/dist/types/targets/duckdb-node-eh.worker.d.ts +2 -0
- package/dist/types/targets/duckdb-node-mvp.worker.d.ts +2 -0
- package/dist/types/targets/duckdb.d.ts +10 -0
- package/dist/types/utils/binary_dump.d.ts +1 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/opfs_util.d.ts +4 -0
- package/dist/types/utils/s3_helper.d.ts +27 -0
- package/dist/types/worker.d.ts +1 -0
- package/dist/types/worker_node.d.ts +6 -0
- package/package.json +89 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(E,R){typeof exports=="object"&&typeof module<"u"?R(exports):typeof define=="function"&&define.amd?define(["exports"],R):(E=typeof globalThis<"u"?globalThis:E||self,R(E["duckdb-wasm"]={}))})(this,function(E){"use strict";var R=(t=>(t[t.UNDEFINED=0]="UNDEFINED",t[t.AUTOMATIC=1]="AUTOMATIC",t[t.READ_ONLY=2]="READ_ONLY",t[t.READ_WRITE=3]="READ_WRITE",t))(R||{}),A=(t=>(t[t.IDENTIFIER=0]="IDENTIFIER",t[t.NUMERIC_CONSTANT=1]="NUMERIC_CONSTANT",t[t.STRING_CONSTANT=2]="STRING_CONSTANT",t[t.OPERATOR=3]="OPERATOR",t[t.KEYWORD=4]="KEYWORD",t[t.COMMENT=5]="COMMENT",t))(A||{}),c=(t=>(t[t.NONE=0]="NONE",t[t.DEBUG=1]="DEBUG",t[t.INFO=2]="INFO",t[t.WARNING=3]="WARNING",t[t.ERROR=4]="ERROR",t))(c||{}),o=(t=>(t[t.NONE=0]="NONE",t[t.CONNECT=1]="CONNECT",t[t.DISCONNECT=2]="DISCONNECT",t[t.OPEN=3]="OPEN",t[t.QUERY=4]="QUERY",t[t.INSTANTIATE=5]="INSTANTIATE",t))(o||{}),I=(t=>(t[t.NONE=0]="NONE",t[t.OK=1]="OK",t[t.ERROR=2]="ERROR",t[t.START=3]="START",t[t.RUN=4]="RUN",t[t.CAPTURE=5]="CAPTURE",t))(I||{}),h=(t=>(t[t.NONE=0]="NONE",t[t.WEB_WORKER=1]="WEB_WORKER",t[t.NODE_WORKER=2]="NODE_WORKER",t[t.BINDINGS=3]="BINDINGS",t[t.ASYNC_DUCKDB=4]="ASYNC_DUCKDB",t))(h||{});class P{log(s){}}class y{constructor(s=2){this.level=s}log(s){s.level>=this.level&&console.log(s)}}function M(t){switch(t){case 0:return"NONE";case 1:return"DEBUG";case 2:return"INFO";case 3:return"WARNING";case 4:return"ERROR";default:return"?"}}function p(t){switch(t){case 0:return"NONE";case 1:return"OK";case 2:return"ERROR";case 3:return"START";case 4:return"RUN";case 5:return"CAPTURE";default:return"?"}}function k(t){switch(t){case 1:return"CONNECT";case 2:return"DISCONNECT";case 5:return"INSTANTIATE";case 3:return"OPEN";case 4:return"QUERY";default:return"?"}}function G(t){switch(t){case 0:return"NONE";case 1:return"WEB WORKER";case 2:return"NODE WORKER";case 3:return"DUCKDB BINDINGS";case 4:return"DUCKDB";default:return"?"}}var w=(t=>(t[t.SUCCESS=0]="SUCCESS",t[t.MAX_ARROW_ERROR=255]="MAX_ARROW_ERROR",t[t.DUCKDB_WASM_RETRY=256]="DUCKDB_WASM_RETRY",t))(w||{});function D(t){return t<=255}function Q(t){return t===256}class u{constructor(s,e){this._bindings=s,this._conn=e}get bindings(){return this._bindings}async close(){return this._bindings.disconnect(this._conn)}useUnsafe(s){return s(this._bindings,this._conn)}query(s){return this._bindings.logger.log({timestamp:new Date,level:c.INFO,origin:h.ASYNC_DUCKDB,topic:o.QUERY,event:I.RUN,value:s}),this._bindings.runQuery(this._conn,s)}async send(s,e=!1){this._bindings.logger.log({timestamp:new Date,level:c.INFO,origin:h.ASYNC_DUCKDB,topic:o.QUERY,event:I.RUN,value:s});let n=await this._bindings.startPendingQuery(this._conn,s,e);for(;n==null;){if(this._bindings.isDetached()){console.error("cannot send a message since the worker is not set!");return}n=await this._bindings.pollPendingQuery(this._conn)}return new S(this._bindings,this._conn,n)}async cancelSent(){return await this._bindings.cancelPendingQuery(this._conn)}async getTableNames(s){return await this._bindings.getTableNames(this._conn,s)}async prepare(s){const e=await this._bindings.createPrepared(this._conn,s);return new f(this._bindings,this._conn,e)}async insertArrowFromIPCStream(s,e){await this._bindings.insertArrowFromIPCStream(this._conn,s,e)}async insertCSVFromPath(s,e){await this._bindings.insertCSVFromPath(this._conn,s,e)}async insertJSONFromPath(s,e){await this._bindings.insertJSONFromPath(this._conn,s,e)}}class S{constructor(s,e,n){this.db=s,this.conn=e,this.header=n,this._first=!0,this._depleted=!1,this._inFlight=null}async next(){if(this._first)return this._first=!1,{done:!1,value:this.header};if(this._depleted)return{done:!0,value:null};let s=null;for(this._inFlight!=null&&(s=await this._inFlight,this._inFlight=null);s==null;)s=await this.db.fetchQueryResults(this.conn);return this._depleted=s.length==0,this._depleted||(this._inFlight=this.db.fetchQueryResults(this.conn)),{done:this._depleted,value:s}}[Symbol.asyncIterator](){return this}}class f{constructor(s,e,n){this.bindings=s,this.connectionId=e,this.statementId=n}async close(){await this.bindings.closePrepared(this.connectionId,this.statementId)}query(...s){return this.bindings.runPrepared(this.connectionId,this.statementId,s)}async send(...s){const e=await this.bindings.sendPrepared(this.connectionId,this.statementId,s);return new S(this.bindings,this.connectionId,e)}}var a=(t=>(t.CANCEL_PENDING_QUERY="CANCEL_PENDING_QUERY",t.CLOSE_PREPARED="CLOSE_PREPARED",t.COLLECT_FILE_STATISTICS="COLLECT_FILE_STATISTICS",t.REGISTER_OPFS_FILE_NAME="REGISTER_OPFS_FILE_NAME",t.CONNECT="CONNECT",t.COPY_FILE_TO_BUFFER="COPY_FILE_TO_BUFFER",t.COPY_FILE_TO_PATH="COPY_FILE_TO_PATH",t.CREATE_PREPARED="CREATE_PREPARED",t.DISCONNECT="DISCONNECT",t.DROP_FILE="DROP_FILE",t.DROP_FILES="DROP_FILES",t.EXPORT_FILE_STATISTICS="EXPORT_FILE_STATISTICS",t.FETCH_QUERY_RESULTS="FETCH_QUERY_RESULTS",t.FLUSH_FILES="FLUSH_FILES",t.GET_FEATURE_FLAGS="GET_FEATURE_FLAGS",t.GET_TABLE_NAMES="GET_TABLE_NAMES",t.GET_VERSION="GET_VERSION",t.GLOB_FILE_INFOS="GLOB_FILE_INFOS",t.INSERT_ARROW_FROM_IPC_STREAM="INSERT_ARROW_FROM_IPC_STREAM",t.INSERT_CSV_FROM_PATH="IMPORT_CSV_FROM_PATH",t.INSERT_JSON_FROM_PATH="IMPORT_JSON_FROM_PATH",t.INSTANTIATE="INSTANTIATE",t.OPEN="OPEN",t.PING="PING",t.POLL_PENDING_QUERY="POLL_PENDING_QUERY",t.REGISTER_FILE_BUFFER="REGISTER_FILE_BUFFER",t.REGISTER_FILE_HANDLE="REGISTER_FILE_HANDLE",t.REGISTER_FILE_URL="REGISTER_FILE_URL",t.RESET="RESET",t.RUN_PREPARED="RUN_PREPARED",t.RUN_QUERY="RUN_QUERY",t.SEND_PREPARED="SEND_PREPARED",t.START_PENDING_QUERY="START_PENDING_QUERY",t.TOKENIZE="TOKENIZE",t))(a||{}),i=(t=>(t.CONNECTION_INFO="CONNECTION_INFO",t.ERROR="ERROR",t.FEATURE_FLAGS="FEATURE_FLAGS",t.FILE_BUFFER="FILE_BUFFER",t.FILE_INFOS="FILE_INFOS",t.FILE_SIZE="FILE_SIZE",t.FILE_STATISTICS="FILE_STATISTICS",t.INSTANTIATE_PROGRESS="INSTANTIATE_PROGRESS",t.LOG="LOG",t.PROGRESS_UPDATE="PROGRESS_UPDATE",t.OK="OK",t.PREPARED_STATEMENT_ID="PREPARED_STATEMENT_ID",t.QUERY_PLAN="QUERY_PLAN",t.QUERY_RESULT="QUERY_RESULT",t.QUERY_RESULT_CHUNK="QUERY_RESULT_CHUNK",t.QUERY_RESULT_HEADER="QUERY_RESULT_HEADER",t.QUERY_RESULT_HEADER_OR_NULL="QUERY_RESULT_HEADER_OR_NULL",t.REGISTERED_FILE="REGISTERED_FILE",t.SCRIPT_TOKENS="SCRIPT_TOKENS",t.SUCCESS="SUCCESS",t.TABLE_NAMES="TABLE_NAMES",t.VERSION_STRING="VERSION_STRING",t))(i||{});class _{constructor(s,e){this.promiseResolver=()=>{},this.promiseRejecter=()=>{},this.type=s,this.data=e,this.promise=new Promise((n,r)=>{this.promiseResolver=n,this.promiseRejecter=r})}}const Y=/'(opfs:\/\/\S*?)'/g,H=/(opfs:\/\/\S*?)/g;function K(t){return t.search(H)>-1}function v(t){return[...t.matchAll(Y)].map(s=>s[1])}const B=new TextEncoder;class L{constructor(s,e=null){this._onInstantiationProgress=[],this._onExecutionProgress=[],this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{},this._nextMessageId=0,this._pendingRequests=new Map,this._config={},this._logger=s,this._onMessageHandler=this.onMessage.bind(this),this._onErrorHandler=this.onError.bind(this),this._onCloseHandler=this.onClose.bind(this),e!=null&&this.attach(e)}get logger(){return this._logger}get config(){return this._config}attach(s){this._worker=s,this._worker.addEventListener("message",this._onMessageHandler),this._worker.addEventListener("error",this._onErrorHandler),this._worker.addEventListener("close",this._onCloseHandler),this._workerShutdownPromise=new Promise((e,n)=>{this._workerShutdownResolver=e})}detach(){this._worker&&(this._worker.removeEventListener("message",this._onMessageHandler),this._worker.removeEventListener("error",this._onErrorHandler),this._worker.removeEventListener("close",this._onCloseHandler),this._worker=null,this._workerShutdownResolver(null),this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{})}async terminate(){this._worker&&(this._worker.terminate(),this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{})}async postTask(s,e=[]){if(!this._worker){console.error("cannot send a message since the worker is not set!:"+s.type+","+s.data);return}const n=this._nextMessageId++;return this._pendingRequests.set(n,s),this._worker.postMessage({messageId:n,type:s.type,data:s.data},e),await s.promise}onMessage(s){var r;const e=s.data;switch(e.type){case i.PROGRESS_UPDATE:{for(const d of this._onExecutionProgress)d(e.data);return}case i.LOG:{this._logger.log(e.data);return}case i.INSTANTIATE_PROGRESS:{for(const d of this._onInstantiationProgress)d(e.data);return}}const n=this._pendingRequests.get(e.requestId);if(!n){console.warn(`unassociated response: [${e.requestId}, ${e.type.toString()}]`);return}if(this._pendingRequests.delete(e.requestId),e.type==i.ERROR){const d=new Error(e.data.message);d.name=e.data.name,(r=Object.getOwnPropertyDescriptor(d,"stack"))!=null&&r.writable&&(d.stack=e.data.stack),n.promiseRejecter(d);return}switch(n.type){case a.CLOSE_PREPARED:case a.COLLECT_FILE_STATISTICS:case a.REGISTER_OPFS_FILE_NAME:case a.COPY_FILE_TO_PATH:case a.DISCONNECT:case a.DROP_FILE:case a.DROP_FILES:case a.FLUSH_FILES:case a.INSERT_ARROW_FROM_IPC_STREAM:case a.INSERT_CSV_FROM_PATH:case a.INSERT_JSON_FROM_PATH:case a.OPEN:case a.PING:case a.REGISTER_FILE_BUFFER:case a.REGISTER_FILE_HANDLE:case a.REGISTER_FILE_URL:case a.RESET:if(e.type==i.OK){n.promiseResolver(e.data);return}break;case a.INSTANTIATE:if(this._onInstantiationProgress=[],e.type==i.OK){n.promiseResolver(e.data);return}break;case a.GLOB_FILE_INFOS:if(e.type==i.FILE_INFOS){n.promiseResolver(e.data);return}break;case a.GET_VERSION:if(e.type==i.VERSION_STRING){n.promiseResolver(e.data);return}break;case a.GET_FEATURE_FLAGS:if(e.type==i.FEATURE_FLAGS){n.promiseResolver(e.data);return}break;case a.GET_TABLE_NAMES:if(e.type==i.TABLE_NAMES){n.promiseResolver(e.data);return}break;case a.TOKENIZE:if(e.type==i.SCRIPT_TOKENS){n.promiseResolver(e.data);return}break;case a.COPY_FILE_TO_BUFFER:if(e.type==i.FILE_BUFFER){n.promiseResolver(e.data);return}break;case a.EXPORT_FILE_STATISTICS:if(e.type==i.FILE_STATISTICS){n.promiseResolver(e.data);return}break;case a.CONNECT:if(e.type==i.CONNECTION_INFO){n.promiseResolver(e.data);return}break;case a.RUN_PREPARED:case a.RUN_QUERY:if(e.type==i.QUERY_RESULT){n.promiseResolver(e.data);return}break;case a.SEND_PREPARED:if(e.type==i.QUERY_RESULT_HEADER){n.promiseResolver(e.data);return}break;case a.START_PENDING_QUERY:if(e.type==i.QUERY_RESULT_HEADER_OR_NULL){n.promiseResolver(e.data);return}break;case a.POLL_PENDING_QUERY:if(e.type==i.QUERY_RESULT_HEADER_OR_NULL){n.promiseResolver(e.data);return}break;case a.CANCEL_PENDING_QUERY:if(this._onInstantiationProgress=[],e.type==i.SUCCESS){n.promiseResolver(e.data);return}break;case a.FETCH_QUERY_RESULTS:if(e.type==i.QUERY_RESULT_CHUNK){n.promiseResolver(e.data);return}break;case a.CREATE_PREPARED:if(e.type==i.PREPARED_STATEMENT_ID){n.promiseResolver(e.data);return}break}n.promiseRejecter(new Error(`unexpected response type: ${e.type.toString()}`))}onError(s){console.error(s),console.error(`error in duckdb worker: ${s.message}`),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn(`worker terminated with ${this._pendingRequests.size} pending requests`);return}this._pendingRequests.clear()}isDetached(){return!this._worker}async reset(){const s=new _(a.RESET,null);return await this.postTask(s)}async ping(){const s=new _(a.PING,null);await this.postTask(s)}async dropFile(s){const e=new _(a.DROP_FILE,s);return await this.postTask(e)}async dropFiles(s){const e=new _(a.DROP_FILES,s);return await this.postTask(e)}async flushFiles(){const s=new _(a.FLUSH_FILES,null);return await this.postTask(s)}async instantiate(s,e=null,n=r=>{}){this._onInstantiationProgress.push(n);const r=new _(a.INSTANTIATE,[s,e]);return await this.postTask(r)}async getVersion(){const s=new _(a.GET_VERSION,null);return await this.postTask(s)}async getFeatureFlags(){const s=new _(a.GET_FEATURE_FLAGS,null);return await this.postTask(s)}async open(s){this._config=s;const e=new _(a.OPEN,s);await this.postTask(e)}async tokenize(s){const e=new _(a.TOKENIZE,s);return await this.postTask(e)}async connectInternal(){const s=new _(a.CONNECT,null);return await this.postTask(s)}async connect(){const s=await this.connectInternal();return new u(this,s)}async disconnect(s){const e=new _(a.DISCONNECT,s);await this.postTask(e)}async runQuery(s,e){if(this.shouldOPFSFileHandling()){const n=await this.registerOPFSFileFromSQL(e);try{return await this._runQueryAsync(s,e)}finally{n.length>0&&await this.dropFiles(n)}}else return await this._runQueryAsync(s,e)}async _runQueryAsync(s,e){const n=new _(a.RUN_QUERY,[s,e]);return await this.postTask(n)}async startPendingQuery(s,e,n=!1){if(this.shouldOPFSFileHandling()){const r=await this.registerOPFSFileFromSQL(e);try{return await this._startPendingQueryAsync(s,e,n)}finally{r.length>0&&await this.dropFiles(r)}}else return await this._startPendingQueryAsync(s,e,n)}async _startPendingQueryAsync(s,e,n=!1){const r=new _(a.START_PENDING_QUERY,[s,e,n]);return await this.postTask(r)}async pollPendingQuery(s){const e=new _(a.POLL_PENDING_QUERY,s);return await this.postTask(e)}async cancelPendingQuery(s){const e=new _(a.CANCEL_PENDING_QUERY,s);return await this.postTask(e)}async fetchQueryResults(s){const e=new _(a.FETCH_QUERY_RESULTS,s);return await this.postTask(e)}async getTableNames(s,e){const n=new _(a.GET_TABLE_NAMES,[s,e]);return await this.postTask(n)}async createPrepared(s,e){const n=new _(a.CREATE_PREPARED,[s,e]);return await this.postTask(n)}async closePrepared(s,e){const n=new _(a.CLOSE_PREPARED,[s,e]);await this.postTask(n)}async runPrepared(s,e,n){const r=new _(a.RUN_PREPARED,[s,e,n]);return await this.postTask(r)}async sendPrepared(s,e,n){const r=new _(a.SEND_PREPARED,[s,e,n]);return await this.postTask(r)}async globFiles(s){const e=new _(a.GLOB_FILE_INFOS,s);return await this.postTask(e)}async registerFileText(s,e){const n=B.encode(e);await this.registerFileBuffer(s,n)}async registerFileURL(s,e,n,r){e===void 0&&(e=s);const d=new _(a.REGISTER_FILE_URL,[s,e,n,r]);await this.postTask(d)}async registerEmptyFileBuffer(s){}async registerFileBuffer(s,e){const n=new _(a.REGISTER_FILE_BUFFER,[s,e]);await this.postTask(n,[e.buffer])}async registerFileHandle(s,e,n,r){const d=new _(a.REGISTER_FILE_HANDLE,[s,e,n,r]);await this.postTask(d,[])}async registerOPFSFileName(s){const e=new _(a.REGISTER_OPFS_FILE_NAME,[s]);await this.postTask(e,[])}async collectFileStatistics(s,e){const n=new _(a.COLLECT_FILE_STATISTICS,[s,e]);await this.postTask(n,[])}async exportFileStatistics(s){const e=new _(a.EXPORT_FILE_STATISTICS,s);return await this.postTask(e,[])}async copyFileToBuffer(s){const e=new _(a.COPY_FILE_TO_BUFFER,s);return await this.postTask(e)}async copyFileToPath(s,e){const n=new _(a.COPY_FILE_TO_PATH,[s,e]);await this.postTask(n)}async insertArrowFromIPCStream(s,e,n){if(e.length==0)return;const r=new _(a.INSERT_ARROW_FROM_IPC_STREAM,[s,e,n]);await this.postTask(r,[e.buffer])}async insertCSVFromPath(s,e,n){const r=new _(a.INSERT_CSV_FROM_PATH,[s,e,n]);await this.postTask(r)}async insertJSONFromPath(s,e,n){const r=new _(a.INSERT_JSON_FROM_PATH,[s,e,n]);await this.postTask(r)}shouldOPFSFileHandling(){var s;return K(this.config.path??"")?((s=this.config.opfs)==null?void 0:s.fileHandling)=="auto":!1}async registerOPFSFileFromSQL(s){const e=v(s),n=[];for(const r of e)try{await this.registerOPFSFileName(r),n.push(r)}catch(d){throw console.error(d),new Error("File Not found:"+r)}return n}}function W(){const t=new TextDecoder;return s=>(typeof SharedArrayBuffer<"u"&&s.buffer instanceof SharedArrayBuffer&&(s=new Uint8Array(s)),t.decode(s))}W();var C=(t=>(t[t.BUFFER=0]="BUFFER",t[t.NODE_FS=1]="NODE_FS",t[t.BROWSER_FILEREADER=2]="BROWSER_FILEREADER",t[t.BROWSER_FSACCESS=3]="BROWSER_FSACCESS",t[t.HTTP=4]="HTTP",t[t.S3=5]="S3",t))(C||{});new TextEncoder;var U=(t=>(t[t.WASM_EXCEPTIONS=1]="WASM_EXCEPTIONS",t[t.WASM_THREADS=2]="WASM_THREADS",t[t.WASM_SIMD=4]="WASM_SIMD",t[t.WASM_BULK_MEMORY=8]="WASM_BULK_MEMORY",t[t.EMIT_BIGINT=16]="EMIT_BIGINT",t[t.WASMFS=32]="WASMFS",t))(U||{});class V{constructor(){this._bindings=null,this._nextMessageId=0}log(s){this.postMessage({messageId:this._nextMessageId++,requestId:0,type:i.LOG,data:s},[])}sendOK(s){this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.OK,data:null},[])}failWith(s,e){const n={name:e.name,message:e.message,stack:e.stack||void 0};this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.ERROR,data:n},[])}async onMessage(s){switch(s.type){case a.PING:this.sendOK(s);return;case a.INSTANTIATE:this._bindings!=null&&this.failWith(s,new Error("duckdb already initialized"));try{this._bindings=await this.instantiate(s.data[0],s.data[1],e=>{this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.INSTANTIATE_PROGRESS,data:e},[])}),this.sendOK(s)}catch(e){console.log(e),this._bindings=null,this.failWith(s,e)}return}if(!this._bindings)return this.failWith(s,new Error("duckdb is not initialized"));try{switch(s.type){case a.GET_VERSION:this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.VERSION_STRING,data:this._bindings.getVersion()},[]);break;case a.GET_FEATURE_FLAGS:this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.FEATURE_FLAGS,data:this._bindings.getFeatureFlags()},[]);break;case a.RESET:this._bindings.reset(),this.sendOK(s);break;case a.OPEN:{const e=s.data.path,n=!!(this._bindings.getFeatureFlags()&U.WASM_THREADS);if(e!=null&&e.startsWith("opfs://")&&!n){const r=globalThis.DUCKDB_RUNTIME;r!=null&&r.prepareDBFileHandle&&await r.prepareDBFileHandle(e,C.BROWSER_FSACCESS),s.data.useDirectIO=!0}this._bindings.open(s.data),this.sendOK(s);break}case a.DROP_FILE:this._bindings.dropFile(s.data),this.sendOK(s);break;case a.DROP_FILES:this._bindings.dropFiles(s.data),this.sendOK(s);break;case a.FLUSH_FILES:this._bindings.flushFiles(),this.sendOK(s);break;case a.CONNECT:{const e=this._bindings.connect();this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.CONNECTION_INFO,data:e.useUnsafe((n,r)=>r)},[]);break}case a.DISCONNECT:this._bindings.disconnect(s.data),this.sendOK(s);break;case a.CREATE_PREPARED:{const e=this._bindings.createPrepared(s.data[0],s.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.PREPARED_STATEMENT_ID,data:e},[]);break}case a.CLOSE_PREPARED:{this._bindings.closePrepared(s.data[0],s.data[1]),this.sendOK(s);break}case a.RUN_PREPARED:{const e=this._bindings.runPrepared(s.data[0],s.data[1],s.data[2]);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.QUERY_RESULT,data:e},[e.buffer]);break}case a.RUN_QUERY:{const e=this._bindings.runQuery(s.data[0],s.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.QUERY_RESULT,data:e},[e.buffer]);break}case a.SEND_PREPARED:{const e=this._bindings.sendPrepared(s.data[0],s.data[1],s.data[2]);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.QUERY_RESULT_HEADER,data:e},[e.buffer]);break}case a.START_PENDING_QUERY:{const e=this._bindings.startPendingQuery(s.data[0],s.data[1],s.data[2]),n=[];e&&n.push(e.buffer),this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.QUERY_RESULT_HEADER_OR_NULL,data:e},n);break}case a.POLL_PENDING_QUERY:{const e=this._bindings.pollPendingQuery(s.data),n=[];e&&n.push(e.buffer),this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.QUERY_RESULT_HEADER_OR_NULL,data:e},n);break}case a.CANCEL_PENDING_QUERY:{const e=this._bindings.cancelPendingQuery(s.data);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.SUCCESS,data:e},[]);break}case a.FETCH_QUERY_RESULTS:{const e=this._bindings.fetchQueryResults(s.data),n=e?[e.buffer]:[];this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.QUERY_RESULT_CHUNK,data:e},n);break}case a.GET_TABLE_NAMES:{const e=this._bindings.getTableNames(s.data[0],s.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.TABLE_NAMES,data:e},[]);break}case a.GLOB_FILE_INFOS:{const e=this._bindings.globFiles(s.data);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.FILE_INFOS,data:e},[]);break}case a.REGISTER_FILE_URL:this._bindings.registerFileURL(s.data[0],s.data[1],s.data[2],s.data[3]),this.sendOK(s);break;case a.REGISTER_FILE_BUFFER:this._bindings.registerFileBuffer(s.data[0],s.data[1]),this.sendOK(s);break;case a.REGISTER_FILE_HANDLE:await this._bindings.registerFileHandleAsync(s.data[0],s.data[1],s.data[2],s.data[3]),this.sendOK(s);break;case a.COPY_FILE_TO_PATH:this._bindings.copyFileToPath(s.data[0],s.data[1]),this.sendOK(s);break;case a.COPY_FILE_TO_BUFFER:{const e=this._bindings.copyFileToBuffer(s.data);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.FILE_BUFFER,data:e},[]);break}case a.COLLECT_FILE_STATISTICS:this._bindings.collectFileStatistics(s.data[0],s.data[1]),this.sendOK(s);break;case a.REGISTER_OPFS_FILE_NAME:await this._bindings.registerOPFSFileName(s.data[0]),this.sendOK(s);break;case a.EXPORT_FILE_STATISTICS:{this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.FILE_STATISTICS,data:this._bindings.exportFileStatistics(s.data)},[]);break}case a.INSERT_ARROW_FROM_IPC_STREAM:{this._bindings.insertArrowFromIPCStream(s.data[0],s.data[1],s.data[2]),this.sendOK(s);break}case a.INSERT_CSV_FROM_PATH:{this._bindings.insertCSVFromPath(s.data[0],s.data[1],s.data[2]),this.sendOK(s);break}case a.INSERT_JSON_FROM_PATH:{this._bindings.insertJSONFromPath(s.data[0],s.data[1],s.data[2]),this.sendOK(s);break}case a.TOKENIZE:{const e=this._bindings.tokenize(s.data);this.postMessage({messageId:this._nextMessageId++,requestId:s.messageId,type:i.SCRIPT_TOKENS,data:e},[]);break}}}catch(e){return console.log(e),this.failWith(s,e)}}}const X=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,3,1,0,1,10,14,1,12,0,65,0,65,0,65,0,252,10,0,0,11])),j=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,8,1,6,0,6,64,25,11,11])),J=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11])),x=()=>(async t=>{try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(t)}catch{return!1}})(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11])),l=()=>typeof navigator>"u",m=()=>l()?"node":navigator.userAgent,Z=()=>m().includes("Firefox"),z=()=>/^((?!chrome|android).)*safari/i.test(m());let T=null,N=null,O=null,g=null,F=null;async function b(){return T==null&&(T=typeof BigInt64Array<"u"),N==null&&(N=await j()),O==null&&(O=await x()),g==null&&(g=await J()),F==null&&(F=await X()),{bigInt64Array:T,crossOriginIsolated:l()||globalThis.crossOriginIsolated||!1,wasmExceptions:N,wasmSIMD:g,wasmThreads:O,wasmBulkMemory:F}}async function $(t){const s=await b();if(s.wasmExceptions){if(s.wasmSIMD&&s.wasmThreads&&s.crossOriginIsolated&&t.coi)return{mainModule:t.coi.mainModule,mainWorker:t.coi.mainWorker,pthreadWorker:t.coi.pthreadWorker};if(t.eh)return{mainModule:t.eh.mainModule,mainWorker:t.eh.mainWorker,pthreadWorker:null}}return{mainModule:t.mvp.mainModule,mainWorker:t.mvp.mainWorker,pthreadWorker:null}}const q=typeof Worker<"u"?Worker:void 0;async function ss(t){const s=new Request(t),e=await fetch(s),n=URL.createObjectURL(await e.blob());return new q(n)}async function ts(t,s){const e=new Worker(t.mainWorker),n=new L(s??new P,e);return await n.instantiate(t.mainModule,t.pthreadWorker),n}E.AsyncDuckDB=L,E.AsyncDuckDBConnection=u,E.AsyncDuckDBDispatcher=V,E.AsyncPreparedStatement=f,E.AsyncResultStreamIterator=S,E.ConsoleLogger=y,E.DuckDBAccessMode=R,E.IsArrowBuffer=D,E.IsDuckDBWasmRetry=Q,E.LogEvent=I,E.LogLevel=c,E.LogOrigin=h,E.LogTopic=o,E.StatusCode=w,E.TokenType=A,E.VoidLogger=P,E.WorkerRequestType=a,E.WorkerResponseType=i,E.WorkerTask=_,E.createWorker=ss,E.duckdb=ts,E.getLogEventLabel=p,E.getLogLevelLabel=M,E.getLogOriginLabel=G,E.getLogTopicLabel=k,E.getPlatformFeatures=b,E.isFirefox=Z,E.isNode=l,E.isSafari=z,E.selectBundle=$,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { DuckDBModule, PThread } from './duckdb_module';
|
|
2
|
+
import { DuckDBConfig } from './config';
|
|
3
|
+
import { Logger } from '../log';
|
|
4
|
+
import { InstantiationProgress } from './progress';
|
|
5
|
+
import { DuckDBBindings } from './bindings_interface';
|
|
6
|
+
import { DuckDBConnection } from './connection';
|
|
7
|
+
import { DuckDBRuntime, DuckDBDataProtocol } from './runtime';
|
|
8
|
+
import { CSVInsertOptions, JSONInsertOptions, ArrowInsertOptions } from './insert_options';
|
|
9
|
+
import { ScriptTokens } from './tokens';
|
|
10
|
+
import { FileStatistics } from './file_stats';
|
|
11
|
+
import { WebFile } from './web_file';
|
|
12
|
+
declare global {
|
|
13
|
+
var DUCKDB_RUNTIME: any;
|
|
14
|
+
}
|
|
15
|
+
/** A DuckDB Feature */
|
|
16
|
+
export declare enum DuckDBFeature {
|
|
17
|
+
WASM_EXCEPTIONS = 1,
|
|
18
|
+
WASM_THREADS = 2,
|
|
19
|
+
WASM_SIMD = 4,
|
|
20
|
+
WASM_BULK_MEMORY = 8,
|
|
21
|
+
EMIT_BIGINT = 16,
|
|
22
|
+
WASMFS = 32
|
|
23
|
+
}
|
|
24
|
+
/** The proxy for either the browser- order node-based DuckDB API */
|
|
25
|
+
export declare abstract class DuckDBBindingsBase implements DuckDBBindings {
|
|
26
|
+
/** The logger */
|
|
27
|
+
protected readonly _logger: Logger;
|
|
28
|
+
/** Backend-dependent native-glue code for DuckDB */
|
|
29
|
+
protected readonly _runtime: DuckDBRuntime;
|
|
30
|
+
/** The instance */
|
|
31
|
+
protected _instance: DuckDBModule | null;
|
|
32
|
+
/** The loading promise */
|
|
33
|
+
protected _initPromise: Promise<void> | null;
|
|
34
|
+
/** The resolver for the open promise (called by onRuntimeInitialized) */
|
|
35
|
+
protected _initPromiseResolver: () => void;
|
|
36
|
+
/** The next UDF id */
|
|
37
|
+
protected _nextUDFId: number;
|
|
38
|
+
constructor(logger: Logger, runtime: DuckDBRuntime);
|
|
39
|
+
/** Get the logger */
|
|
40
|
+
get logger(): Logger;
|
|
41
|
+
/** Get the instance */
|
|
42
|
+
get mod(): DuckDBModule;
|
|
43
|
+
/** Get the instance */
|
|
44
|
+
get pthread(): PThread | null;
|
|
45
|
+
/** Instantiate the module */
|
|
46
|
+
protected abstract instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule>;
|
|
47
|
+
/** Instantiate the module */
|
|
48
|
+
protected onInstantiationProgress: ((p: InstantiationProgress) => void)[];
|
|
49
|
+
/** Instantiate the database */
|
|
50
|
+
instantiate(onProgress?: (progress: InstantiationProgress) => void): Promise<this>;
|
|
51
|
+
/** Open a database with a config */
|
|
52
|
+
open(config: DuckDBConfig): void;
|
|
53
|
+
/** Reset the database */
|
|
54
|
+
reset(): void;
|
|
55
|
+
/** Get the version */
|
|
56
|
+
getVersion(): string;
|
|
57
|
+
/** Get the feature flags */
|
|
58
|
+
getFeatureFlags(): number;
|
|
59
|
+
/** Tokenize a script */
|
|
60
|
+
tokenize(text: string): ScriptTokens;
|
|
61
|
+
/** Connect to database */
|
|
62
|
+
connect(): DuckDBConnection;
|
|
63
|
+
/** Disconnect from database */
|
|
64
|
+
disconnect(conn: number): void;
|
|
65
|
+
/** Send a query and return the full result */
|
|
66
|
+
runQuery(conn: number, text: string): Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* Start a pending query asynchronously.
|
|
69
|
+
* This method returns either the arrow ipc schema or null.
|
|
70
|
+
* On null, the query has to be executed using `pollPendingQuery` until that returns != null.
|
|
71
|
+
* Results can then be fetched using `fetchQueryResults`
|
|
72
|
+
*/
|
|
73
|
+
startPendingQuery(conn: number, text: string, allowStreamResult?: boolean): Uint8Array | null;
|
|
74
|
+
/** Poll a pending query */
|
|
75
|
+
pollPendingQuery(conn: number): Uint8Array | null;
|
|
76
|
+
/** Cancel a pending query */
|
|
77
|
+
cancelPendingQuery(conn: number): boolean;
|
|
78
|
+
/** Fetch query results */
|
|
79
|
+
fetchQueryResults(conn: number): Uint8Array | null;
|
|
80
|
+
/** Get table names */
|
|
81
|
+
getTableNames(conn: number, text: string): string[];
|
|
82
|
+
/** Create a scalar function */
|
|
83
|
+
/** Prepare a statement and return its identifier */
|
|
84
|
+
createPrepared(conn: number, text: string): number;
|
|
85
|
+
/** Close a prepared statement */
|
|
86
|
+
closePrepared(conn: number, statement: number): void;
|
|
87
|
+
/** Execute a prepared statement and return the full result */
|
|
88
|
+
runPrepared(conn: number, statement: number, params: any[]): Uint8Array;
|
|
89
|
+
/** Execute a prepared statement and stream the result */
|
|
90
|
+
sendPrepared(conn: number, statement: number, params: any[]): Uint8Array;
|
|
91
|
+
/** Insert record batches from an arrow ipc stream */
|
|
92
|
+
insertArrowFromIPCStream(conn: number, buffer: Uint8Array, options?: ArrowInsertOptions): void;
|
|
93
|
+
/** Insert csv from path */
|
|
94
|
+
insertCSVFromPath(conn: number, path: string, options: CSVInsertOptions): void;
|
|
95
|
+
/** Insert json from path */
|
|
96
|
+
insertJSONFromPath(conn: number, path: string, options: JSONInsertOptions): void;
|
|
97
|
+
/** Glob file infos */
|
|
98
|
+
globFiles(path: string): WebFile[];
|
|
99
|
+
/** Register a file object URL */
|
|
100
|
+
registerFileURL(name: string, url: string, proto: DuckDBDataProtocol, directIO?: boolean): void;
|
|
101
|
+
/** Register file text */
|
|
102
|
+
registerFileText(name: string, text: string): void;
|
|
103
|
+
/** Register a file buffer */
|
|
104
|
+
registerFileBuffer(name: string, buffer: Uint8Array): void;
|
|
105
|
+
prepareFileHandle(fileName: string, protocol: DuckDBDataProtocol): Promise<void>;
|
|
106
|
+
/** Prepare a file handle that could only be acquired aschronously */
|
|
107
|
+
prepareDBFileHandle(path: string, protocol: DuckDBDataProtocol): Promise<void>;
|
|
108
|
+
/** Prepare a file object URL */
|
|
109
|
+
prepareFileHandleAsync<HandleType>(name: string, handle: HandleType, protocol: DuckDBDataProtocol, directIO: boolean): Promise<HandleType>;
|
|
110
|
+
/** Register a file object URL async */
|
|
111
|
+
registerFileHandleAsync<HandleType>(name: string, handle: HandleType, protocol: DuckDBDataProtocol, directIO: boolean): Promise<void>;
|
|
112
|
+
/** Register a file object URL */
|
|
113
|
+
registerFileHandle<HandleType>(name: string, handle: HandleType, protocol: DuckDBDataProtocol, directIO: boolean): void;
|
|
114
|
+
/** Drop file */
|
|
115
|
+
dropFile(name: string): void;
|
|
116
|
+
/** Drop files */
|
|
117
|
+
dropFiles(names?: string[]): void;
|
|
118
|
+
/** Flush all files */
|
|
119
|
+
flushFiles(): void;
|
|
120
|
+
/** Write a file to a path */
|
|
121
|
+
copyFileToPath(name: string, path: string): void;
|
|
122
|
+
/** Write a file to a buffer */
|
|
123
|
+
copyFileToBuffer(name: string): Uint8Array;
|
|
124
|
+
/** Enable tracking of file statistics */
|
|
125
|
+
registerOPFSFileName(file: string): Promise<void>;
|
|
126
|
+
collectFileStatistics(file: string, enable: boolean): void;
|
|
127
|
+
/** Export file statistics */
|
|
128
|
+
exportFileStatistics(file: string): FileStatistics;
|
|
129
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DuckDBModule } from './duckdb_module';
|
|
2
|
+
import { DuckDBBindingsBase } from './bindings_base';
|
|
3
|
+
import { DuckDBRuntime } from './runtime';
|
|
4
|
+
import { Logger } from '../log';
|
|
5
|
+
/** DuckDB bindings for the browser */
|
|
6
|
+
export declare abstract class DuckDBBrowserBindings extends DuckDBBindingsBase {
|
|
7
|
+
/** The path of the wasm module */
|
|
8
|
+
protected readonly mainModuleURL: string;
|
|
9
|
+
/** The path of the pthread worker script */
|
|
10
|
+
protected readonly pthreadWorkerURL: string | null;
|
|
11
|
+
/** Constructor */
|
|
12
|
+
constructor(logger: Logger, runtime: DuckDBRuntime, mainModuleURL: string, pthreadWorkerURL: string | null);
|
|
13
|
+
/** Locate a file */
|
|
14
|
+
protected locateFile(path: string, prefix: string): string;
|
|
15
|
+
/** Instantiate the wasm module */
|
|
16
|
+
protected instantiateWasm(imports: any, success: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void): WebAssembly.Exports;
|
|
17
|
+
protected abstract instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DuckDBBrowserBindings } from './bindings_browser_base';
|
|
2
|
+
import { DuckDBModule } from './duckdb_module';
|
|
3
|
+
import { DuckDBRuntime } from './runtime';
|
|
4
|
+
import { Logger } from '../log';
|
|
5
|
+
/** DuckDB bindings for the browser */
|
|
6
|
+
export declare class DuckDB extends DuckDBBrowserBindings {
|
|
7
|
+
/** Constructor */
|
|
8
|
+
constructor(logger: Logger, runtime: DuckDBRuntime, mainModuleURL: string, pthreadWorkerURL?: string | null);
|
|
9
|
+
/** Instantiate the bindings */
|
|
10
|
+
protected instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule>;
|
|
11
|
+
}
|
|
12
|
+
export default DuckDB;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DuckDBBrowserBindings } from './bindings_browser_base';
|
|
2
|
+
import { DuckDBModule } from './duckdb_module';
|
|
3
|
+
import { DuckDBRuntime } from './runtime';
|
|
4
|
+
import { Logger } from '../log';
|
|
5
|
+
/** DuckDB bindings for the browser */
|
|
6
|
+
export declare class DuckDB extends DuckDBBrowserBindings {
|
|
7
|
+
/** Constructor */
|
|
8
|
+
constructor(logger: Logger, runtime: DuckDBRuntime, mainModuleURL: string, pthreadWorkerURL?: string | null);
|
|
9
|
+
/** Instantiate the bindings */
|
|
10
|
+
protected instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule>;
|
|
11
|
+
}
|
|
12
|
+
export default DuckDB;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DuckDBBrowserBindings } from './bindings_browser_base';
|
|
2
|
+
import { DuckDBModule } from './duckdb_module';
|
|
3
|
+
import { DuckDBRuntime } from './runtime';
|
|
4
|
+
import { Logger } from '../log';
|
|
5
|
+
/** DuckDB bindings for the browser */
|
|
6
|
+
export declare class DuckDB extends DuckDBBrowserBindings {
|
|
7
|
+
/** Constructor */
|
|
8
|
+
constructor(logger: Logger, runtime: DuckDBRuntime, mainModuleURL: string, pthreadWorkerURL?: string | null);
|
|
9
|
+
/** Instantiate the bindings */
|
|
10
|
+
protected instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DuckDBConfig, DuckDBConnection, DuckDBDataProtocol, FileStatistics, InstantiationProgress } from '.';
|
|
2
|
+
import { CSVInsertOptions, JSONInsertOptions, ArrowInsertOptions } from './insert_options';
|
|
3
|
+
import { ScriptTokens } from './tokens';
|
|
4
|
+
import { WebFile } from './web_file';
|
|
5
|
+
export interface DuckDBBindings {
|
|
6
|
+
open(config: DuckDBConfig): void;
|
|
7
|
+
reset(): void;
|
|
8
|
+
instantiate(onProgress: (p: InstantiationProgress) => void): Promise<this>;
|
|
9
|
+
getVersion(): string;
|
|
10
|
+
getFeatureFlags(): number;
|
|
11
|
+
tokenize(text: string): ScriptTokens;
|
|
12
|
+
connect(): DuckDBConnection;
|
|
13
|
+
disconnect(conn: number): void;
|
|
14
|
+
runQuery(conn: number, text: string): Uint8Array;
|
|
15
|
+
startPendingQuery(conn: number, text: string, allowStreamResult: boolean): Uint8Array | null;
|
|
16
|
+
pollPendingQuery(conn: number): Uint8Array | null;
|
|
17
|
+
cancelPendingQuery(conn: number): boolean;
|
|
18
|
+
fetchQueryResults(conn: number): Uint8Array | null;
|
|
19
|
+
getTableNames(conn: number, text: string): string[];
|
|
20
|
+
createPrepared(conn: number, text: string): number;
|
|
21
|
+
closePrepared(conn: number, statement: number): void;
|
|
22
|
+
runPrepared(conn: number, statement: number, params: any[]): Uint8Array;
|
|
23
|
+
sendPrepared(conn: number, statement: number, params: any[]): Uint8Array;
|
|
24
|
+
insertArrowFromIPCStream(conn: number, buffer: Uint8Array, options?: ArrowInsertOptions): void;
|
|
25
|
+
insertCSVFromPath(conn: number, path: string, options: CSVInsertOptions): void;
|
|
26
|
+
insertJSONFromPath(conn: number, path: string, options: JSONInsertOptions): void;
|
|
27
|
+
registerFileURL(name: string, url: string, proto: DuckDBDataProtocol, directIO: boolean): void;
|
|
28
|
+
registerFileText(name: string, text: string): void;
|
|
29
|
+
registerFileBuffer(name: string, buffer: Uint8Array): void;
|
|
30
|
+
registerFileHandle<HandleType>(name: string, handle: HandleType, protocol: DuckDBDataProtocol, directIO: boolean): void;
|
|
31
|
+
registerFileHandleAsync<HandleType>(name: string, handle: HandleType, protocol: DuckDBDataProtocol, directIO: boolean): Promise<void>;
|
|
32
|
+
prepareFileHandleAsync<HandleType>(name: string, handle: HandleType, protocol: DuckDBDataProtocol, directIO: boolean): Promise<HandleType>;
|
|
33
|
+
prepareFileHandle(path: string, protocol: DuckDBDataProtocol): Promise<void>;
|
|
34
|
+
prepareDBFileHandle(path: string, protocol: DuckDBDataProtocol): Promise<void>;
|
|
35
|
+
globFiles(path: string): WebFile[];
|
|
36
|
+
dropFile(name: string): void;
|
|
37
|
+
dropFiles(names?: string[]): void;
|
|
38
|
+
flushFiles(): void;
|
|
39
|
+
copyFileToPath(name: string, path: string): void;
|
|
40
|
+
copyFileToBuffer(name: string): Uint8Array;
|
|
41
|
+
registerOPFSFileName(file: string): Promise<void>;
|
|
42
|
+
collectFileStatistics(file: string, enable: boolean): void;
|
|
43
|
+
exportFileStatistics(file: string): FileStatistics;
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DuckDBModule } from './duckdb_module';
|
|
2
|
+
import { DuckDBBindingsBase } from './bindings_base';
|
|
3
|
+
import { DuckDBRuntime } from './runtime';
|
|
4
|
+
import { Logger } from '../log';
|
|
5
|
+
declare global {
|
|
6
|
+
var DUCKDB_RUNTIME: any;
|
|
7
|
+
}
|
|
8
|
+
/** DuckDB bindings for node.js */
|
|
9
|
+
export declare class DuckDBNodeBindings extends DuckDBBindingsBase {
|
|
10
|
+
/** The path of the wasm module */
|
|
11
|
+
protected readonly mainModulePath: string;
|
|
12
|
+
/** The path of the pthread worker script */
|
|
13
|
+
protected readonly pthreadWorkerPath: string | null;
|
|
14
|
+
/** Constructor */
|
|
15
|
+
constructor(logger: Logger, runtime: DuckDBRuntime, mainModulePath: string, pthreadWorkerPath: string | null);
|
|
16
|
+
/** Locate a file */
|
|
17
|
+
protected locateFile(path: string, prefix: string): string;
|
|
18
|
+
/** Instantiate the wasm module */
|
|
19
|
+
protected instantiateWasm(imports: any, success: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void): WebAssembly.Exports;
|
|
20
|
+
/** Instantiate the bindings */
|
|
21
|
+
protected instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DuckDBModule } from './duckdb_module';
|
|
2
|
+
import { DuckDBNodeBindings } from './bindings_node_base.js';
|
|
3
|
+
import { DuckDBRuntime } from './runtime';
|
|
4
|
+
import { Logger } from '../log';
|
|
5
|
+
/** DuckDB bindings for node.js */
|
|
6
|
+
export declare class DuckDB extends DuckDBNodeBindings {
|
|
7
|
+
/** Constructor */
|
|
8
|
+
constructor(logger: Logger, runtime: DuckDBRuntime, mainModulePath: string, pthreadWorkerPath?: string | null);
|
|
9
|
+
/** Instantiate the bindings */
|
|
10
|
+
protected instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule>;
|
|
11
|
+
}
|
|
12
|
+
export default DuckDB;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DuckDBNodeBindings } from './bindings_node_base.js';
|
|
2
|
+
import { Logger } from '../log.js';
|
|
3
|
+
import { DuckDBModule } from './duckdb_module';
|
|
4
|
+
import { DuckDBRuntime } from './runtime';
|
|
5
|
+
/** DuckDB bindings for node.js */
|
|
6
|
+
export declare class DuckDB extends DuckDBNodeBindings {
|
|
7
|
+
/** Constructor */
|
|
8
|
+
constructor(logger: Logger, runtime: DuckDBRuntime, mainModulePath: string, pthreadWorkerPath?: string | null);
|
|
9
|
+
/** Instantiate the bindings */
|
|
10
|
+
protected instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule>;
|
|
11
|
+
}
|
|
12
|
+
export default DuckDB;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export interface DuckDBQueryConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The polling interval for queries
|
|
4
|
+
*/
|
|
5
|
+
queryPollingInterval?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Cast BigInt to Double?
|
|
8
|
+
*/
|
|
9
|
+
castBigIntToDouble?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Cast Timestamp to Date64?
|
|
12
|
+
*/
|
|
13
|
+
castTimestampToDate?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Cast Timestamp to Date64?
|
|
16
|
+
*/
|
|
17
|
+
castDurationToTime64?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Cast Decimal to Double?
|
|
20
|
+
*/
|
|
21
|
+
castDecimalToDouble?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface DuckDBFilesystemConfig {
|
|
24
|
+
reliableHeadRequests?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Allow falling back to full HTTP reads if the server does not support range requests.
|
|
27
|
+
*/
|
|
28
|
+
allowFullHTTPReads?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Force use of full HTTP reads, suppressing range requests.
|
|
31
|
+
*/
|
|
32
|
+
forceFullHTTPReads?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface DuckDBOPFSConfig {
|
|
35
|
+
/**
|
|
36
|
+
* Defines how `opfs://` files are handled during SQL execution.
|
|
37
|
+
* - "auto": Automatically register `opfs://` files and drop them after execution.
|
|
38
|
+
* - "manual": Files must be manually registered and dropped.
|
|
39
|
+
*/
|
|
40
|
+
fileHandling?: "auto" | "manual";
|
|
41
|
+
}
|
|
42
|
+
export declare enum DuckDBAccessMode {
|
|
43
|
+
UNDEFINED = 0,
|
|
44
|
+
AUTOMATIC = 1,
|
|
45
|
+
READ_ONLY = 2,
|
|
46
|
+
READ_WRITE = 3
|
|
47
|
+
}
|
|
48
|
+
export interface DuckDBConfig {
|
|
49
|
+
/**
|
|
50
|
+
* The database path
|
|
51
|
+
*/
|
|
52
|
+
path?: string;
|
|
53
|
+
/**
|
|
54
|
+
* The access mode
|
|
55
|
+
*/
|
|
56
|
+
accessMode?: DuckDBAccessMode;
|
|
57
|
+
/**
|
|
58
|
+
* The maximum number of threads.
|
|
59
|
+
* Note that this will only work with cross-origin isolated sites since it requires SharedArrayBuffers.
|
|
60
|
+
*/
|
|
61
|
+
maximumThreads?: number;
|
|
62
|
+
/**
|
|
63
|
+
* The direct io flag
|
|
64
|
+
*/
|
|
65
|
+
useDirectIO?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The query config
|
|
68
|
+
*/
|
|
69
|
+
query?: DuckDBQueryConfig;
|
|
70
|
+
/**
|
|
71
|
+
* The filesystem config
|
|
72
|
+
*/
|
|
73
|
+
filesystem?: DuckDBFilesystemConfig;
|
|
74
|
+
/**
|
|
75
|
+
* Whether to allow unsigned extensions
|
|
76
|
+
*/
|
|
77
|
+
allowUnsignedExtensions?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Whether to use alternate Arrow conversion that preserves full range and precision of data.
|
|
80
|
+
*/
|
|
81
|
+
arrowLosslessConversion?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Custom user agent string
|
|
84
|
+
*/
|
|
85
|
+
customUserAgent?: string;
|
|
86
|
+
/**
|
|
87
|
+
* opfs string
|
|
88
|
+
*/
|
|
89
|
+
opfs?: DuckDBOPFSConfig;
|
|
90
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DuckDBBindings } from './bindings_interface';
|
|
2
|
+
import { CSVInsertOptions, JSONInsertOptions, ArrowInsertOptions } from './insert_options';
|
|
3
|
+
/** A thin helper to bind the connection id and talk record batches */
|
|
4
|
+
export declare class DuckDBConnection {
|
|
5
|
+
/** The bindings */
|
|
6
|
+
protected _bindings: DuckDBBindings;
|
|
7
|
+
/** The connection handle */
|
|
8
|
+
protected _conn: number;
|
|
9
|
+
/** Constructor */
|
|
10
|
+
constructor(bindings: DuckDBBindings, conn: number);
|
|
11
|
+
/** Close a connection */
|
|
12
|
+
close(): void;
|
|
13
|
+
/** Brave souls may use this function to consume the underlying connection id */
|
|
14
|
+
useUnsafe<R>(callback: (bindings: DuckDBBindings, conn: number) => R): R;
|
|
15
|
+
/** Run a query */
|
|
16
|
+
query(text: string): Uint8Array;
|
|
17
|
+
/** Send a query */
|
|
18
|
+
send(text: string, allowStreamResult?: boolean): Promise<Iterable<Uint8Array>>;
|
|
19
|
+
/** Cancel a query that was sent earlier */
|
|
20
|
+
cancelSent(): boolean;
|
|
21
|
+
/** Get table names */
|
|
22
|
+
getTableNames(query: string): string[];
|
|
23
|
+
/** Create a prepared statement */
|
|
24
|
+
prepare(text: string): PreparedStatement;
|
|
25
|
+
/** Create a scalar function */
|
|
26
|
+
/** Insert an arrow table from an ipc stream */
|
|
27
|
+
insertArrowFromIPCStream(buffer: Uint8Array, options: ArrowInsertOptions): void;
|
|
28
|
+
/** Inesrt csv file from path */
|
|
29
|
+
insertCSVFromPath(path: string, options: CSVInsertOptions): void;
|
|
30
|
+
/** Insert json file from path */
|
|
31
|
+
insertJSONFromPath(path: string, options: JSONInsertOptions): void;
|
|
32
|
+
}
|
|
33
|
+
/** A result stream iterator */
|
|
34
|
+
export declare class ResultStreamIterator implements Iterable<Uint8Array> {
|
|
35
|
+
protected bindings: DuckDBBindings;
|
|
36
|
+
protected conn: number;
|
|
37
|
+
protected header: Uint8Array;
|
|
38
|
+
/** First chunk? */
|
|
39
|
+
_first: boolean;
|
|
40
|
+
/** Reached end of stream? */
|
|
41
|
+
_depleted: boolean;
|
|
42
|
+
constructor(bindings: DuckDBBindings, conn: number, header: Uint8Array);
|
|
43
|
+
next(): IteratorResult<Uint8Array>;
|
|
44
|
+
[Symbol.iterator](): this;
|
|
45
|
+
}
|
|
46
|
+
/** A thin helper to bind the prepared statement id*/
|
|
47
|
+
export declare class PreparedStatement {
|
|
48
|
+
/** The bindings */
|
|
49
|
+
protected readonly bindings: DuckDBBindings;
|
|
50
|
+
/** The connection id */
|
|
51
|
+
protected readonly connectionId: number;
|
|
52
|
+
/** The statement id */
|
|
53
|
+
protected readonly statementId: number;
|
|
54
|
+
/** Constructor */
|
|
55
|
+
constructor(bindings: DuckDBBindings, connectionId: number, statementId: number);
|
|
56
|
+
/** Close a prepared statement */
|
|
57
|
+
close(): void;
|
|
58
|
+
/** Run a prepared statement */
|
|
59
|
+
query(...params: any[]): Uint8Array;
|
|
60
|
+
/** Send a prepared statement */
|
|
61
|
+
send(...params: any[]): Iterable<Uint8Array>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface PThread {
|
|
2
|
+
unusedWorkers: Worker[];
|
|
3
|
+
runningWorkers: Worker[];
|
|
4
|
+
}
|
|
5
|
+
export interface DuckDBModule extends EmscriptenModule {
|
|
6
|
+
stackSave: typeof stackSave;
|
|
7
|
+
stackAlloc: typeof stackAlloc;
|
|
8
|
+
stackRestore: typeof stackRestore;
|
|
9
|
+
lengthBytesUTF8: typeof lengthBytesUTF8;
|
|
10
|
+
stringToUTF8: typeof stringToUTF8;
|
|
11
|
+
ccall: typeof ccall;
|
|
12
|
+
PThread: PThread;
|
|
13
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface FileBlockStatistics {
|
|
2
|
+
/** The file reads cold */
|
|
3
|
+
file_reads_cold: number;
|
|
4
|
+
/** The file reads aheads */
|
|
5
|
+
file_reads_ahead: number;
|
|
6
|
+
/** The file reads cached */
|
|
7
|
+
file_reads_cached: number;
|
|
8
|
+
/** The file writes */
|
|
9
|
+
file_writes: number;
|
|
10
|
+
/** The page accesses */
|
|
11
|
+
page_accesses: number;
|
|
12
|
+
/** The page loads */
|
|
13
|
+
page_loads: number;
|
|
14
|
+
}
|
|
15
|
+
/** The file block statistics */
|
|
16
|
+
export declare class FileStatistics {
|
|
17
|
+
/** The cold file reads */
|
|
18
|
+
totalFileReadsCold: number;
|
|
19
|
+
/** The file readaheads */
|
|
20
|
+
totalFileReadsAhead: number;
|
|
21
|
+
/** The cached file reads */
|
|
22
|
+
totalFileReadsCached: number;
|
|
23
|
+
/** The file writes */
|
|
24
|
+
totalFileWrites: number;
|
|
25
|
+
/** The page accesses */
|
|
26
|
+
totalPageAccesses: number;
|
|
27
|
+
/** The page loads */
|
|
28
|
+
totalPageLoads: number;
|
|
29
|
+
/** The blocks */
|
|
30
|
+
blockSize: number;
|
|
31
|
+
/** The blocks */
|
|
32
|
+
blockStats: Uint8Array;
|
|
33
|
+
constructor(u8array: Uint8Array);
|
|
34
|
+
/** The block stats */
|
|
35
|
+
getBlockStats(index: number, out?: FileBlockStatistics): FileBlockStatistics;
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './bindings_interface.js';
|
|
2
|
+
export * from './bindings_base.js';
|
|
3
|
+
export * from './config.js';
|
|
4
|
+
export * from './connection.js';
|
|
5
|
+
export * from './duckdb_module.js';
|
|
6
|
+
export * from './file_stats.js';
|
|
7
|
+
export * from './runtime.js';
|
|
8
|
+
export * from './insert_options.js';
|
|
9
|
+
export * from './progress.js';
|
|
10
|
+
export * from './tokens.js';
|
|
11
|
+
export * from './web_file.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SQLField } from '../sql_field';
|
|
2
|
+
export declare enum JSONTableShape {
|
|
3
|
+
ROW_ARRAY = "row-array",
|
|
4
|
+
COLUMN_OBJECT = "column-object"
|
|
5
|
+
}
|
|
6
|
+
export interface JSONInsertOptions {
|
|
7
|
+
name: string;
|
|
8
|
+
schema?: string;
|
|
9
|
+
create?: boolean;
|
|
10
|
+
shape?: JSONTableShape;
|
|
11
|
+
columns?: SQLField[];
|
|
12
|
+
}
|
|
13
|
+
export interface CSVInsertOptions {
|
|
14
|
+
name: string;
|
|
15
|
+
schema?: string;
|
|
16
|
+
create?: boolean;
|
|
17
|
+
header?: boolean;
|
|
18
|
+
delimiter?: string;
|
|
19
|
+
quote?: string;
|
|
20
|
+
escape?: string;
|
|
21
|
+
skip?: number;
|
|
22
|
+
detect?: boolean;
|
|
23
|
+
dateFormat?: string;
|
|
24
|
+
timestampFormat?: string;
|
|
25
|
+
columns?: SQLField[];
|
|
26
|
+
}
|
|
27
|
+
export interface ArrowInsertOptions {
|
|
28
|
+
name: string;
|
|
29
|
+
schema?: string;
|
|
30
|
+
create?: boolean;
|
|
31
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** An instantiation progress */
|
|
2
|
+
export interface InstantiationProgress {
|
|
3
|
+
startedAt: Date;
|
|
4
|
+
updatedAt: Date;
|
|
5
|
+
bytesTotal: number;
|
|
6
|
+
bytesLoaded: number;
|
|
7
|
+
}
|
|
8
|
+
/** An instantiation progress handler */
|
|
9
|
+
export type InstantiationProgressHandler = (p: InstantiationProgress) => void;
|