mirror of
https://github.com/gofiber/storage.git
synced 2025-10-17 22:21:37 +08:00
id, title
id | title |
---|---|
surrealdb | SurrealDB |
Table of Contents
Signatures
func New(config ...Config) (*Storage, error)
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",
})
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
}
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",
}