tinywasm/indexdb is an IndexedDB driver for tinywasm/orm, compiled to WebAssembly with Go. It lets you use a familiar Create, Query, ReadOne, ReadAll API directly in the browser, backed by the browser's built-in persistent storage engine — no server, no SQLite file, no extra runtime.
Why this matters: your data-access logic stays the same whether it runs on a server (with a SQL backend) or in the browser (with IndexedDB). Swap the driver, keep the code.
db := indexdb.New("my_db", idGenerator, logger, &User{}, &Product{})This single-line initialization instantly yields a fully functioning *orm.DB ready for use with the github.com/tinywasm/orm API.
package main
import (
. "github.com/tinywasm/fmt"
"github.com/tinywasm/indexdb"
"github.com/tinywasm/orm"
)
// ModelName, Schema and Pointers are auto-generated by ormc — you only write the struct.
// See: https://github.com/tinywasm/orm
type User struct {
ID string
Name string
Email string
}
func (u *User) ModelName() string { return "users" }
func (u *User) Schema() []indexdb.Field {
return []indexdb.Field{
{Name: "ID", Type: indexdb.FieldText, DB: &indexdb.FieldDB{PK: true}},
{Name: "Name", Type: indexdb.FieldText},
{Name: "Email", Type: indexdb.FieldText, DB: &indexdb.FieldDB{Unique: true}},
}
}
func (u *User) Pointers() []any { return []any{&u.ID, &u.Name, &u.Email} }
func main() {
// 1. Initialize the database
db := indexdb.New("my_app_db", idGen, nil, &User{})
// 2. Create a record
user := User{ID: "1", Name: "John Doe", Email: "john@example.com"}
err := db.Create(&user)
// 3. Query a record
var result User
err = db.Query(&result).Where("ID").Eq("1").ReadOne()
// 4. Read all records
err = db.Query(&User{}).ReadAll(
func() indexdb.Model { return &User{} },
func(m indexdb.Model) {
u := m.(*User)
indexdb.Println(u.Name)
},
)
}