wazero_lmdb

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

Wazero LMDB

A wazero host module, ABI and guest SDK providing LMDB for WASI modules.

Go Reference License Go Report Card Go Coverage

First register the host module with the runtime

import (
	"github.com/pantopic/wazero-lmdb"
	"github.com/tetratelabs/wazero"
	"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)

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)

	// ...
}

Then you can import the guest SDK into your WASI module to create and manage LMDB environments from WASM.

package main

import (
	"unsafe"

	"github.com/pantopic/wazero-lmdb/lmdb"
)

func main() {}

//export set
func set() {
	lmdb.Open("test", lmdb.Create).Update(func(txn *lmdb.Txn) error {
		txn.Put(txn.DbOpen("dbname", lmdb.Create), []byte(`hello`), []byte(`world`))
		return nil
	})
}

//export get
func get() uint64 {
	var val []byte
	lmdb.Open("test").View(func(txn *lmdb.Txn) {
		val = txn.Get(txn.DbOpen("dbname"), []byte(`hello`))
	})
	return uint64(uintptr(unsafe.Pointer(&val[0])))<<32 + uint64(len(val))
}

The guest SDK has no dependencies outside the Go std lib. The ABI is ~130 lines of code and the SDK is ~200 lines of code so it should be simple to port this guest SDK if you want to use use this Host Module in other guest languages (i.e. Rust). Contributions welcome.

Wazero prides itself on having no dependencies and neither does lmdb-go so your 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

License

Licensed under Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCtxKeyMeta = `module_lmdb_meta`
	DefaultCtxKeyPath = `tenant_lmdb_path`
)

Functions

func New

func New(opts ...Option) *module

Types

type Errno added in v0.0.4

type Errno uint32
const (
	None Errno = iota
	KeyExist
	NotFound
	PageNotFound
	Corrupted
	Panic
	VersionMismatch
	Invalid
	MapFull
	DBsFull
	ReadersFull
	TLSFull
	TxnFull
	CursorFull
	PageFull
	MapResized
	Incompatible
	BadRSlot
	BadTxn
	BadValSize
	BadDBI
	Exist
	NotExist
	Permission
	Unknown
)

type Option

type Option func(*module)

func WithCtxKeyMeta

func WithCtxKeyMeta(key string) Option

func WithCtxKeyPath added in v0.0.2

func WithCtxKeyPath(key string) Option

Directories

Path Synopsis
host module
lmdb module
lmdb-go module
sdk-go module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL