Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database uint32
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/database" "github.com/taubyte/go-sdk/database" "github.com/taubyte/go-sdk/event" ) var ( testId = uint32(5) testName = "someDatabase" testData = map[string][]byte{} ) func databaseFunction(e event.Event) uint32 { db, err := database.New(testName) if err != nil { return 1 } err = db.Put("value/hello", []byte("Hello, world")) if err != nil { return 1 } err = db.Put("value/hello2", []byte("Hello, world")) if err != nil { return 1 } keys, err := db.List("value") if len(keys) != 2 || err != nil { return 1 } data, err := db.Get("value/hello") if err != nil { return 1 } if string(data) != "Hello, world" { return 1 } err = db.Delete("value/hello") if err != nil { return 1 } data, err = db.Get("value/hello") if err == nil { return 1 } err = db.Close() if err != nil { return 1 } return 0 } func main() { // Mocking the calls to the vm for usage in tests and playground symbols.Mock(testId, testName, testData) e := databaseFunction(event.Event(1)) if e != 0 { fmt.Println(e) return } fmt.Println("Success") }
Output: Success
func New ¶
New creates a new database Returns a database and error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/database" "github.com/taubyte/go-sdk/database" ) func main() { // Mocking the calls to the vm for usage in tests and playground testName := "someDatabase" symbols.MockNew(16, testName) db, err := database.New(testName) if err != nil { return } fmt.Println(db) }
Output: 16
func (Database) Close ¶
Close closes the database Returns an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/database" "github.com/taubyte/go-sdk/database" ) func main() { // Mocking the calls to the vm for usage in tests and playground testId := uint32(3) symbols.MockClose(testId) err := database.Database(testId).Close() fmt.Println(err) }
Output: <nil>
func (Database) Delete ¶
Delete removes an entry from the database Returns an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/database" "github.com/taubyte/go-sdk/database" ) func main() { // Mocking the calls to the vm for usage in tests and playground testId := uint32(5) testKey := "someKey" symbols.MockDelete(testId, testKey, map[string][]byte{}) err := database.Database(testId).Delete(testKey) fmt.Println(err) }
Output: <nil>
func (Database) Get ¶
Get retrieves the given key from the database. Returns the data of the key and an error.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/database" "github.com/taubyte/go-sdk/database" ) func main() { // Mocking the calls to the vm for usage in tests and playground testId := uint32(5) testKey := "someKey" testData := map[string][]byte{ testKey: []byte("Hello, world!"), } symbols.MockGet(testId, testData) data, err := database.Database(testId).Get(testKey) if err != nil { return } fmt.Println(string(data)) }
Output: Hello, world!
func (Database) List ¶
List uses the prefix given to get a list of keys that use the prefix in the database Returns all keys found and an error
Example ¶
package main import ( "fmt" "reflect" "sort" symbols "github.com/taubyte/go-sdk-symbols/database" "github.com/taubyte/go-sdk/database" ) func main() { // Mocking the calls to the vm for usage in tests and playground testId := uint32(5) testKey := "someKey" testData := map[string][]byte{ testKey + "/a": {}, testKey + "/bb": {}, testKey + "/cccd": {}, } symbols.MockList(testId, testKey, testData) data, err := database.Database(testId).List(testKey) if err != nil { return } expected := []string{"someKey/a", "someKey/bb", "someKey/cccd"} sort.Strings(expected) sort.Strings(data) if reflect.DeepEqual(data, expected) == false { return } fmt.Println("Success") }
Output: Success
func (Database) Put ¶
Put writes the key and data into the database. Returns an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/database" "github.com/taubyte/go-sdk/database" ) func main() { // Mocking the calls to the vm for usage in tests and playground testId := uint32(18) testPut := map[string][]byte{} symbols.MockPut(testId, testPut) testKey := "someKey" err := database.Database(testId).Put(testKey, []byte("Hello, world")) if err != nil { return } fmt.Println(string(testPut[testKey])) }
Output: Hello, world
type DatabaseData ¶
type DatabaseData struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.