|
| 1 | +# ZDB Module |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +Package zdb provides a Go client for interacting with [0-DB](https://github.com/threefoldtech/0-DB), which is an efficient key-value store. |
| 6 | +The package offers a simple API for creating, managing, and inspecting 0-DB namespaces abstracting manual Redis commands, in order to control namespace size limits, running modes, passwords, and public visibility. |
| 7 | + |
| 8 | + |
| 9 | +## Interface |
| 10 | + |
| 11 | +A namespace is a complete set of key/data. Each namespace can be optionally protected by a password and size limited. |
| 12 | +You are always attached to a namespace, by default, it's namespace `default`. |
| 13 | +```go |
| 14 | +type Namespace struct { |
| 15 | + Name string `yaml:"name"` // The namespace name |
| 16 | + DataLimit gridtypes.Unit `yaml:"data_limits_bytes"` // Maximum data size in bytes |
| 17 | + DataDiskFreespace gridtypes.Unit `yaml:"data_disk_freespace_bytes"`// Disk space available in bytes |
| 18 | + Mode string `yaml:"mode"` // Running mode (user or seq) |
| 19 | + PasswordProtected bool `yaml:"password"` // Whether password protection is enabled |
| 20 | + Public bool `yaml:"public"` // Whether the namespace is public |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +The zdb package exposes a `Client` interface that defines all 0-DB operations, including creating a 0-DB connection, managing namespaces, configuration, and retrieving database size. |
| 25 | + |
| 26 | +```go |
| 27 | +type Client interface { |
| 28 | + // Connect creates the connection pool and verifies connectivity by pinging the 0-DB server. |
| 29 | + Connect() error |
| 30 | + |
| 31 | + // Close releases the resources used by the client. |
| 32 | + Close() error |
| 33 | + |
| 34 | + // CreateNamespace creates a new namespace. Only admin can do this. |
| 35 | + // By default, a namespace is not password protected, is public and not size limited. |
| 36 | + CreateNamespace(name string) error |
| 37 | + |
| 38 | + // Exist checks if namespace exists |
| 39 | + Exist(name string) (bool, error) |
| 40 | + |
| 41 | + // DeleteNamespace deletes a namespace. Only admin can do this. |
| 42 | + // You can't remove the namespace you're currently using. |
| 43 | + // Any other clients using this namespace will be moved to a special state, awaiting to be disconnected. |
| 44 | + DeleteNamespace(name string) error |
| 45 | + |
| 46 | + // Namespaces returns a slice of all available namespaces name. |
| 47 | + Namespaces() ([]string, error) |
| 48 | + |
| 49 | + // Namespace retrieves returns basic informations about a specific namespace |
| 50 | + Namespace(name string) (Namespace, error) |
| 51 | + |
| 52 | + // NamespaceSetSize sets the maximum size in bytes, of the namespace's data set |
| 53 | + NamespaceSetSize(name string, size uint64) error |
| 54 | + |
| 55 | + // NamespaceSetPassword locks the namespace by a password, use * password to clear it |
| 56 | + NamespaceSetPassword(name, password string) error |
| 57 | + |
| 58 | + // NamespaceSetMode sets the mode of the namespace |
| 59 | + NamespaceSetMode(name, mode string) error |
| 60 | + |
| 61 | + // NamespaceSetPublic changes the public flag, a public namespace can be read-only if a password is set |
| 62 | + NamespaceSetPublic(name string, public bool) error |
| 63 | + |
| 64 | + // NamespaceSetLock set namespace in read-write protected or normal mode (0 or 1) |
| 65 | + NamespaceSetLock(name string, lock bool) error |
| 66 | + |
| 67 | + // DBSize returns the size of the database in bytes |
| 68 | + DBSize() (uint64, error) |
| 69 | +} |
| 70 | +``` |
| 71 | + |
0 commit comments