skytable

package module
v0.0.0-...-5f04646 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

go-skytable

Go Reference

A Go driver of Skytable, a fast, secure and reliable realtime NoSQL database.

Status

The package implements Skyhash 1.1.

DDL actions implemented.

The interfaces may be changed anytime before first release.

Installation

go get github.com/No3371/go-skytable

Usage

Open single connection to a local Skytable instance

localAddr := &net.TCPAddr{IP: []byte{127, 0, 0, 1}, Port: int(protocol.DefaultPort)}

// Auth is disabled in the instance
c, err := skytable.NewConn(localAddr)
// or
auth := func() (u, t string) { // ⚠️ You don't really write AuthProvider like this! Never include your credential in code!
        u = "USERNAME"
        t = "TOKEN"
        return u, t
    }
c, err := skytable.NewConnAuth(localAddr, auth)

Open a connection pool to a local Skytable instance

localAddr := &net.TCPAddr{IP: []byte{127, 0, 0, 1}, Port: int(protocol.DefaultPort)}

// Auth is disabled in the instance
c := skytable.NewConnPool(localAddr, skytable.DefaultConnPoolOptions)
// or
auth := func() (u, t string) { // ⚠️ You don't really write AuthProvider like this! Never include your credential in code!
        u = "USERNAME"
        t = "TOKEN"
        return u, t
    }
c := skytable.NewConnPool(localAddr, skytable.ConnPoolOptions{
    AuthProvider: auth,
})

Set a value

err := c.Set(ctx, "KEY", "VALUE")

Get a value

resp, err := c.Get(ctx, "KEY")

Multi-actions query

p := skytable.NewQueryPacket(
    []skytable.Action{
		action.Del { Keys: []string{k} },
		action.Set { Key: k, Value: v },
		action.Get { Key: k },
})

resp, err := c.BuildAndExecQuery(p)

Progress

Mechanics

⬜ TLS ✅ DDL (Keyspaces/Tables) ✅ Auto-Reconnection

DataTypes
✅ Implemented ⬜ NotImplemented 🟪 WaitingForSkyhash
--- --- --- --- ---
✅ ResponseCode ✅ Integer ✅ SignedInteger ✅ String ✅ BinaryString
✅ Float ⬜ SmallInteger ⬜ SignedSmallInteger 🟪 Json
⬜ Array ✅ FlatArray ✅ AnyArray ✅ TypedArray ✅ TypedNonNullArray
Actions (Fully Supports Skytable 0.7.6)
✅ Implemented ⬜ NotImplemented 🟪 Partial
--- --- --- --- ---
✅ GET ✅ SET ✅ UPDATE ✅ MGET ✅ MSET
✅ DEL ✅ EXISTS ✅ HEYA ✅ USET ✅ POP
✅ MPOP ✅ MUPDATE ✅ SDEL ✅ SSET ✅ SUPDATE
✅ LMOD ✅ LGET ✅ LSET ✅ LSKEYS
✅ DBSIZE ✅ FLUSHDB ✅ KEYLEN ✅ WHEREAMI ✅ MKSNAP
✅ SYS ✅ AUTH

SkytableX

The subpackage provides opinionated extensions that could be useful or convenient.

For example, *ConnX.GetWithSimTTL(), *ConnX.SetWithSimTTL(), *ConnX.UpdateWithSimTTL() are alternative versions of their respective methods of Conn, these methods only works with []byte values and automatically add an action to maintain timestamp with key "key_timestamp".

DDL with Connection Pool

Connection Pools manage multiple connections on its own and users have no way to decide which Conn is used on method calls.

If you are working with multiple Keyspaces/Tables and you are using Connection Pool, there are 2 suggested usages:

  • Container-dedicated connection pool: Keep a connection pool for every container. By specifying default container in ConnectionPoolOptions, all the new connections spawned by the pool automatically USE it. Running USE is equal to run USE on all of the existing connections in it, and change the default container of the pool so future connections will automatically USE that.
  • USE first in every packet: This should explain itself, but it may introduce performance loss and frequent USEs are not recommended by Skytable official.

Testing

Testcases are written for local Skytable instances (@127.0.0.1), some of them use auth coonnections, some don't.

The Auth-Enabled one should be bound to 2003 (Skytable default port), while the Auth-Disabled one should be bound to 2004 (as specified in skytable_test.go).

Auth

All auth testcases use username go-skytable-test (as specified in skytable_test.go), and looks up the token by:

  1. Read the value of environment variable GO_SKYTABLE_TEST_TOKEN as the token.
  2. If step 1 failed, read a file in the repo named go-skytable-test and read the content as the token.

If the go-skytable-test user and the token are setup correctly, the auth testcases should run without issues.

Known Issues:

  • (Skytable) On Windows, executing DDL to an Auth-Enabled instance will results in auth data file loss. This has been reported and will be fixed in Skytable 0.7.6.

Documentation

Index

Constants

View Source
const DEBUG = false
View Source
const ProtoVer = "Skyhash-1.1"

Variables

View Source
var DefaultConnPoolOptions = ConnPoolOptions{
	Cap: int64(runtime.NumCPU()) * 2,
}

Functions

This section is empty.

Types

type Action

type Action interface {
	AppendToPacket(builder *strings.Builder) error
	ValidateProtocol(response interface{}) error
}

type AuthProvider

type AuthProvider func() (username, token string, err error)

type BuiltQuery

type BuiltQuery struct {
	*QueryPacket
	// contains filtered or unexported fields
}

type Conn

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

func NewConn

func NewConn(remote *net.TCPAddr) (*Conn, error)

Create a new Conn. If auth is enabled on the destination server, use NewConnAuth instead.

After connection established, the driver automatically validate Skyhash protocol version with the server, and return an error in case of mismatch.

func NewConnAuth

func NewConnAuth(remote *net.TCPAddr, authProvider AuthProvider) (*Conn, error)

Create a new Conn and “AUTH LOGIN” with the provided auth info.

After connection established, the driver automatically validate Skyhash protocol version with the server, and return an error in case of mismatch.

func (*Conn) AuthAddUser

func (c *Conn) AuthAddUser(ctx context.Context, username string) (string, error)

https://docs.skytable.io/actions/auth#adduser

func (*Conn) AuthClaim

func (c *Conn) AuthClaim(ctx context.Context, originKey string) (string, error)

https://docs.skytable.io/actions/auth#claim

func (*Conn) AuthDelUser

func (c *Conn) AuthDelUser(ctx context.Context, username string) error

https://docs.skytable.io/actions/auth#deluser

func (*Conn) AuthLogin

func (c *Conn) AuthLogin(ctx context.Context, authProvider AuthProvider) error

https://docs.skytable.io/actions/auth#login

func (*Conn) AuthRestore

func (c *Conn) AuthRestore(ctx context.Context, originKey string, username string) (string, error)

https://docs.skytable.io/actions/auth#restore

If provided `originKey` is "", it'll be omitted in the sent command

func (*Conn) BuildAndExecQuery

func (c *Conn) BuildAndExecQuery(p *QueryPacket) (*ResponsePacket, error)

func (*Conn) BuildQuery

func (c *Conn) BuildQuery(p *QueryPacket) (BuiltQuery, error)

func (*Conn) BuildSingleActionPacketRaw

func (c *Conn) BuildSingleActionPacketRaw(segs []any) (raw string, err error)

Allows building a packet easily like:

c.BuildSingleActionPacketRaw("SET", "X", 100)

The arguments accept any type. The arguments are formatted internally with %v so most basic types should be supported.

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) CreateKeyspace

func (c *Conn) CreateKeyspace(ctx context.Context, name string) error

https://docs.skytable.io/ddl/#keyspaces

func (*Conn) CreateTable

func (c *Conn) CreateTable(ctx context.Context, path string, modelDesc any) error

https://docs.skytable.io/ddl/#tables

func (*Conn) DBSize

func (c *Conn) DBSize(ctx context.Context, entity string) (size uint64, err error)

https://docs.skytable.io/actions/dbsize

func (*Conn) Del

func (c *Conn) Del(ctx context.Context, keys []string) (deleted uint64, err error)

https://docs.skytable.io/actions/del

func (*Conn) DropKeyspace

func (c *Conn) DropKeyspace(ctx context.Context, name string) error

https://docs.skytable.io/ddl/#keyspaces-1

func (*Conn) DropTable

func (c *Conn) DropTable(ctx context.Context, path string) error

https://docs.skytable.io/ddl/#tables-1

func (*Conn) EnableAutoReconnect

func (c *Conn) EnableAutoReconnect()

A Conn may closes itself when errors occured when reading/writng packets.

While all the errors are being returned and can be handled, enabling auto reconnection will save you the trouble dealing with disconnection

⚠️ This could make you unaware of issues.

func (*Conn) Err

func (c *Conn) Err() error

Err() return an error if the conn is closed due to an error

func (*Conn) Exec

func (c *Conn) Exec(packet *QueryPacket) ([]response.ResponseEntry, error)

func (*Conn) ExecQuery

func (c *Conn) ExecQuery(bq BuiltQuery) (*ResponsePacket, error)

func (*Conn) ExecRaw

func (c *Conn) ExecRaw(query string) (*RawResponsePacket, error)

func (*Conn) ExecSingleActionPacketRaw

func (c *Conn) ExecSingleActionPacketRaw(segments ...any) (response.ResponseEntry, error)

Allows executing a packet easily like:

c.ExecSingleActionPacketRaw("SET", "X", 100)

The arguments accept any type. The arguments are formatted internally with %v so most basic types should be supported.

func (*Conn) Exists

func (c *Conn) Exists(ctx context.Context, keys []string) (existing uint64, err error)

https://docs.skytable.io/actions/exists

func (*Conn) FlushDB

func (c *Conn) FlushDB(ctx context.Context, entity string) (err error)

https://docs.skytable.io/actions/flushdb

If entity is "", flush the current table

func (*Conn) GetBytes

func (c *Conn) GetBytes(ctx context.Context, key string) ([]byte, error)

GetBytes() is a strict version of [Get] that only success if the value is stored as BinaryString in Skytable.

func (*Conn) GetString

func (c *Conn) GetString(ctx context.Context, key string) (string, error)

GetString() is a strict version of [Get] that only success if the value is stored as String in Skytable.

func (*Conn) Heya

func (c *Conn) Heya(ctx context.Context, echo string) error

https://docs.skytable.io/actions/heya

The method does not return anything but the error, because the value returned by Skytable will be automatically validated.

func (*Conn) InspectKeyspace

func (c *Conn) InspectKeyspace(ctx context.Context, name string) (*protocol.TypedArray, error)

https://docs.skytable.io/ddl/#keyspaces-2

If the supplied name is "", inspect the current keyspace

func (*Conn) InspectTable

func (c *Conn) InspectTable(ctx context.Context, path string) (protocol.ModelDescription, error)

https://docs.skytable.io/ddl/#tables-2

If path is "", inspect the current table

func (*Conn) LGetLen

func (c *Conn) LGetLen(ctx context.Context, listName string) (uint64, error)

https://docs.skytable.io/actions/lget#len

func (*Conn) LGetRange

func (c *Conn) LGetRange(ctx context.Context, listName string, from uint64, to uint64) (*protocol.TypedArray, error)

https://docs.skytable.io/actions/lget#range

If provided `to` is 0, it's omitted in the sent command.

func (*Conn) LModClear

func (c *Conn) LModClear(ctx context.Context, listName string) error

https://docs.skytable.io/actions/lmod#clear

func (*Conn) LModInsert

func (c *Conn) LModInsert(ctx context.Context, listName string, index uint64, element any) error

https://docs.skytable.io/actions/lmod#insert

func (*Conn) LModPush

func (c *Conn) LModPush(ctx context.Context, listName string, elements []any) error

https://docs.skytable.io/actions/lmod#push

func (*Conn) LModRemove

func (c *Conn) LModRemove(ctx context.Context, listName string, index uint64) error

https://docs.skytable.io/actions/lmod#remove

func (*Conn) LSet

func (c *Conn) LSet(ctx context.Context, listName string, elements []any) error

https://docs.skytable.io/actions/lset

If `elements` is nil, it's omitted in the sent command.`

func (*Conn) MKSnap

func (c *Conn) MKSnap(ctx context.Context, name string) error

https://docs.skytable.io/actions/mksnap

If name is "", it will only send "MKSNAP"

func (*Conn) MSet

func (c *Conn) MSet(ctx context.Context, entries []action.KVPair) (set uint64, err error)

https://docs.skytable.io/actions/mset

This is just an alternative MSet with different signature.

func (*Conn) MSetB

func (c *Conn) MSetB(ctx context.Context, keys []string, values []any) (set uint64, err error)

https://docs.skytable.io/actions/mset

func (*Conn) MUpdate

func (c *Conn) MUpdate(ctx context.Context, entries []action.KVPair) (updated uint64, err error)

https://docs.skytable.io/actions/mupdate

func (Conn) OpenedAt

func (c Conn) OpenedAt() time.Time

func (*Conn) PopBytes

func (c *Conn) PopBytes(ctx context.Context, key string) ([]byte, error)

PopBytes() is a strict version of [Pop] that only success if the value is stored as BinaryString in Skytable.

func (*Conn) PopString

func (c *Conn) PopString(ctx context.Context, key string) (string, error)

PopString() is a strict version of [Pop] that only success if the value is stored as String in Skytable.

func (*Conn) SDel

func (c *Conn) SDel(ctx context.Context, keys []string) (err error)

https://docs.skytable.io/actions/sdel

func (*Conn) SSet

func (c *Conn) SSet(ctx context.Context, entries []action.KVPair) (err error)

https://docs.skytable.io/actions/sset

func (*Conn) SUpdate

func (c *Conn) SUpdate(ctx context.Context, entries []action.KVPair) (err error)

https://docs.skytable.io/actions/supdate

func (*Conn) Set

func (c *Conn) Set(ctx context.Context, key string, value any) error

https://docs.skytable.io/actions/set

func (*Conn) USet

func (c *Conn) USet(ctx context.Context, entries ...action.KVPair) (set uint64, err error)

https://docs.skytable.io/actions/uset

func (*Conn) Update

func (c *Conn) Update(ctx context.Context, key string, value any) error

https://docs.skytable.io/actions/update

func (*Conn) Use

func (c *Conn) Use(ctx context.Context, path string) error

https://docs.skytable.io/ddl/#use

“USE KEYSPACE” and “USE TABLE” are unified into “USE”.

func (Conn) UsedAt

func (c Conn) UsedAt() time.Time

type ConnPool

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

ConnPool manage multiple Conns automatically.

A conn will be spawned or taken from a internal queue (channel) to perform the task for most of the methods, and be queued back when done. A slow start should be expected if bursting packets with a new pool or not yet used to send a burst of packets.

Therefore, `prewarming` by spawning a burst of parallel packet-sending goroutines is viable.

func NewConnPool

func NewConnPool(remote *net.TCPAddr, opts ConnPoolOptions) *ConnPool

NewConnPool create a ConnPool that manage Conns automatically. DefaultConnPoolOptions is available for the `opts` argument.

func (*ConnPool) AuthAddUser

func (c *ConnPool) AuthAddUser(ctx context.Context, username string) (string, error)

https://docs.skytable.io/actions/auth#adduser

func (*ConnPool) AuthClaim

func (c *ConnPool) AuthClaim(ctx context.Context, originKey string) (string, error)

https://docs.skytable.io/actions/auth#claim

func (*ConnPool) AuthDelUser

func (c *ConnPool) AuthDelUser(ctx context.Context, username string) error

https://docs.skytable.io/actions/auth#deluser

func (*ConnPool) AuthLogin

func (c *ConnPool) AuthLogin(ctx context.Context, authProvider AuthProvider) error

*ConnPool.AuthLogin() will take all conns and do Conn.AuthLogin() on each, and overwrite the AuthProvider of the pool.

Noted that if there's an error, it's possible that the iteration is not completed and the connections may be using different users.

func (*ConnPool) AuthLogout

func (c *ConnPool) AuthLogout(ctx context.Context) error

*ConnPool.AuthLogin() will take all conns and do Conn.AuthLogout() on each, and overwrite the AuthProvider of the pool.

Noted that if there's an error, it's possible that the iteration is not completed and the connections may be using different users.

func (*ConnPool) AuthRestore

func (c *ConnPool) AuthRestore(ctx context.Context, originKey string, username string) (string, error)

https://docs.skytable.io/actions/auth#restore

If provided `originKey` is "", it'll be omitted in the sent command

func (*ConnPool) CreateKeyspace

func (c *ConnPool) CreateKeyspace(ctx context.Context, name string) error

https://docs.skytable.io/ddl/#keyspaces

func (*ConnPool) CreateTable

func (c *ConnPool) CreateTable(ctx context.Context, path string, modelDesc any) error

https://docs.skytable.io/ddl/#tables

func (*ConnPool) DBSize

func (c *ConnPool) DBSize(ctx context.Context, entity string) (uint64, error)

https://docs.skytable.io/actions/dbsize

func (*ConnPool) Del

func (c *ConnPool) Del(ctx context.Context, keys []string) (deleted uint64, err error)

https://docs.skytable.io/actions/del

func (*ConnPool) DoEachConn

func (c *ConnPool) DoEachConn(action func(conn *Conn) error) error

DoEachConn execute the supplied func for every conn opened before the call. If an error is returned, the iteration may be incomplete.

func (*ConnPool) DropKeyspace

func (c *ConnPool) DropKeyspace(ctx context.Context, name string) error

https://docs.skytable.io/ddl/#keyspaces-1

func (*ConnPool) DropTable

func (c *ConnPool) DropTable(ctx context.Context, path string) error

https://docs.skytable.io/ddl/#tables-1

func (*ConnPool) Exec

func (c *ConnPool) Exec(packet *QueryPacket) ([]response.ResponseEntry, error)

func (*ConnPool) ExecSingleActionPacketRaw

func (c *ConnPool) ExecSingleActionPacketRaw(segments ...any) (response.ResponseEntry, error)

func (*ConnPool) Exists

func (c *ConnPool) Exists(ctx context.Context, keys []string) (existing uint64, err error)

https://docs.skytable.io/actions/exists

func (*ConnPool) FlushDB

func (c *ConnPool) FlushDB(ctx context.Context, entity string) error

https://docs.skytable.io/actions/flushdb

If entity is "", flush the current table

func (*ConnPool) GetBytes

func (c *ConnPool) GetBytes(ctx context.Context, key string) ([]byte, error)

GetBytes() is a strict version of [Get] that only success if the value is stored as BinaryString in Skytable.

func (*ConnPool) GetString

func (c *ConnPool) GetString(ctx context.Context, key string) (string, error)

GetString() is a strict version of [Get] that only success if the value is stored as String in Skytable.

func (*ConnPool) Heya

func (c *ConnPool) Heya(ctx context.Context, echo string) (err error)

https://docs.skytable.io/actions/heya

The method does not return anything but the error, because the value returned by Skytable will be automatically validated.

func (*ConnPool) InspectKeyspace

func (c *ConnPool) InspectKeyspace(ctx context.Context, name string) (*protocol.TypedArray, error)

https://docs.skytable.io/ddl/#keyspaces-2

If the supplied name is "", inspect the current keyspace

func (*ConnPool) InspectTable

func (c *ConnPool) InspectTable(ctx context.Context, path string) (protocol.ModelDescription, error)

https://docs.skytable.io/ddl/#tables-2

If path is "", inspect the current table

func (*ConnPool) LGetLen

func (c *ConnPool) LGetLen(ctx context.Context, listName string) (uint64, error)

https://docs.skytable.io/actions/lget#len

func (*ConnPool) LGetLimit

func (c *ConnPool) LGetLimit(ctx context.Context, listName string, limit uint64) (*protocol.TypedArray, error)

https://docs.skytable.io/actions/lget#limit

func (*ConnPool) LGetRange

func (c *ConnPool) LGetRange(ctx context.Context, listName string, from uint64, to uint64) (*protocol.TypedArray, error)

https://docs.skytable.io/actions/lget#range

If provided `to` is 0, it's omitted in the sent command.

func (*ConnPool) LModClear

func (c *ConnPool) LModClear(ctx context.Context, listName string) error

https://docs.skytable.io/actions/lmod#clear

func (*ConnPool) LModInsert

func (c *ConnPool) LModInsert(ctx context.Context, listName string, index uint64, element any) error

https://docs.skytable.io/actions/lmod#insert

func (*ConnPool) LModPopIndex

func (c *ConnPool) LModPopIndex(ctx context.Context, listName string, index uint64) (response.ResponseEntry, error)

https://docs.skytable.io/actions/lmod#pop

func (*ConnPool) LModPush

func (c *ConnPool) LModPush(ctx context.Context, listName string, elements []any) error

https://docs.skytable.io/actions/lmod#push

func (*ConnPool) LModRemove

func (c *ConnPool) LModRemove(ctx context.Context, listName string, index uint64) error

https://docs.skytable.io/actions/lmod#remove

func (*ConnPool) LSKeys

func (c *ConnPool) LSKeys(ctx context.Context, entity string, limit uint64) (*protocol.TypedArray, error)

https://docs.skytable.io/actions/lskeys

func (*ConnPool) LSet

func (c *ConnPool) LSet(ctx context.Context, listName string, elements []any) error

https://docs.skytable.io/actions/lset

If `elements` is nil, it's omitted in the sent command.`

func (*ConnPool) MKSnap

func (c *ConnPool) MKSnap(ctx context.Context, name string) error

https://docs.skytable.io/actions/mksnap

If name is "", it will only send "MKSNAP"

func (*ConnPool) MSet

func (c *ConnPool) MSet(ctx context.Context, entries []action.KVPair) (set uint64, err error)

https://docs.skytable.io/actions/mset

func (*ConnPool) MSetB

func (c *ConnPool) MSetB(ctx context.Context, keys []string, values []any) (set uint64, err error)

https://docs.skytable.io/actions/mset

func (*ConnPool) MUpdate

func (c *ConnPool) MUpdate(ctx context.Context, entries []action.KVPair) (updated uint64, err error)

https://docs.skytable.io/actions/update

func (*ConnPool) OpenedConns

func (c *ConnPool) OpenedConns() int64

func (*ConnPool) Pop

func (*ConnPool) PopBytes

func (c *ConnPool) PopBytes(ctx context.Context, key string) ([]byte, error)

PopBytes() is a strict version of [Pop] that only success if the value is stored as BinaryString in Skytable.

func (*ConnPool) PopString

func (c *ConnPool) PopString(ctx context.Context, key string) (string, error)

PopString() is a strict version of [Pop] that only success if the value is stored as String in Skytable.

func (*ConnPool) RentConn

func (c *ConnPool) RentConn(dontOpenNew bool) (conn *Conn, pusher func(), err error)

Get a conn and return it back. A “pusher” func is returned to push back the conn.

conn, pusher, err := c.RentConn(false)
if err != nil {
return err
}
defer pusher ()

func (*ConnPool) SDel

func (c *ConnPool) SDel(ctx context.Context, keys []string) (err error)

https://docs.skytable.io/actions/sdel

func (*ConnPool) SSet

func (c *ConnPool) SSet(ctx context.Context, entries []action.KVPair) (err error)

https://docs.skytable.io/actions/sset

func (*ConnPool) SUpdate

func (c *ConnPool) SUpdate(ctx context.Context, entries []action.KVPair) (err error)

https://docs.skytable.io/actions/supdate

func (*ConnPool) Set

func (c *ConnPool) Set(ctx context.Context, key string, value any) error

https://docs.skytable.io/actions/set

func (*ConnPool) SysMetricHealth

func (c *ConnPool) SysMetricHealth(ctx context.Context) (bool, error)

https://docs.skytable.io/actions/sys#metric

Returns true if "good", false when "critical"

func (*ConnPool) USet

func (c *ConnPool) USet(ctx context.Context, entries ...action.KVPair) (set uint64, err error)

https://docs.skytable.io/actions/uset

func (*ConnPool) Update

func (c *ConnPool) Update(ctx context.Context, key string, value any) error

https://docs.skytable.io/actions/update

func (*ConnPool) Use

func (c *ConnPool) Use(ctx context.Context, path string) error

https://docs.skytable.io/ddl/#use

This method will take all conns and do *Conn.Use() on each, and overwrite the DefaultEntity of the pool.

Noted that if there's an error, it's possible that the iteration is not completed and the connections may be using different containers. So it's suggested to reset them by doing DDLs not likely to go wrong, like Use("default").

type ConnPoolOptions

type ConnPoolOptions struct {
	Cap           int64                                      // The maximun of opened Conns at the same time
	AuthProvider  func() (username, token string, err error) // Do not keep auth info in memory
	DefaultEntity string                                     // "KEYSPACE" or "KEYSPACE:CONTAINER"
}

type ErrComu

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

func NewComuError

func NewComuError(msg string, err error) ErrComu

func (ErrComu) Error

func (err ErrComu) Error() string

func (ErrComu) Unwrap

func (err ErrComu) Unwrap() error

type ErrInvalidUsage

type ErrInvalidUsage ErrLocal

func NewUsageError

func NewUsageError(msg string, err error) ErrInvalidUsage

func (ErrInvalidUsage) Error

func (err ErrInvalidUsage) Error() string

func (ErrInvalidUsage) Unwrap

func (err ErrInvalidUsage) Unwrap() error

type ErrLocal

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

func NewLocalError

func NewLocalError(msg string, err error) ErrLocal

func (ErrLocal) Error

func (err ErrLocal) Error() string

func (ErrLocal) Unwrap

func (err ErrLocal) Unwrap() error

type QueryPacket

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

func NewQueryPacket

func NewQueryPacket(actions []Action) *QueryPacket

func NewQueryPacketContext

func NewQueryPacketContext(ctx context.Context, actions []Action) *QueryPacket

type RawResponsePacket

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

type ResponsePacket

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

func (ResponsePacket) Resps

func (rr ResponsePacket) Resps() []response.ResponseEntry

type Skytable

type Skytable interface {
	// https://docs.skytable.io/actions/heya
	Heya(ctx context.Context, echo string) error
	// https://docs.skytable.io/actions/auth#login
	AuthLogin(ctx context.Context, authProvider AuthProvider) error
	// https://docs.skytable.io/actions/auth#logout
	AuthLogout(ctx context.Context) error
	// https://docs.skytable.io/actions/auth#claim
	AuthClaim(ctx context.Context, originKey string) (string, error)
	// https://docs.skytable.io/actions/auth#adduser
	AuthAddUser(ctx context.Context, username string) (string, error)
	// https://docs.skytable.io/actions/auth#deluser
	AuthDelUser(ctx context.Context, username string) error
	// https://docs.skytable.io/actions/auth#restore
	//
	// If provided `originKey` is "", it'll be omitted in the sent command
	AuthRestore(ctx context.Context, originKey string, username string) (string, error)
	// https://docs.skytable.io/actions/auth#listuser
	AuthListUser(ctx context.Context) (*protocol.TypedArray, error)
	// https://docs.skytable.io/actions/auth#whoami
	AuthWhoAmI(ctx context.Context) (string, error)

	// https://docs.skytable.io/actions/exists
	Exists(ctx context.Context, keys []string) (existing uint64, err error)
	// https://docs.skytable.io/actions/del
	Del(ctx context.Context, keys []string) (deleted uint64, err error)
	// https://docs.skytable.io/actions/sdel
	SDel(ctx context.Context, keys []string) error

	// https://docs.skytable.io/actions/get
	Get(ctx context.Context, key string) (response.ResponseEntry, error)
	// a strict version of [Get] that only success if the value is stored as String in Skytable.
	GetString(ctx context.Context, key string) (string, error)
	// a strict version of [Get] that only success if the value is stored as BinaryString in Skytable.
	GetBytes(ctx context.Context, key string) ([]byte, error)
	// https://docs.skytable.io/actions/mget
	MGet(ctx context.Context, keys []string) (*protocol.TypedArray, error)
	// https://docs.skytable.io/actions/pop
	Pop(ctx context.Context, key string) (response.ResponseEntry, error)
	// https://docs.skytable.io/actions/mpop
	MPop(ctx context.Context, keys []string) (*protocol.TypedArray, error)

	// https://docs.skytable.io/actions/set
	Set(ctx context.Context, key string, value any) error
	// https://docs.skytable.io/actions/mset
	MSetB(ctx context.Context, keys []string, values []any) (set uint64, err error)
	// https://docs.skytable.io/actions/mset
	MSet(ctx context.Context, entries []action.KVPair) (set uint64, err error)
	// https://docs.skytable.io/actions/sset
	SSet(ctx context.Context, entries []action.KVPair) error
	USet(ctx context.Context, entries ...action.KVPair) (set uint64, err error)

	// https://docs.skytable.io/actions/update
	Update(ctx context.Context, key string, value any) error
	// https://docs.skytable.io/actions/mupdate
	MUpdate(ctx context.Context, entries []action.KVPair) (updated uint64, err error)
	// https://docs.skytable.io/actions/supdate
	SUpdate(ctx context.Context, entries []action.KVPair) error

	// https://docs.skytable.io/actions/lget#lget
	LGet(ctx context.Context, listName string) (*protocol.TypedArray, error)
	// https://docs.skytable.io/actions/lget#limit
	LGetLimit(ctx context.Context, listName string, limit uint64) (*protocol.TypedArray, error)
	// https://docs.skytable.io/actions/lget#len
	LGetLen(ctx context.Context, listName string) (uint64, error)
	// https://docs.skytable.io/actions/lget#valueat
	LGetValueAt(ctx context.Context, listName string, index uint64) (response.ResponseEntry, error)
	// https://docs.skytable.io/actions/lget#first
	LGetFirst(ctx context.Context, listName string) (response.ResponseEntry, error)
	// https://docs.skytable.io/actions/lget#last
	LGetLast(ctx context.Context, listName string) (response.ResponseEntry, error)
	// https://docs.skytable.io/actions/lget#range
	//
	// If provided `to` is 0, it's omitted in the sent command.
	LGetRange(ctx context.Context, listName string, from uint64, to uint64) (*protocol.TypedArray, error)

	// https://docs.skytable.io/actions/lmod#push
	LModPush(ctx context.Context, listName string, elements []any) error
	// https://docs.skytable.io/actions/lmod#insert
	LModInsert(ctx context.Context, listName string, index uint64, element any) error
	// https://docs.skytable.io/actions/lmod#pop
	LModPop(ctx context.Context, listName string) (response.ResponseEntry, error)
	// https://docs.skytable.io/actions/lmod#pop
	LModPopIndex(ctx context.Context, listName string, index uint64) (response.ResponseEntry, error)
	// https://docs.skytable.io/actions/lmod#remove
	LModRemove(ctx context.Context, listName string, index uint64) error
	// https://docs.skytable.io/actions/lmod#clear
	LModClear(ctx context.Context, listName string) error

	// https://docs.skytable.io/actions/lset
	//
	// If `elements` is nil, it's omitted in the sent command.`
	LSet(ctx context.Context, listName string, elements []any) error

	Exec(packet *QueryPacket) ([]response.ResponseEntry, error)
	ExecSingleActionPacketRaw(segments ...any) (response.ResponseEntry, error)

	// https://docs.skytable.io/ddl/#use
	//
	// “USE KEYSPACE” and “USE TABLE” are unified into “USE”.
	Use(ctx context.Context, path string) error

	// https://docs.skytable.io/ddl/#inspect
	InspectKeyspaces(ctx context.Context) (*protocol.TypedArray, error)
	// https://docs.skytable.io/ddl/#keyspaces
	CreateKeyspace(ctx context.Context, name string) error
	// https://docs.skytable.io/ddl/#keyspaces-1
	DropKeyspace(ctx context.Context, name string) error
	// https://docs.skytable.io/ddl/#keyspaces-2
	//
	// If name is "", inspect the current keyspace
	InspectKeyspace(ctx context.Context, name string) (*protocol.TypedArray, error)

	// https://docs.skytable.io/ddl/#tables
	CreateTable(ctx context.Context, path string, modelDesc any) error
	// https://docs.skytable.io/ddl/#tables-1
	DropTable(ctx context.Context, path string) error
	// https://docs.skytable.io/ddl/#tables-2
	//
	// If path is "", inspect the current table
	InspectTable(ctx context.Context, path string) (protocol.ModelDescription, error)

	// https://docs.skytable.io/actions/sys#info
	SysInfoVersion(ctx context.Context) (string, error)
	// https://docs.skytable.io/actions/sys#info
	SysInfoProtocol(ctx context.Context) (string, error)
	// https://docs.skytable.io/actions/sys#info
	SysInfoProtoVer(ctx context.Context) (float32, error)
	// https://docs.skytable.io/actions/sys#metric
	//
	// Returns true if "good", false when "critical"
	SysMetricHealth(ctx context.Context) (bool, error)
	// https://docs.skytable.io/actions/sys#metric
	SysMetricStorage(ctx context.Context) (uint64, error)

	// https://docs.skytable.io/actions/mksnap
	//
	// If name is "", it will only send "MKSNAP"
	MKSnap(ctx context.Context, name string) error
	// https://docs.skytable.io/actions/whereami
	WhereAmI(ctx context.Context) (string, error)
	// https://docs.skytable.io/actions/dbsize
	//
	// If entity is "", check the current table
	DBSize(ctx context.Context, entity string) (uint64, error)
	// https://docs.skytable.io/actions/keylen
	KeyLen(ctx context.Context, key string) (uint64, error)
	// https://docs.skytable.io/actions/flushdb
	//
	// If entity is "", flush the current table
	FlushDB(ctx context.Context, entity string) error

	// https://docs.skytable.io/actions/lskeys
	LSKeys(ctx context.Context, entity string, limit uint64) (*protocol.TypedArray, error)
}

type SkytablePool

type SkytablePool interface {
	Skytable

	RentConn(dontOpenNew bool) (conn *Conn, pusher func(), err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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