const m=await(async()=>{const a={},e=await fetch("https://cdn.jsdelivr.net/npm/sql.js@1.10.2/dist/sql-wasm.js");return new Function("exports",await e.text())(a),a.Module({locateFile:t=>"https://cdn.jsdelivr.net/npm/sql.js@1.10.2/dist/"+t})})();class u{constructor(e){Object.defineProperties(this,{_db:{value:e}})}static async open(e){return new u(new m.Database(await o(await e)))}async query(e,t){return await d(this._db,e,t)}async queryRow(e,t){return(await this.query(e,t))[0]||null}async explain(e,t){const r=await this.query(`EXPLAIN QUERY PLAN ${e}`,t);return s("pre",{className:"observablehq--inspect"},[l(r.map(n=>n.detail).join(` `))])}async describeTables({schema:e}={}){return this.query(`SELECT NULLIF(schema, 'main') AS schema, name FROM pragma_table_list() WHERE type = 'table'${e==null?"":" AND schema = ?"} AND name NOT LIKE 'sqlite_%' ORDER BY schema, name`,e==null?[]:[e])}async describeColumns({schema:e,table:t}={}){if(t==null)throw new Error("missing table");const r=await this.query(`SELECT name, type, "notnull" FROM pragma_table_info(?${e==null?"":", ?"}) ORDER BY cid`,e==null?[t]:[t,e]);if(!r.length)throw new Error(`table not found: ${t}`);return r.map(({name:n,type:c,notnull:i})=>({name:n,type:p(c),databaseType:c,nullable:!i}))}async describe(e){const t=await(e===void 0?this.query("SELECT name FROM sqlite_master WHERE type = 'table'"):this.query("SELECT * FROM pragma_table_info(?)",[e]));if(!t.length)throw new Error("Not found");const{columns:r}=t;return s("table",{value:t},[s("thead",[s("tr",r.map(n=>s("th",[l(n)])))]),s("tbody",t.map(n=>s("tr",r.map(c=>s("td",[l(n[c])])))))])}async sql(){return this.query(...this.queryTag.apply(this,arguments))}queryTag(e,...t){return[e.join("?"),t]}}Object.defineProperty(u.prototype,"dialect",{value:"sqlite"});function p(a){switch(a){case"NULL":return"null";case"INT":case"INTEGER":case"TINYINT":case"SMALLINT":case"MEDIUMINT":case"BIGINT":case"UNSIGNED BIG INT":case"INT2":case"INT8":return"integer";case"TEXT":case"CLOB":return"string";case"REAL":case"DOUBLE":case"DOUBLE PRECISION":case"FLOAT":case"NUMERIC":return"number";case"BLOB":return"buffer";case"DATE":case"DATETIME":return"string";default:return/^(?:(?:(?:VARYING|NATIVE) )?CHARACTER|(?:N|VAR|NVAR)CHAR)\(/.test(a)?"string":/^(?:DECIMAL|NUMERIC)\(/.test(a)?"number":"other"}}function o(a){return typeof a=="string"?fetch(a).then(o):a&&typeof a.arrayBuffer=="function"?a.arrayBuffer().then(o):a instanceof ArrayBuffer?new Uint8Array(a):a}async function d(a,e,t){const[r]=await a.exec(e,t);if(!r)return[];const{columns:n,values:c}=r,i=c.map(E=>Object.fromEntries(E.map((y,f)=>[n[f],y])));return i.columns=n,i}function s(a,e,t){arguments.length===2&&(t=e,e=void 0);const r=document.createElement(a);if(e!==void 0)for(const n in e)r[n]=e[n];if(t!==void 0)for(const n of t)r.appendChild(n);return r}function l(a){return document.createTextNode(a)}export{u as SQLiteDatabaseClient,m as default};