💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[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(); ```