https://github.com/web-atoms/sql-indexed-db
Simple to use Sql interface for IndexedDB
https://github.com/web-atoms/sql-indexed-db
Last synced: 4 months ago
JSON representation
Simple to use Sql interface for IndexedDB
- Host: GitHub
- URL: https://github.com/web-atoms/sql-indexed-db
- Owner: web-atoms
- License: apache-2.0
- Created: 2024-01-11T08:57:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-11T09:54:25.000Z (over 1 year ago)
- Last Synced: 2025-01-09T23:46:47.691Z (6 months ago)
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sql-Indexed-Db
Simple to use Sql interface for IndexedDB# Why
Most implementations are buggy and complicated and sql.js requires synchronous file api which is not possible without changing headers on server side. Exposing headers from server side isn't safe without understanding full consequences.# State
Development - Not Ready for Production# Design
This will contain simple API as shown below.```javascript
// there is no way to upgrade database
// new one will be recreated in case of version mismatch
const db = await SqlIndexedDb.open("db", /* version */ 2);const customers = await db.table.createTableIfNotExists("Customers", {
customerID: {
type: "bigint",
generated: "identity"
},
firstName: {
type: "string",
max: 50
},
lastName: {
type: "string",
max: 50
},
address: {
type: "string",
nullable: true
}
});await customers.createIndex("IX_Customers_By_Name", {
columns: {
firstName: "ASC",
lastName: "ASC"
},
filter: (x) => x.firstName || x.lastName
});// create
const c = await customers.insert({
firstName: "Akash",
lastName: "Kava"
});// retrieve
await customers
.where({ id: 5 }, (p) => (x) => x.customerID === p.id)
.first();// delete
await customers
.where({ id: 5 }, (p) => (x) => x.customerID === p.id)
.delete();// update
await customers
.where({ id: 5 }, (p) => (x) => x.customerID === p.id)
.update(void 0, (p) => (x) => ({ address: "no where" }));
```