Ejemplo n.º 1
0
func Example() {
	// The examples below show how to set up all the codecs shipped with Storm.
	// Proper error handling left out to make it simple.
	var gobDb, _ = storm.Open("gob.db", storm.Codec(gob.Codec))
	var jsonDb, _ = storm.Open("json.db", storm.Codec(json.Codec))
	var serealDb, _ = storm.Open("sereal.db", storm.Codec(sereal.Codec))
	var protobufDb, _ = storm.Open("protobuf.db", storm.Codec(protobuf.Codec))

	fmt.Printf("%T\n", gobDb.Codec())
	fmt.Printf("%T\n", jsonDb.Codec())
	fmt.Printf("%T\n", serealDb.Codec())
	fmt.Printf("%T\n", protobufDb.Codec())

	// Output:
	// *gob.gobCodec
	// *json.jsonCodec
	// *sereal.serealCodec
	// *protobuf.protobufCodec
}
Ejemplo n.º 2
0
func TestGetSet(t *testing.T) {
	dir, _ := ioutil.TempDir(os.TempDir(), "storm")
	defer os.RemoveAll(dir)
	db, _ := storm.Open(filepath.Join(dir, "storm.db"), storm.Codec(Codec))
	err := db.Set("bucket", "key", "value")
	assert.NoError(t, err)
	var s string
	err = db.Get("bucket", "key", &s)
	assert.NoError(t, err)
	assert.Equal(t, "value", s)
}
Ejemplo n.º 3
0
func TestSave(t *testing.T) {
	dir, _ := ioutil.TempDir(os.TempDir(), "storm")
	defer os.RemoveAll(dir)
	db, _ := storm.Open(filepath.Join(dir, "storm.db"), storm.Codec(Codec))
	u1 := SimpleUser{Id: 1, Name: "John"}
	err := db.Save(&u1)
	assert.NoError(t, err)
	u2 := SimpleUser{}
	err = db.One("Id", uint64(1), &u2)
	assert.NoError(t, err)
	assert.Equal(t, u2.Name, u1.Name)
}