企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## [using fetch](https://sql.js.org/#/?id=using-fetch) ``` const sqlPromise = initSqlJs({ locateFile: file => `https://path/to/your/dist/folder/dist/${file}` }); const dataPromise = fetch("/path/to/database.sqlite").then(res => res.arrayBuffer()); const [SQL, buf] = await Promise.all([sqlPromise, dataPromise]) const db = new SQL.Database(new Uint8Array(buf)); ``` ## [using XMLHttpRequest](https://sql.js.org/#/?id=using-xmlhttprequest) ``` const xhr = new XMLHttpRequest(); // For example: https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite xhr.open('GET', '/path/to/database.sqlite', true); xhr.responseType = 'arraybuffer'; xhr.onload = e => { const uInt8Array = new Uint8Array(xhr.response); const db = new SQL.Database(uInt8Array); const contents = db.exec("SELECT * FROM my_table"); // contents is now [{columns:['col1','col2',...], values:[[first row], [second row], ...]}] }; xhr.send(); ```