Four variants of the same sync library (IndexedDB, NeDB, SQLite WASM, sql.js) plus a paste-bin demo app for testing multi-browser sync via shared folders. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { SQLITE3_WASM_BASE64 } from './sqlite3-wasm.ts';
|
|
import { FolderSyncDB } from '../../sqlite/src/index.ts';
|
|
import { initPasteApp } from '../shared.ts';
|
|
|
|
// Decode embedded WASM → blob URL so sqlite3InitModule loads
|
|
// without fetch(), enabling file:// usage (no server needed).
|
|
function base64ToBlob(b64: string, mime: string): Blob {
|
|
const bin = atob(b64);
|
|
const bytes = new Uint8Array(bin.length);
|
|
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
return new Blob([bytes], { type: mime });
|
|
}
|
|
|
|
const wasmBlobUrl = URL.createObjectURL(
|
|
base64ToBlob(SQLITE3_WASM_BASE64, 'application/wasm'),
|
|
);
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
try {
|
|
const db = await FolderSyncDB.open({
|
|
autoSyncIntervalMs: 3000,
|
|
sqlite3Config: {
|
|
locateFile: (path: string) =>
|
|
path.endsWith('.wasm') ? wasmBlobUrl : path,
|
|
},
|
|
});
|
|
await initPasteApp(db as any, 'sqlite');
|
|
} catch (e) {
|
|
console.error('SQLite init failed:', e);
|
|
document.body.innerHTML = `<div style="color:#e05555;padding:2rem;font-family:monospace">
|
|
SQLite init failed: ${(e as Error).message}</div>`;
|
|
}
|
|
});
|