surrealdb

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

surrealdb.go

The official SurrealDB library for Golang.

Go Reference

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoResult          = errors.New("query returned no results")
	ErrTooFewContainers  = errors.New("a result has no container to unmarshal into")
	ErrTooManyContainers = errors.New("there were not enough results to fill the provided containers")
)

Functions

func ChangeAs added in v1.0.6

func ChangeAs[T any](ctx *context.Context, db *DB, what string, data any) (*T, error)

func CreateAs added in v1.0.6

func CreateAs[T any](ctx *context.Context, db *DB, thing string, data any) (*T, error)

func ModifyAs added in v1.0.6

func ModifyAs[T any](ctx *context.Context, db *DB, what string, data []Patch) (*T, error)

func QueryAs added in v1.0.6

func QueryAs[T any](ctx *context.Context, db *DB, sql string, vars any) (*T, error)

func SelectAs added in v1.0.6

func SelectAs[T any](ctx *context.Context, db *DB, what string) (*T, error)

func UpdateAs added in v1.0.6

func UpdateAs[T any](ctx *context.Context, db *DB, what string, data any) (*T, error)

Types

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(ctx *context.Context, url string) (*DB, error)

New Creates a new DB instance given a WebSocket URL.

func (*DB) Authenticate

func (db *DB) Authenticate(ctx *context.Context, token string) error

func (*DB) Change

func (db *DB) Change(ctx *context.Context, what string, data interface{}) *SurrealWSResult

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

func (*DB) Close

func (db *DB) Close() error

Close closes the underlying WebSocket connection.

func (*DB) Create

func (db *DB) Create(ctx *context.Context, thing string, data interface{}) *SurrealWSResult

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

func (*DB) Delete

func (db *DB) Delete(ctx *context.Context, what string) error

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

func (*DB) Info

func (db *DB) Info(ctx *context.Context) error

func (*DB) Invalidate

func (db *DB) Invalidate(ctx *context.Context) error

func (*DB) Kill

func (db *DB) Kill(ctx *context.Context, query string) error

func (*DB) Let

func (db *DB) Let(ctx *context.Context, key string, val interface{}) error

func (*DB) Live

func (db *DB) Live(ctx *context.Context, table string) error

func (*DB) Modify

func (db *DB) Modify(ctx *context.Context, what string, data []Patch) *SurrealWSResult

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

func (*DB) Query

func (db *DB) Query(ctx *context.Context, sql string, vars interface{}) *SurrealWSRawResult

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

func (*DB) Select

func (db *DB) Select(ctx *context.Context, what string) *SurrealWSResult

Select a table or record from the database.

func (*DB) Signin

func (db *DB) Signin(ctx *context.Context, vars UserInfo) error

Signin is a helper method for signing in a user.

func (*DB) Signup

func (db *DB) Signup(ctx *context.Context, vars interface{}) error

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

func (*DB) Update

func (db *DB) Update(ctx *context.Context, what string, data interface{}) *SurrealWSResult

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

func (*DB) Use

func (db *DB) Use(ctx *context.Context, ns string, dbname string) error

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

type ErrFailedRawQuery added in v1.0.6

type ErrFailedRawQuery struct {
	Cause error
}

func (ErrFailedRawQuery) Error added in v1.0.6

func (e ErrFailedRawQuery) Error() string

type ErrFailedUnmarshal added in v1.0.6

type ErrFailedUnmarshal struct {
	Cause error
}

func (ErrFailedUnmarshal) Error added in v1.0.6

func (e ErrFailedUnmarshal) Error() string

type ErrInvalidSurrealResponse added in v1.0.6

type ErrInvalidSurrealResponse struct {
	Cause error
}

func (ErrInvalidSurrealResponse) Error added in v1.0.6

type MultiQueryError added in v1.0.6

type MultiQueryError struct {
	QueryNumber int
	Error       error
}

type Patch added in v1.0.6

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

Patch represents a patch object set to MODIFY a record

type RPCError

type RPCError struct {
	Code    int    `json:"code" msgpack:"code"`
	Message string `json:"message,omitempty" msgpack:"message,omitempty"`
}

RPCError represents a JSON-RPC error

func (*RPCError) Error

func (r *RPCError) Error() string

type RPCNotification

type RPCNotification struct {
	ID     interface{}   `json:"id" msgpack:"id"`
	Method string        `json:"method,omitempty" msgpack:"method,omitempty"`
	Params []interface{} `json:"params,omitempty" msgpack:"params,omitempty"`
}

RPCNotification represents an outgoing JSON-RPC notification

type RPCRequest

type RPCRequest struct {
	ID     interface{}   `json:"id" msgpack:"id"`
	Async  bool          `json:"async,omitempty" msgpack:"async,omitempty"`
	Method string        `json:"method,omitempty" msgpack:"method,omitempty"`
	Params []interface{} `json:"params,omitempty" msgpack:"params,omitempty"`
}

RPCRequest represents an incoming JSON-RPC request

type RPCResponse

type RPCResponse struct {
	ID     interface{} `json:"id" msgpack:"id"`
	Error  *RPCError   `json:"error,omitempty" msgpack:"error,omitempty"`
	Result interface{} `json:"result,omitempty" msgpack:"result,omitempty"`
}

RPCResponse represents an outgoing JSON-RPC response

type RawRPCResponse added in v1.0.6

type RawRPCResponse struct {
	ID     string
	Result []byte
}

RawRPCResponse represents an outgoing JSON-RPC response

type SurrealWSRawResult added in v1.0.6

type SurrealWSRawResult struct {
	Result []byte
	Error  error
}

func (SurrealWSRawResult) String added in v1.0.6

func (r SurrealWSRawResult) String() string

func (*SurrealWSRawResult) Unmarshal added in v1.0.6

func (r *SurrealWSRawResult) Unmarshal(v interface{}) error

Unmarshal unmarshals a single response returned by a raw query

func (*SurrealWSRawResult) UnmarshalMultiQuery added in v1.0.6

func (r *SurrealWSRawResult) UnmarshalMultiQuery(v ...interface{}) []MultiQueryError

UnmarshalMultiQuery unmarshals the response returned by queries sent in bulk into the provided containers.

type SurrealWSResult added in v1.0.6

type SurrealWSResult struct {
	Result        []byte
	SingleRequest bool
	Error         error
}

func (SurrealWSResult) String added in v1.0.6

func (r SurrealWSResult) String() string

func (*SurrealWSResult) Unmarshal added in v1.0.6

func (r *SurrealWSResult) Unmarshal(v interface{}) error

type UserInfo added in v1.0.6

type UserInfo struct {
	User     string `json:"user"`
	Password string `json:"pass"`
}

type WS

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

func NewWebsocket

func NewWebsocket(ctx *context.Context, url string) (*WS, error)

func (*WS) Close

func (ws *WS) Close() error

func (*WS) Once

func (ws *WS) Once(id, _ string) <-chan responseValue

Once subscribes to once()

func (*WS) Send

func (ws *WS) Send(id string, method string, params []interface{})

func (*WS) When

func (ws *WS) When(id, _ string) <-chan responseValue

When subscribes to when()

Jump to

Keyboard shortcuts

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