-
Notifications
You must be signed in to change notification settings - Fork 0
/
skytable.go
182 lines (159 loc) · 7.73 KB
/
skytable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package skytable
import (
"context"
"strings"
"github.com/No3371/go-skytable/action"
"github.com/No3371/go-skytable/protocol"
"github.com/No3371/go-skytable/response"
)
const ProtoVer = "Skyhash-1.1"
type AuthProvider func() (username, token string, err error)
type Action interface {
AppendToPacket(builder *strings.Builder) error
ValidateProtocol(response interface{}) error
}
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 interface {
Skytable
RentConn(dontOpenNew bool) (conn *Conn, pusher func(), err error)
}