import ( "github.com/cockroachdb/cockroach/storage/engine" ) func main() { // Open a new RocksDB-backed database at "/var/lib/cockroach/data" opts := engine.RocksDBOptions{ Dir: "/var/lib/cockroach/data", } db, err := engine.NewRocksDB(opts) if err != nil { panic(err) } defer db.Close() }
import ( "github.com/cockroachdb/cockroach/storage/engine" ) func main() { // Open a database db := engine.NewInMem() defer db.Close() // Write a key-value pair err := db.Put([]byte("key"), []byte("value")) if err != nil { panic(err) } }
import ( "fmt" "github.com/cockroachdb/cockroach/storage/engine" ) func main() { // Open a database db := engine.NewInMem() defer db.Close() // Write a key-value pair err := db.Put([]byte("key"), []byte("value")) if err != nil { panic(err) } // Read the value for the key val, err := db.Get([]byte("key")) if err != nil { panic(err) } fmt.Printf("Value for key 'key' is '%s'\n", string(val)) }This example shows how to read a value from the database using the in-memory backend. In summary, the "github.com/cockroachdb/cockroach/storage/engine" package library in Go contains the Engine type, which is used to provide a key-value store for CockroachDB. The examples shown above demonstrate how to create and interact with a database using the Engine type.