surrealdb

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 6 Imported by: 34

README

surrealdb.go

The official SurrealDB library for Golang.

Go Reference

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidResponse = errors.New("invalid SurrealDB response") //nolint:stylecheck
	ErrQuery        = errors.New("error occurred processing the SurrealDB query")
	ErrNoRow        = errors.New("error no row")
)
View Source
var (
	ErrNotStruct    = errors.New("data is not struct")
	ErrNotValidFunc = errors.New("invalid function")
)

Smart Marshal Errors

Functions

func SmartMarshal added in v0.2.0

func SmartMarshal[I any](inputfunc interface{}, data I) (output interface{}, err error)

SmartUnmarshal can be used with all DB methods with generics and type safety. This handles errors and can use any struct tag with `BaseModel` type. Warning: "ID" field is case sensitive and expect string. Upon failure, the following will happen 1. If there are some ID on struct it will fill the table with the ID 2. If there are struct tags of the type `Basemodel`, it will use those values instead 3. If everything above fails or the IDs do not exist, SmartUnmarshal will use the struct name as the table name.

func SmartUnmarshal added in v0.2.0

func SmartUnmarshal[I any](respond interface{}, wrapperError error) (data I, err error)

SmartUnmarshal using generics for return desired type. Supports both raw and normal queries.

func Unmarshal added in v0.2.0

func Unmarshal(data, v interface{}) error

Unmarshal loads a SurrealDB response into a struct.

func UnmarshalRaw added in v0.2.0

func UnmarshalRaw(rawData, v interface{}) (ok bool, err error)

UnmarshalRaw loads a raw SurrealQL response returned by Query into a struct. Queries that return with results will return ok = true, and queries that return with no results will return ok = false.

Types

type Basemodel added in v0.2.0

type Basemodel struct{}

Used for define table name, it has no value.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB is a client for the SurrealDB database that holds are websocket connection.

func New

func New(url string, options ...Option) (*DB, error)

New creates a new SurrealDB client.

func (*DB) Authenticate

func (db *DB) Authenticate(token string) (interface{}, error)

func (*DB) Change

func (db *DB) Change(what string, data interface{}) (interface{}, error)

Change a table or record in the database like a PATCH request.

func (*DB) Close

func (db *DB) Close()

Close closes the underlying WebSocket connection.

func (*DB) Create

func (db *DB) Create(thing string, data interface{}) (interface{}, error)

Creates a table or record in the database like a POST request.

func (*DB) Delete

func (db *DB) Delete(what string) (interface{}, error)

Delete a table or a row from the database like a DELETE request.

func (*DB) Info

func (db *DB) Info() (interface{}, error)

func (*DB) Invalidate

func (db *DB) Invalidate() (interface{}, error)

func (*DB) Kill

func (db *DB) Kill(query string) (interface{}, error)

func (*DB) Let

func (db *DB) Let(key string, val interface{}) (interface{}, error)

func (*DB) Live

func (db *DB) Live(table string) (interface{}, error)

func (*DB) Modify

func (db *DB) Modify(what string, data []Patch) (interface{}, error)

Modify applies a series of JSONPatches to a table or record.

func (*DB) Query

func (db *DB) Query(sql string, vars interface{}) (interface{}, error)

Query is a convenient method for sending a query to the database.

func (*DB) Select

func (db *DB) Select(what string) (interface{}, error)

Select a table or record from the database.

func (*DB) Signin

func (db *DB) Signin(vars interface{}) (interface{}, error)

Signin is a helper method for signing in a user.

func (*DB) Signup

func (db *DB) Signup(vars interface{}) (interface{}, error)

Signup is a helper method for signing up a new user.

func (*DB) Update

func (db *DB) Update(what string, data interface{}) (interface{}, error)

Update a table or record in the database like a PUT request.

func (*DB) Use

func (db *DB) Use(ns, database string) (interface{}, error)

Use is a method to select the namespace and table to use.

type Option added in v0.2.1

type Option struct {
	WsOption websocket.Option
}

Option is a struct that holds options for the SurrealDB client.

func UseWriteCompression added in v0.2.1

func UseWriteCompression(useWriteCompression bool) Option

UseWriteCompression enables or disables write compression for internal websocket client

func WithTimeout added in v0.2.1

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for requests, default timeout is 30 seconds

type Patch added in v0.2.0

type Patch struct {
	Op    string `json:"op"`
	Path  string `json:"path"`
	Value any    `json:"value"`
}

Patch represents a patch object set to MODIFY a record

type RawQuery added in v0.2.0

type RawQuery[I any] struct {
	Status string `json:"status"`
	Time   string `json:"time"`
	Result I      `json:"result"`
	Detail string `json:"detail"`
}

Used for RawQuery Unmarshaling

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL