v0.7.0

Quick Start: Embedded Store

Last updated


This page opens a ToriiDB data directory in-process with store.New, for programs that are the only owner of that directory.

Use the Embedded Store


When a single process owns the directory, use store.New directly. The directory argument is required; an empty path fails.
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "github.com/pardnchiu/toriidb/core/store"
  6. )
  7. func main() {
  8. torii, err := store.New("./data")
  9. if err != nil {
  10. log.Fatal(err)
  11. }
  12. defer torii.Close()
  13. fmt.Println(torii.Exec("SET greeting hello"))
  14. fmt.Println(torii.Exec("GET greeting"))
  15. }

Always call Close before exit. It waits for background vector jobs, compacts each loaded database into a new snapshot, and removes superseded generations.

中文