mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-24 03:34:18 +01:00
opfs for sync in one commit!
This commit is contained in:
34
bindings/javascript/examples/wasm/index.html
Normal file
34
bindings/javascript/examples/wasm/index.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
|
||||
</head>
|
||||
<body>
|
||||
<button id="run">Run</button>
|
||||
<script type="module">
|
||||
import { Database, opfsSetup } from "@tursodatabase/database";
|
||||
var opfs = await opfsSetup("local.db");
|
||||
console.info(opfs);
|
||||
async function consume() {
|
||||
console.info('take', opfs.take());
|
||||
setTimeout(consume, 1000);
|
||||
}
|
||||
consume();
|
||||
async function tick() {
|
||||
console.info('tick');
|
||||
setTimeout(tick, 1000);
|
||||
}
|
||||
tick();
|
||||
|
||||
async function run() {
|
||||
const db = new Database(opfs);
|
||||
console.info('inited');
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
await db.exec("CREATE TABLE IF NOT EXISTS t(x)");
|
||||
console.info('created');
|
||||
await db.exec("INSERT INTO t VALUES (1)");
|
||||
console.info('inserted');
|
||||
}
|
||||
document.getElementById("run").onclick = run;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
19
bindings/javascript/examples/wasm/package.json
Normal file
19
bindings/javascript/examples/wasm/package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "wasm",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
"vite": "^7.1.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tursodatabase/database": "../.."
|
||||
}
|
||||
}
|
||||
26
bindings/javascript/examples/wasm/vite.config.js
Normal file
26
bindings/javascript/examples/wasm/vite.config.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { defineConfig, searchForWorkspaceRoot } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
minify: false, // Set this to false to disable minification
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@tursodatabase/database-wasm32-wasi': '../../turso.wasi-browser.js'
|
||||
},
|
||||
},
|
||||
server: {
|
||||
fs: {
|
||||
allow: ['.']
|
||||
},
|
||||
headers: {
|
||||
'Cross-Origin-Opener-Policy': 'same-origin',
|
||||
'Cross-Origin-Embedder-Policy': 'require-corp',
|
||||
}
|
||||
},
|
||||
optimizeDeps: {
|
||||
exclude: [
|
||||
"@tursodatabase/database-wasm32-wasi",
|
||||
]
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user