https://github.com/pantopic/wazero-lmdb
Access LMDB from WASM modules
https://github.com/pantopic/wazero-lmdb
go golang lmdb wasm wazero
Last synced: 2 months ago
JSON representation
Access LMDB from WASM modules
- Host: GitHub
- URL: https://github.com/pantopic/wazero-lmdb
- Owner: pantopic
- License: apache-2.0
- Created: 2025-06-17T05:23:06.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-07-03T03:01:39.000Z (3 months ago)
- Last Synced: 2025-07-03T04:19:17.323Z (3 months ago)
- Topics: go, golang, lmdb, wasm, wazero
- Language: Go
- Homepage:
- Size: 131 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Wazero LMDB
A [wazero](https://pkg.go.dev/github.com/tetratelabs/wazero) host module, ABI and guest SDK providing [LMDB](https://pkg.go.dev/github.com/PowerDNS/lmdb-go/lmdb) for WASI modules.
## Host Module
[](https://godoc.org/github.com/pantopic/wazero-lmdb/host)
[](https://goreportcard.com/report/github.com/pantopic/wazero-lmdb/host)
[](https://raw.githack.com/wiki/pantopic/wazero-lmdb/host/coverage.html)First register the host module with the runtime
```go
import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1""github.com/pantopic/wazero-lmdb/host"
)func main() {
ctx := context.Background()
r := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfig())
wasi_snapshot_preview1.MustInstantiate(ctx, r)module := wazero_lmdb.New()
module.Register(ctx, r)// ...
}
```## Guest SDK (Go)
[](https://godoc.org/github.com/pantopic/wazero-lmdb/lmdb-go)
[](https://goreportcard.com/report/github.com/pantopic/wazero-lmdb/lmdb-go)Then you can import the guest SDK into your WASI module to create and manage LMDB environments from WASM.
```go
package mainimport (
"unsafe""github.com/pantopic/wazero-lmdb/lmdb-go"
)func main() {}
//export set
func set() {
lmdb.Update(func(txn *lmdb.Txn) error {
dbi, _ := txn.DbCreate("test")
return txn.Put(dbi, []byte(`hello`), []byte(`world`))
})
}//export get
func get() uint64 {
var val []byte
lmdb.View(func(txn *lmdb.Txn) (err error) {
dbi, _ := txn.DbOpen("test")
val, err = txn.Get(dbi, []byte(`hello`))
return
})
return uint64(uintptr(unsafe.Pointer(&val[0])))<<32 + uint64(len(val))
}
```The [guest SDK](https://pkg.go.dev/github.com/pantopic/wazero-lmdb/lmdb) has no dependencies outside the Go std lib.
The [ABI](lmdb/abi.go) is ~130 lines of code and the [SDK](lmdb/sdk.go) is ~400 lines of code so it should be simple
to port this guest SDK if you want to use the Host Module from WASM modules written in other guest languages
(i.e. Rust). Contributions welcome.Wazero prides itself on having no dependencies and neither does [lmdb-go](https://pkg.go.dev/github.com/PowerDNS/lmdb-go/lmdb)
(apart from CGO), so your [go.sum](go.sum) should remain tidy.## Roadmap
This project is in alpha. Breaking API changes should be expected until Beta.
- `v0.0.x` - Alpha
- [ ] Stabilize API
- `v0.x.x` - Beta
- [ ] Finalize API
- [ ] Test in production
- `v1.x.x` - General Availability
- [ ] Proven long term stability in production