Documentation
¶
Overview ¶
Package zetabase provides a Go client library for the Zetabase cloud database along with a command-line tool for managing data and users.
Most users will only require the ZetabaseClient class; other exposed functions are primarily of use for working at the protocol layer, e.g. for performance fine-tuning.
The client library communicates using a protocol based on gRPC/Protocol Buffers.
This code and the included command-line tool are licensed under the Modified BSD License included in the attached LICENSE file.
Index ¶
- Constants
- func ConfirmUserIdentity(ctx context.Context, uid string, parentId *string, verifyStr string, ...) error
- func DecodeEcdsaPrivateKey(pemEncoded string) (*ecdsa.PrivateKey, error)
- func DecodeEcdsaPublicKey(pemEncodedPub string) (*ecdsa.PublicKey, error)
- func EmptySignature() *zbprotocol.EcdsaSignature
- func EncodeEcdsaPrivateKey(privateKey *ecdsa.PrivateKey) ([]byte, error)
- func EncodeEcdsaPublicKey(publicKey *ecdsa.PublicKey) ([]byte, error)
- func GenerateKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey)
- func IsSemVerVersionAtLeast(userVersion, minVersion string) bool
- func MakeCredentialEcdsa(nonce int64, uid string, relBytes []byte, pk *ecdsa.PrivateKey) *zbprotocol.ProofOfCredential
- func MakeCredentialJwt(tok string) *zbprotocol.ProofOfCredential
- func MakeEmptyCredentials() *zbprotocol.ProofOfCredential
- func MakeGetPages(client *ZetabaseClient, dataKeys []string, maxItemSize int64, ...) *getPages
- func MakeZetabaseSignature(uid string, nonce int64, relData []byte, pk *ecdsa.PrivateKey) (string, string)
- func MultiPutExtraSigningBytesMd5(pairs []*zbprotocol.DataPair) []byte
- func PermissionsEntrySigningBytes(perm *zbprotocol.PermissionsEntry) []byte
- func TableCreateSigningBytes(tblId string, perms []*zbprotocol.PermissionsEntry) []byte
- func TablePutExtraSigningBytes(key string, valu []byte) []byte
- func ValidatePhoneNumber(s string) bool
- func ValidateZetabaseSignature(uid string, nonce int64, relData []byte, pk *ecdsa.PublicKey, r, s string) bool
- type BQClause
- type BQCompQ
- type BQLogicalQ
- type BQParser
- type BQRootQ
- type BQValue
- type IndexedField
- type NewRootUserInfo
- type NonceMaker
- type PaginationHandler
- type PermConstraint
- func NewPermConstraintCustom(field, reqValue string) *PermConstraint
- func NewPermConstraintOrder(field string) *PermConstraint
- func NewPermConstraintRandom(field string) *PermConstraint
- func NewPermConstraintTime(field string) *PermConstraint
- func NewPermConstraintUserId(field string) *PermConstraint
- func NewPermissionConstraint(field, reqValue string) *PermConstraint
- type PermEntry
- type QueryAnd
- type QueryEquals
- type QueryGreaterThan
- type QueryGreaterThanEqual
- type QueryLessThan
- type QueryLessThanEqual
- type QueryNotEquals
- type QueryOr
- type QueryTextSearch
- type SubQueryConvertible
- type ZetabaseClient
- func (z *ZetabaseClient) AddPermission(tblOwnerId, tblId string, perm *PermEntry) error
- func (z *ZetabaseClient) CheckVersion() (bool, *zbprotocol.VersionDetails, error)
- func (z *ZetabaseClient) ConfirmNewRootUser(userId, verificationCode string) error
- func (z *ZetabaseClient) ConfirmNewSubUser(subuserId, verificationCode string) error
- func (z *ZetabaseClient) Connect() error
- func (z *ZetabaseClient) CreateTable(tblId string, dataType zbprotocol.TableDataFormat, ...) error
- func (z *ZetabaseClient) DeleteKey(tableOwnerId, tableId, key string) error
- func (z *ZetabaseClient) DeleteTable(tableOwnerId, tableId string) error
- func (z *ZetabaseClient) Get(tableOwnerId, tableId string, keys []string) *getPages
- func (z *ZetabaseClient) GetSubIdentities() ([]*zbprotocol.NewSubIdentityRequest, error)
- func (z *ZetabaseClient) GrpcClient() zbprotocol.ZetabaseProviderClient
- func (z *ZetabaseClient) Id() string
- func (z *ZetabaseClient) JwtTokens() (string, string)
- func (z *ZetabaseClient) ListKeys(tableOwnerId, tableId string) *PaginationHandler
- func (z *ZetabaseClient) ListKeysWithPattern(tableOwnerId, tableId, pattern string) *PaginationHandler
- func (z *ZetabaseClient) ListTables() ([]string, error)
- func (z *ZetabaseClient) ModifySubIdentity(subUserId string, newHandle *string, newEmail *string, newMobile *string, ...) error
- func (z *ZetabaseClient) NewRootUser(handle, email, mobile, password string, pubKey0 *ecdsa.PublicKey) (*NewRootUserInfo, error)
- func (z *ZetabaseClient) NewSubUser(handle, email, mobile, password, signupCode, groupId string, ...) (string, error)
- func (z *ZetabaseClient) PutData(tableOwnerId, tableId, key string, valu []byte, overwrite bool) error
- func (z *ZetabaseClient) PutMulti(tableOwnerId, tableId string, keys []string, valus [][]byte, overwrite bool) error
- func (z *ZetabaseClient) Query(tableOwnerId, tableId string, qry0 SubQueryConvertible) *PaginationHandler
- func (z *ZetabaseClient) QueryData(tbldOwnerId, tblId string, qry SubQueryConvertible) (*getPages, error)
- func (z *ZetabaseClient) RefreshToken() error
- func (z *ZetabaseClient) SetCertVerify(b bool)
- func (z *ZetabaseClient) SetDebugMode()
- func (z *ZetabaseClient) SetIdKey(priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey)
- func (z *ZetabaseClient) SetIdPassword(loginId, pwd string)
- func (z *ZetabaseClient) SetInsecure()
- func (z *ZetabaseClient) SetMaxItemSize(newSize int64)
- func (z *ZetabaseClient) SetParent(id string)
- func (z *ZetabaseClient) SetServerAddr(addr string)
- func (z *ZetabaseClient) SetThirdPartyAuthToken(handle, token, source string)
- func (z *ZetabaseClient) StringDump() string
Constants ¶
const ( ClientVersion = "0.1.1" ClientVersionCode = "Curry" )
const (
DoSaveCertificates = false
)
const (
GrpcMaxBytes = 4000000
)
Variables ¶
This section is empty.
Functions ¶
func ConfirmUserIdentity ¶
func ConfirmUserIdentity(ctx context.Context, uid string, parentId *string, verifyStr string, client zbprotocol.ZetabaseProviderClient) error
Function ConfirmUserIdentity confirms a new user ID with the SMS confirmation code they received.
func DecodeEcdsaPrivateKey ¶
func DecodeEcdsaPrivateKey(pemEncoded string) (*ecdsa.PrivateKey, error)
func DecodeEcdsaPublicKey ¶
func EmptySignature ¶
func EmptySignature() *zbprotocol.EcdsaSignature
func EncodeEcdsaPrivateKey ¶
func EncodeEcdsaPrivateKey(privateKey *ecdsa.PrivateKey) ([]byte, error)
func GenerateKeyPair ¶
func GenerateKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey)
func IsSemVerVersionAtLeast ¶
func MakeCredentialEcdsa ¶
func MakeCredentialEcdsa(nonce int64, uid string, relBytes []byte, pk *ecdsa.PrivateKey) *zbprotocol.ProofOfCredential
func MakeCredentialJwt ¶
func MakeCredentialJwt(tok string) *zbprotocol.ProofOfCredential
func MakeEmptyCredentials ¶
func MakeEmptyCredentials() *zbprotocol.ProofOfCredential
func MakeGetPages ¶
func MakeGetPages(client *ZetabaseClient, dataKeys []string, maxItemSize int64, tableOwnerId, tableId string) *getPages
func MakeZetabaseSignature ¶
func MultiPutExtraSigningBytesMd5 ¶
func MultiPutExtraSigningBytesMd5(pairs []*zbprotocol.DataPair) []byte
Get extra signing bytes for a list of data pairs (PutMulti).
func PermissionsEntrySigningBytes ¶
func PermissionsEntrySigningBytes(perm *zbprotocol.PermissionsEntry) []byte
func TableCreateSigningBytes ¶
func TableCreateSigningBytes(tblId string, perms []*zbprotocol.PermissionsEntry) []byte
func TablePutExtraSigningBytes ¶
Get extra signing bytes for a single table put
func ValidatePhoneNumber ¶
Types ¶
type BQClause ¶
A "clause": a subexpression in parentheses OR a single field comparison
func (*BQClause) ToQuery ¶
func (b *BQClause) ToQuery() SubQueryConvertible
type BQCompQ ¶
type BQCompQ struct { Field string `@Ident` Operator string `@("=" | ">" | "<" | ">=" | "<=" | "~" | "!=" | "not")` Value *BQValue `@@` }
Base comparison: an identifier then a comparison operator then a literal
func (*BQCompQ) ToQuery ¶
func (b *BQCompQ) ToQuery() SubQueryConvertible
type BQLogicalQ ¶
A "logical": an operator with a second clause
type BQParser ¶
type BQParser struct {
// contains filtered or unexported fields
}
func NewBQParser ¶
type BQRootQ ¶
type BQRootQ struct { Clause *BQClause `@@` Conjunctions []*BQLogicalQ `@@*` }
Root (expression): a comparison followed by one or more logical conjunctions...
func (*BQRootQ) ToQuery ¶
func (b *BQRootQ) ToQuery() SubQueryConvertible
type BQValue ¶
type BQValue struct { String *string ` @String` Number *float64 ` | @Float` Integer *int64 ` | @Int` }
A value: string or number literal
type IndexedField ¶
type IndexedField struct { FieldName string LangCode string IndexType zbprotocol.QueryOrdering }
func NewIndexedField ¶
func NewIndexedField(fieldName string, indexTyp zbprotocol.QueryOrdering) *IndexedField
func (*IndexedField) SetLanguageCode ¶
func (f *IndexedField) SetLanguageCode(code string)
func (*IndexedField) ToProtocol ¶
func (f *IndexedField) ToProtocol() *zbprotocol.TableIndexField
type NewRootUserInfo ¶ added in v0.1.5
type NewRootUserInfo struct { Id string `json:"uid"` PubKeyEncoded string `json:"pub_key"` PrivKeyEncoded string `json:"priv_key"` }
Information on newly created root users
type NonceMaker ¶
type NonceMaker struct {
// contains filtered or unexported fields
}
func NewNonceMaker ¶
func NewNonceMaker() *NonceMaker
func (*NonceMaker) Get ¶
func (n *NonceMaker) Get() int64
type PaginationHandler ¶
type PaginationHandler struct {
// contains filtered or unexported fields
}
Type PaginationHandler manages pagination of Zetabase responses.
func StandardPaginationHandlerFor ¶
func StandardPaginationHandlerFor(f func(int64) (map[string][]byte, bool, error)) *PaginationHandler
Build a PaginationHandler given a function that takes as input a page index and returns the page data
func (*PaginationHandler) Data ¶
func (p *PaginationHandler) Data() (map[string][]byte, error)
Get data fetched so far (for data retrieval responses)
func (*PaginationHandler) DataAll ¶
func (p *PaginationHandler) DataAll() (map[string][]byte, error)
Get all data from all pages (for data retrieval responses)
func (*PaginationHandler) Keys ¶
func (p *PaginationHandler) Keys() ([]string, error)
Get keys fetched so far
func (*PaginationHandler) KeysAll ¶
func (p *PaginationHandler) KeysAll() ([]string, error)
Get all keys from all pages (for data retrieval responses)
type PermConstraint ¶
func NewPermConstraintCustom ¶ added in v0.1.2
func NewPermConstraintCustom(field, reqValue string) *PermConstraint
func NewPermConstraintOrder ¶ added in v0.1.2
func NewPermConstraintOrder(field string) *PermConstraint
func NewPermConstraintRandom ¶ added in v0.1.2
func NewPermConstraintRandom(field string) *PermConstraint
func NewPermConstraintTime ¶ added in v0.1.2
func NewPermConstraintTime(field string) *PermConstraint
func NewPermConstraintUserId ¶
func NewPermConstraintUserId(field string) *PermConstraint
func NewPermissionConstraint ¶
func NewPermissionConstraint(field, reqValue string) *PermConstraint
type PermEntry ¶
type PermEntry struct { Level zbprotocol.PermissionLevel AudienceType zbprotocol.PermissionAudienceType AudienceId string Constraints []*PermConstraint }
func NewPermissionEntry ¶
func NewPermissionEntry(level zbprotocol.PermissionLevel, typ zbprotocol.PermissionAudienceType, audId string) *PermEntry
func (*PermEntry) AddConstraint ¶
func (p *PermEntry) AddConstraint(c *PermConstraint)
func (*PermEntry) ToProtocol ¶
func (p *PermEntry) ToProtocol(uid, tblId string) *zbprotocol.PermissionsEntry
type QueryAnd ¶
type QueryAnd struct { Left SubQueryConvertible Right SubQueryConvertible }
func QAnd ¶
func QAnd(l, r SubQueryConvertible) *QueryAnd
func (*QueryAnd) ToSubQuery ¶
func (q *QueryAnd) ToSubQuery(tblOwnerId, tblId string) *zbprotocol.TableSubQuery
type QueryEquals ¶
type QueryEquals struct { Field string CompValue interface{} }
func QEq ¶
func QEq(field string, valu interface{}) *QueryEquals
func (*QueryEquals) ToSubQuery ¶
func (q *QueryEquals) ToSubQuery(a, b string) *zbprotocol.TableSubQuery
type QueryGreaterThan ¶
type QueryGreaterThan struct { Field string CompValue interface{} }
func QGt ¶
func QGt(field string, valu interface{}) *QueryGreaterThan
func (*QueryGreaterThan) ToSubQuery ¶
func (q *QueryGreaterThan) ToSubQuery(a, b string) *zbprotocol.TableSubQuery
type QueryGreaterThanEqual ¶
type QueryGreaterThanEqual struct { Field string CompValue interface{} }
func QGte ¶
func QGte(field string, valu interface{}) *QueryGreaterThanEqual
func (*QueryGreaterThanEqual) ToSubQuery ¶
func (q *QueryGreaterThanEqual) ToSubQuery(a, b string) *zbprotocol.TableSubQuery
type QueryLessThan ¶
type QueryLessThan struct { Field string CompValue interface{} }
func QLt ¶
func QLt(field string, valu interface{}) *QueryLessThan
func (*QueryLessThan) ToSubQuery ¶
func (q *QueryLessThan) ToSubQuery(a, b string) *zbprotocol.TableSubQuery
type QueryLessThanEqual ¶
type QueryLessThanEqual struct { Field string CompValue interface{} }
func QLte ¶
func QLte(field string, valu interface{}) *QueryLessThanEqual
func (*QueryLessThanEqual) ToSubQuery ¶
func (q *QueryLessThanEqual) ToSubQuery(a, b string) *zbprotocol.TableSubQuery
type QueryNotEquals ¶
type QueryNotEquals struct { Field string CompValue interface{} }
func QNEq ¶
func QNEq(field string, valu interface{}) *QueryNotEquals
func (*QueryNotEquals) ToSubQuery ¶
func (q *QueryNotEquals) ToSubQuery(a, b string) *zbprotocol.TableSubQuery
type QueryOr ¶
type QueryOr struct { Left SubQueryConvertible Right SubQueryConvertible }
func QOr ¶
func QOr(l, r SubQueryConvertible) *QueryOr
func (*QueryOr) ToSubQuery ¶
func (q *QueryOr) ToSubQuery(tblOwnerId, tblId string) *zbprotocol.TableSubQuery
type QueryTextSearch ¶
type QueryTextSearch struct { Field string CompValue interface{} }
func QText ¶
func QText(field string, queryStr string) *QueryTextSearch
func (*QueryTextSearch) ToSubQuery ¶
func (q *QueryTextSearch) ToSubQuery(a, b string) *zbprotocol.TableSubQuery
type SubQueryConvertible ¶
type SubQueryConvertible interface {
ToSubQuery(tblOwnerId, tblId string) *zbprotocol.TableSubQuery
}
type ZetabaseClient ¶
type ZetabaseClient struct {
// contains filtered or unexported fields
}
Type ZetabaseClient represents a long-lived Zetabase connection for a particular identity.
func NewZetabaseClient ¶
func NewZetabaseClient(uid string) *ZetabaseClient
Creates a new client for a given user ID uid. The user ID should be in UUID form.
func NewZetabaseUserClient ¶ added in v0.1.2
func NewZetabaseUserClient(parentId string) *ZetabaseClient
func (*ZetabaseClient) AddPermission ¶
func (z *ZetabaseClient) AddPermission(tblOwnerId, tblId string, perm *PermEntry) error
Method AddPermission adds permission perm to the given table tblId.
func (*ZetabaseClient) CheckVersion ¶
func (z *ZetabaseClient) CheckVersion() (bool, *zbprotocol.VersionDetails, error)
Checks version compatibility between client and server
func (*ZetabaseClient) ConfirmNewRootUser ¶ added in v0.1.5
func (z *ZetabaseClient) ConfirmNewRootUser(userId, verificationCode string) error
Confirm new given user ID and verification code
func (*ZetabaseClient) ConfirmNewSubUser ¶
func (z *ZetabaseClient) ConfirmNewSubUser(subuserId, verificationCode string) error
Confirm new subuser given subuser ID and verification code
func (*ZetabaseClient) Connect ¶
func (z *ZetabaseClient) Connect() error
Connect to Zetabase with the provided credentials.
func (*ZetabaseClient) CreateTable ¶
func (z *ZetabaseClient) CreateTable(tblId string, dataType zbprotocol.TableDataFormat, indexedFields []*IndexedField, perms []*PermEntry, allowJwt bool) error
Create a new table tblId with the given data format, indexed fields, and permissions
func (*ZetabaseClient) DeleteKey ¶
func (z *ZetabaseClient) DeleteKey(tableOwnerId, tableId, key string) error
Delete a given key-value pair from a table
func (*ZetabaseClient) DeleteTable ¶
func (z *ZetabaseClient) DeleteTable(tableOwnerId, tableId string) error
Delete a table and all its contents
func (*ZetabaseClient) Get ¶
func (z *ZetabaseClient) Get(tableOwnerId, tableId string, keys []string) *getPages
func (*ZetabaseClient) GetSubIdentities ¶
func (z *ZetabaseClient) GetSubIdentities() ([]*zbprotocol.NewSubIdentityRequest, error)
Method GetSubIdentities lists subusers of the authenticated user.
func (*ZetabaseClient) GrpcClient ¶
func (z *ZetabaseClient) GrpcClient() zbprotocol.ZetabaseProviderClient
Return the underlying gRPC client
func (*ZetabaseClient) JwtTokens ¶ added in v0.1.5
func (z *ZetabaseClient) JwtTokens() (string, string)
func (*ZetabaseClient) ListKeys ¶
func (z *ZetabaseClient) ListKeys(tableOwnerId, tableId string) *PaginationHandler
Method ListKeys lists the keys for a given table
func (*ZetabaseClient) ListKeysWithPattern ¶
func (z *ZetabaseClient) ListKeysWithPattern(tableOwnerId, tableId, pattern string) *PaginationHandler
Method ListKeysWithPattern lists keys with a given prefix pattern, where the suffix wildcard operator is represented by %.
func (*ZetabaseClient) ListTables ¶ added in v0.1.2
func (z *ZetabaseClient) ListTables() ([]string, error)
Method ListTables lists the tables associated with the ZetabaseClient's account
func (*ZetabaseClient) ModifySubIdentity ¶
func (z *ZetabaseClient) ModifySubIdentity(subUserId string, newHandle *string, newEmail *string, newMobile *string, newPass *string, newPubKey *string) error
Method ModifySubIdentity modifies an existing subuser. Non-nil fields will be updated.
func (*ZetabaseClient) NewRootUser ¶ added in v0.1.5
func (z *ZetabaseClient) NewRootUser(handle, email, mobile, password string, pubKey0 *ecdsa.PublicKey) (*NewRootUserInfo, error)
Create a new root user with the given attributes
func (*ZetabaseClient) NewSubUser ¶
func (z *ZetabaseClient) NewSubUser(handle, email, mobile, password, signupCode, groupId string, pubKey *ecdsa.PublicKey) (string, error)
Create a new subuser with the given attributes
func (*ZetabaseClient) PutData ¶
func (z *ZetabaseClient) PutData(tableOwnerId, tableId, key string, valu []byte, overwrite bool) error
Put a given key-value pair into a table
func (*ZetabaseClient) PutMulti ¶
func (z *ZetabaseClient) PutMulti(tableOwnerId, tableId string, keys []string, valus [][]byte, overwrite bool) error
Method PutMulti puts multiple key-value pairs into a table at once
func (*ZetabaseClient) Query ¶
func (z *ZetabaseClient) Query(tableOwnerId, tableId string, qry0 SubQueryConvertible) *PaginationHandler
func (*ZetabaseClient) QueryData ¶
func (z *ZetabaseClient) QueryData(tbldOwnerId, tblId string, qry SubQueryConvertible) (*getPages, error)
func (*ZetabaseClient) RefreshToken ¶ added in v0.1.5
func (z *ZetabaseClient) RefreshToken() error
func (*ZetabaseClient) SetCertVerify ¶
func (z *ZetabaseClient) SetCertVerify(b bool)
Toggle certificate verification
func (*ZetabaseClient) SetIdKey ¶
func (z *ZetabaseClient) SetIdKey(priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey)
Set the private and public keys corresponding to this identity
func (*ZetabaseClient) SetIdPassword ¶
func (z *ZetabaseClient) SetIdPassword(loginId, pwd string)
Set a handle and password as authentication credentials (for JWT authentication mode)
func (*ZetabaseClient) SetInsecure ¶
func (z *ZetabaseClient) SetInsecure()
Toggle insecure (plaintext) connection
func (*ZetabaseClient) SetMaxItemSize ¶
func (z *ZetabaseClient) SetMaxItemSize(newSize int64)
func (*ZetabaseClient) SetParent ¶
func (z *ZetabaseClient) SetParent(id string)
Set parent user ID (when connecting as a subuser) to id. This parent ID should be in UUID form.
func (*ZetabaseClient) SetServerAddr ¶
func (z *ZetabaseClient) SetServerAddr(addr string)
Set a customer server address (for on-premises installations only)
func (*ZetabaseClient) SetThirdPartyAuthToken ¶ added in v0.1.4
func (z *ZetabaseClient) SetThirdPartyAuthToken(handle, token, source string)
Set third-party authentication credentials
func (*ZetabaseClient) StringDump ¶ added in v0.1.3
func (z *ZetabaseClient) StringDump() string