github.com/zuoyebang/bitalostable@v1.0.1-0.20240229032404-e3b99a834294/example_test.go (about)

     1  // Copyright 2020 The LevelDB-Go and Pebble and Bitalostored Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package bitalostable_test
     6  
     7  import (
     8  	"fmt"
     9  	"log"
    10  
    11  	"github.com/zuoyebang/bitalostable"
    12  	"github.com/zuoyebang/bitalostable/vfs"
    13  )
    14  
    15  func Example() {
    16  	db, err := bitalostable.Open("", &bitalostable.Options{FS: vfs.NewMem()})
    17  	if err != nil {
    18  		log.Fatal(err)
    19  	}
    20  	key := []byte("hello")
    21  	if err := db.Set(key, []byte("world"), bitalostable.Sync); err != nil {
    22  		log.Fatal(err)
    23  	}
    24  	value, closer, err := db.Get(key)
    25  	if err != nil {
    26  		log.Fatal(err)
    27  	}
    28  	fmt.Printf("%s %s\n", key, value)
    29  	if err := closer.Close(); err != nil {
    30  		log.Fatal(err)
    31  	}
    32  	if err := db.Close(); err != nil {
    33  		log.Fatal(err)
    34  	}
    35  	// Output:
    36  	// hello world
    37  }