CovenantSQL: Index | Files | Directories

package client

import ""

Package client is a golang sql driver implementation to interact with CovenantSQL.


Package Files

config.go conn.go doc.go driver.go errors.go receipt.go result.go rows.go stmt.go tx.go


const (
    // DBScheme defines the dsn scheme.
    DBScheme = "covenantsql"
    // DBSchemeAlias defines the alias dsn scheme.
    DBSchemeAlias = "cql"
    // DefaultGasPrice defines the default gas price for new created database.
    DefaultGasPrice = 1
    // DefaultAdvancePayment defines the default advance payment for new created database.
    DefaultAdvancePayment = 20000000


var (
    // PeersUpdateInterval defines peers list refresh interval for client.
    PeersUpdateInterval = time.Second * 5

    // DefaultConfigFile is the default path of config file
    DefaultConfigFile = "~/.cql/config.yaml"
var (
    // ErrQueryInTransaction represents a read query is presented during user transaction.
    ErrQueryInTransaction = errors.New("only write is supported during transaction")
    // ErrNotInitialized represents the driver is not initialized yet.
    ErrNotInitialized = errors.New("driver not initialized")
    // ErrAlreadyInitialized represents the driver is already initialized.
    ErrAlreadyInitialized = errors.New("driver already initialized")
    // ErrInvalidRequestSeq defines invalid sequence no of request.
    ErrInvalidRequestSeq = errors.New("invalid request sequence applied")
    // ErrInvalidProfile indicates the SQLChain profile is invalid.
    ErrInvalidProfile = errors.New("invalid sqlchain profile")
    // ErrNoSuchTokenBalance indicates no such token balance in chain.
    ErrNoSuchTokenBalance = errors.New("no such token balance")

Various errors the driver might returns.

func Create Uses

func Create(meta ResourceMeta) (txHash hash.Hash, dsn string, err error)

Create sends create database operation to block producer.

func Drop Uses

func Drop(dsn string) (txHash hash.Hash, err error)

Drop sends drop database operation to block producer.

func ExecuteInTx Uses

func ExecuteInTx(tx driver.Tx, fn func() error) (err error)

ExecuteInTx runs fn inside tx which should already have begun.

func ExecuteTx Uses

func ExecuteTx(
    ctx context.Context, db *sql.DB, txopts *sql.TxOptions, fn func(*sql.Tx) error,
) error

ExecuteTx starts a transaction, and runs fn in it.

func GetTokenBalance Uses

func GetTokenBalance(tt types.TokenType) (balance uint64, err error)

GetTokenBalance get the token balance of current account.

func Init Uses

func Init(configFile string, masterKey []byte) (err error)

Init defines init process for client.

func TransferToken Uses

func TransferToken(targetUser proto.AccountAddress, amount uint64, tokenType types.TokenType) (
    txHash hash.Hash, err error,

TransferToken send Transfer transaction to chain.

func UpdatePermission Uses

func UpdatePermission(targetUser proto.AccountAddress,
    targetChain proto.AccountAddress, perm *types.UserPermission) (txHash hash.Hash, err error)

UpdatePermission sends UpdatePermission transaction to chain.

func WaitBPDatabaseCreation Uses

func WaitBPDatabaseCreation(
    ctx context.Context,
    dbID proto.DatabaseID,
    db *sql.DB,
    period time.Duration,
) (err error)

WaitBPDatabaseCreation waits for database creation complete.

func WaitDBCreation Uses

func WaitDBCreation(ctx context.Context, dsn string) (err error)

WaitDBCreation waits for database creation complete.

func WaitTxConfirmation Uses

func WaitTxConfirmation(
    ctx context.Context, txHash hash.Hash) (state interfaces.TransactionState, err error,

WaitTxConfirmation waits for the transaction with target hash txHash to be confirmed. It also returns if any error occurs or a final state is returned from BP.

func WithReceipt Uses

func WithReceipt(ctx context.Context) context.Context

WithReceipt returns a context who holds a *atomic.Value. A *Receipt will be set to this value after the query succeeds.

Note that this context is safe for concurrent queries, but the value may be reset in another goroutines. So if you want to make use of Receipt in several goroutines, you should call this method to get separated child context in each goroutine.

type Config Uses

type Config struct {
    DatabaseID string

    // UseLeader use leader nodes to do queries
    UseLeader bool

    // UseFollower use follower nodes to do queries
    UseFollower bool

    // UseDirectRPC use direct RPC to access the miner
    UseDirectRPC bool

    // Mirror option forces client to query from mirror server
    Mirror string

Config is a configuration parsed from a DSN string.

func NewConfig Uses

func NewConfig() *Config

NewConfig creates a new config with default value.

func ParseDSN Uses

func ParseDSN(dsn string) (cfg *Config, err error)

ParseDSN parse the DSN string to a Config.

func (*Config) FormatDSN Uses

func (cfg *Config) FormatDSN() string

FormatDSN formats the given Config into a DSN string which can be passed to the driver.

type Receipt Uses

type Receipt struct {
    RequestHash hash.Hash

Receipt defines a receipt of CovenantSQL query request.

func GetReceipt Uses

func GetReceipt(ctx context.Context) (rec *Receipt, ok bool)

GetReceipt tries to get *Receipt from context.

type ResourceMeta Uses

type ResourceMeta struct {
    // copied fields from types.ResourceMeta
    TargetMiners           []proto.AccountAddress `json:"target-miners,omitempty"`        // designated miners
    Node                   uint16                 `json:"node,omitempty"`                 // reserved node count
    Space                  uint64                 `json:"space,omitempty"`                // reserved storage space in bytes
    Memory                 uint64                 `json:"memory,omitempty"`               // reserved memory in bytes
    LoadAvgPerCPU          float64                `json:"load-avg-per-cpu,omitempty"`     // max loadAvg15 per CPU
    EncryptionKey          string                 `json:"encrypt-key,omitempty"`          // encryption key for database instance
    UseEventualConsistency bool                   `json:"eventual-consistency,omitempty"` // use eventual consistency replication if enabled
    ConsistencyLevel       float64                `json:"consistency-level,omitempty"`    // customized strong consistency level
    IsolationLevel         int                    `json:"isolation-level,omitempty"`      // customized isolation level

    GasPrice       uint64 `json:"gas-price"`       // customized gas price
    AdvancePayment uint64 `json:"advance-payment"` // customized advance payment

ResourceMeta defines new database resources requirement descriptions.


toolkitPackage toolkit implements handy functions for `AES-128-CBC PKCS#7` encryption and decryption for `end to end encryption`.

Package client imports 28 packages (graph) and is imported by 10 packages. Updated 2019-08-23. Refresh now. Tools for package owners.