-
Notifications
You must be signed in to change notification settings - Fork 0
SQLite Database Bridge
Build rich, offline-first data applications using the embedded native SQLite 3 database engine and promise-based JavaScript bridge.
While browser localStorage and IndexedDB work well for small settings, complex applications require relational queries, foreign keys, transactions, and multi-gigabyte storage capacity without browser quota eviction.
WebToApp Studio Pro embeds a native SQLite 3 C-engine directly inside the host process and exposes an asynchronous, promise-based API on window.desktopApp.db:
┌────────────────────────────────────────────────────────────────────────┐
│ WebView2 JavaScript Client Context │
│ await window.desktopApp.db.query("SELECT * FROM notes") │
└───────────────────────────────────┬────────────────────────────────────┘
│ IPC Bridge (JSON-RPC)
▼
┌────────────────────────────────────────────────────────────────────────┐
│ Host Process SQLite Security Gate │
│ - Origin Isolation Check (blocks unauthorized iframes) │
│ - Path Traversal & Filename Guard (%LocalAppData%\AppName) │
│ - Dangerous PRAGMA Blocking (ATTACH, journal_mode, writable_schema)│
└───────────────────────────────────┬────────────────────────────────────┘
│ Native C# ADO.NET (Microsoft.Data.Sqlite)
▼
┌────────────────────────────────────────────────────────────────────────┐
│ Native SQLite 3 Embedded Database │
│ %LocalAppData%\<YourApp>\database.db │
└────────────────────────────────────────────────────────────────────────┘
The SQLite API is automatically injected into the global window scope when Tab 5 (SQLite Database) is enabled.
// Create tables or run modifications
await window.desktopApp.db.execute(`
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
body TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
// Insert records using parameterized queries (prevents SQL injection!)
const result = await window.desktopApp.db.execute(
"INSERT INTO notes (title, body) VALUES (?, ?)",
["My First Note", "Created completely offline with native SQLite!"]
);
console.log("Inserted ID:", result.lastInsertId);
console.log("Rows affected:", result.rowsAffected);// Query returns an array of plain JavaScript objects
const notes = await window.desktopApp.db.query(
"SELECT * FROM notes WHERE title LIKE ? ORDER BY id DESC",
["%First%"]
);
notes.forEach(note => {
console.log(`[#${note.id}] ${note.title}: ${note.body}`);
});Execute multiple SQL statements atomically. If any statement fails, the entire transaction rolls back cleanly:
await window.desktopApp.db.transaction([
{
sql: "UPDATE accounts SET balance = balance - ? WHERE id = ?",
params: [100, 1]
},
{
sql: "UPDATE accounts SET balance = balance + ? WHERE id = ?",
params: [100, 2]
},
{
sql: "INSERT INTO audit_log (action, amount) VALUES (?, ?)",
params: ["TRANSFER", 100]
}
]);-
Origin Isolation: The database bridge strictly validates the calling frame's
window.location.origin. External untrusted websites or third-party iframes cannot execute queries. -
Sandbox Path Isolation: Databases are strictly stored inside the application's isolated
%LocalAppData%\<AppName>\directory. Path traversal sequences (../, absolute paths) are blocked. -
Dangerous PRAGMA Blocking: Commands that attempt to manipulate filesystem paths or database headers (
PRAGMA journal_mode,ATTACH DATABASE,PRAGMA writable_schema) are blocked at the bridge layer.
Tab 5 in the Studio interface provides 1-click initial schema seeds:
-
Notes / Markdown Journal: Structured table with
id,title,content,tags, andtimestamps. - Key-Value Store: High-performance JSON key-value cache table with indexed keys.
- User Accounts & Roles: User authentication and settings table.
© 2026 Wildcat Studio. WebToApp Studio Pro — Official Developer Documentation & Technical Wiki.
Portal • Web Docs • Releases • Issues • ☕ Buy Me a Coffee
- 03. Windows Executable (.exe)
- 04. Web Frameworks & APIs
- 05. HTML5 Games & Audio
- 06. Icons & Icon Studio
- 07. Splash & Day/Night Mode
- 08. SQLite Database Bridge
- 09. Native OS Notifications
- 10. WordPress Companion
- 11. Deep-Linking (myapp://)
- 12. Inno Setup Wizards (.iss)
- 13. Microsoft Store (MSIX)
- 14. Android & Google Play
- 15. Ubuntu Linux Debian (.deb)
- 16. Integrated PWA Studio
- 17. Multi-Platform Build
- 18. Enterprise Security
- 19. Authenticode Code Signing
- 20. 1-Click Auto-Updater
- 21. Release Protocol & Gateway