SurrealDB
Table of Contentsβ
Signaturesβ
func New(config ...Config) *Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() *surrealdb.DB
func (s *Storage) List() ([]byte, error) {
Installationβ
SurrealDB is tested on latest two version of Golang. Make sure to initialize a Go module first if you havenβt already:
go get github.com/gofiber/storage/surrealdb
Examplesβ
Import the storage package.
import "github.com/gofiber/storage/surrealdb"
You can use the following possibilities to create a storage:
// Initialize default config
store := surrealdb.New()
// Initialize SurrealDB storage with custom config
store := surrealdb.New(Config{
ConnectionString: "ws://localhost:8000",
Namespace: "fiber_storage",
Database: "fiber_storage",
Username: "root",
Password: "root",
Access: "full",
Scope: "all",
DefaultTable: "fiber_storage",
GCInterval: time.Second * 10,
})
Configβ
type Config struct {
// The connection URL to connect to SurrealDB
ConnectionString string
// The namespace to be used in SurrealDB
Namespace string
// The database to be used within the specified namespace
Database string
// The application username to connect to SurrealDB
Username string
// The application password to connect to SurrealDB
Password string
// Optional access token or access type
Access string
// Optional scope for scoped logins (e.g., user-defined scopes)
Scope string
// The default table used to store key-value records
DefaultTable string
// Optional. Default is 10 * time.Second
GCInterval time.Duration
}
Default Configβ
// ConfigDefault is the default config
var ConfigDefault = Config{
ConnectionString: "ws://localhost:8000",
Namespace: "fiber_storage",
Database: "fiber_storage",
Username: "root",
Password: "root",
Access: "full",
Scope: "all",
DefaultTable: "fiber_storage",
GCInterval: time.Second * 10,
}