Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) AddIndex(ctx context.Context, dbName string, tableName string, key string) error
- func (c *Client) AddUniqueIndex(ctx context.Context, dbName string, tableName string, key string) error
- func (c *Client) Close() error
- func (c *Client) CountWhere(ctx context.Context, dbName string, tableName string, cond condition.Condition) (int64, error)
- func (c *Client) CreateTable(ctx context.Context, dbName string, name string, template record.Record) error
- func (c *Client) DeleteIndex(ctx context.Context, dbName string, tableName string, key string) error
- func (c *Client) DeleteTable(ctx context.Context, dbName string, name string) error
- func (c *Client) DeleteWhere(ctx context.Context, dbName string, tableName string, cond condition.Condition) (int64, error)
- func (c *Client) DescribeTable(ctx context.Context, dbName string, tableName string) (record.Record, error)
- func (c *Client) Insert(ctx context.Context, dbName string, tableName string, itr record.Iterator) (err error)
- func (c *Client) InsertRecords(ctx context.Context, dbName string, tableName string, rs ...record.Record) (err error)
- func (c *Client) ListIndices(ctx context.Context, dbName string, tableName string) ([]string, error)
- func (c *Client) ListTables(ctx context.Context, dbName string) ([]string, error)
- func (c *Client) SelectWhere(ctx context.Context, dbName string, tableName string, template record.Record, ...) (record.Iterator, error)
- func (c *Client) SelectWhereLimit(ctx context.Context, dbName string, tableName string, template record.Record, ...) (record.Iterator, error)
- func (c *Client) UpdateWhere(ctx context.Context, dbName string, tableName string, ...) (int64, error)
- type ClientConfig
- type DatabaseDriverFunc
- type Option
- type Server
Constants ¶
const ( DefaultTCPPort = 12356 DefaultWSPort = 80 )
The default ports that kvdb listens on.
const ( DefaultMaxMessageSize = 8 * 1024 * 1024 // 8Mb DefaultReadBufferSize = 64 * 1024 // 64Kb DefaultWriteBufferSize = 64 * 1024 // 64Kb )
The default kvdb server values.
Variables ¶
var ErrNilConfiguration = errors.New("illegal nil configuration data")
ErrNilConfiguration is returned when a ClientConfig fails to validate.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { log.BasicLogable // contains filtered or unexported fields }
Client is the client-view of the server.
func NewClient ¶
func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error)
NewClient returns a new client view of the server specified by the configuration cfg.
func (*Client) AddIndex ¶
AddIndex adds an index on the given key. If an index already exists, this index is unmodified and nil is returned.
func (*Client) AddUniqueIndex ¶
func (c *Client) AddUniqueIndex(ctx context.Context, dbName string, tableName string, key string) error
AddUniqueIndex adds an index on the given key and the constraint that, for each value of this key, there is at most one record with that value. This operation may fail if there is an existing index on that key, and will fail if the existing values in the table do not satisfy the uniqueness constraint.
func (*Client) CountWhere ¶
func (c *Client) CountWhere(ctx context.Context, dbName string, tableName string, cond condition.Condition) (int64, error)
CountWhere returns the number of records in the table that satisfy the condition "cond".
func (*Client) CreateTable ¶
func (c *Client) CreateTable(ctx context.Context, dbName string, name string, template record.Record) error
CreateTable creates a table with the given name in the database.
The provided template will be used by the underlying storage-engine to create the new table if appropriate; the storage-engine is free to ignore the template if it is not required (for example, in a schema-less database).
func (*Client) DeleteIndex ¶
func (c *Client) DeleteIndex(ctx context.Context, dbName string, tableName string, key string) error
DeleteIndex deletes the index on the given key. If no index is present, nil is returned.
func (*Client) DeleteTable ¶
DeleteTable deletes the indicated table from the database. Does not return an error if the table does not exist.
func (*Client) DeleteWhere ¶
func (c *Client) DeleteWhere(ctx context.Context, dbName string, tableName string, cond condition.Condition) (int64, error)
DeleteWhere deletes those records in the table that satisfy the condition "cond". Returns the number of records deleted.
func (*Client) DescribeTable ¶
func (c *Client) DescribeTable(ctx context.Context, dbName string, tableName string) (record.Record, error)
DescribeTable returns a best-guess template for the data in table.
Note that the accuracy of this template depends on the underlying storage engine. It might not be possible to return an exact description (for example, in a schema-less database), and in this case we return a good guess based on a sample of the data available.
func (*Client) Insert ¶
func (c *Client) Insert(ctx context.Context, dbName string, tableName string, itr record.Iterator) (err error)
Insert inserts the records from the given iterator into the table.
func (*Client) InsertRecords ¶
func (c *Client) InsertRecords(ctx context.Context, dbName string, tableName string, rs ...record.Record) (err error)
InsertRecords inserts the given records into the table.
func (*Client) ListIndices ¶
func (c *Client) ListIndices(ctx context.Context, dbName string, tableName string) ([]string, error)
ListIndices lists the keys for which indices are present.
func (*Client) ListTables ¶
ListTables returns the names of the tables in the database.
func (*Client) SelectWhere ¶
func (c *Client) SelectWhere(ctx context.Context, dbName string, tableName string, template record.Record, cond condition.Condition, order sort.OrderBy) (record.Iterator, error)
SelectWhere returns the results satisfying condition "cond" (which may be nil if there are no conditions), sorted as specified by "order" (which may be nil if there is no sort order required). The returned records will be in the form specified by "template".
func (*Client) SelectWhereLimit ¶
func (c *Client) SelectWhereLimit(ctx context.Context, dbName string, tableName string, template record.Record, cond condition.Condition, order sort.OrderBy, n int64) (record.Iterator, error)
SelectWhereLimit returns at most n results that satisfy the condition "cond" (which may be nil if there are no conditions), sorted as specified by "order" (which may be nil if there is no sort order required). The returned records will be in the form specified by "template".
func (*Client) UpdateWhere ¶
func (c *Client) UpdateWhere(ctx context.Context, dbName string, tableName string, replacement record.Record, cond condition.Condition) (int64, error)
UpdateWhere updates all records in the table that satisfy the condition "cond" by setting the keys in "replacement" to the given values. Returns the number of records updated.
type ClientConfig ¶
type ClientConfig struct { Address *address.Address // The address to connect to SSLCert []byte // The SSL certificate (if any) AppName string // The application name to identify ourselves via }
ClientConfig describes the configuration options we allow a user to set on a client connection.
func DefaultConfig ¶
func DefaultConfig() *ClientConfig
DefaultConfig returns a new client configuration initialised with the default values.
The initial default value for the host will be read from the environment variable
PCAS_KVDB_ADDRESS = "hostname[:port]" or "ws://host/path"
on package init.
func SetDefaultConfig ¶
func SetDefaultConfig(c *ClientConfig) *ClientConfig
SetDefaultConfig sets the default client configuration to c and returns the old default configuration. This change will be reflected in future calls to DefaultConfig.
func (*ClientConfig) Copy ¶
func (c *ClientConfig) Copy() *ClientConfig
Copy returns a copy of the configuration.
func (*ClientConfig) URI ¶
func (c *ClientConfig) URI() string
URI returns the URI connection string.
Note that the returned string may differ slightly from the value returned c.Address.URI(). For example, if c.Address omits a port number, an appropriate default port number is used here.
func (*ClientConfig) URL ¶
func (c *ClientConfig) URL(dbName string) string
URL returns a URL representation of the configuration, connecting to the given database.
func (*ClientConfig) Validate ¶
func (c *ClientConfig) Validate() error
Validate validates the client configuration, returning an error if there's a problem.
type DatabaseDriverFunc ¶
DatabaseDriverFunc returns the driver name for the given database name.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option sets options on a kvdb server.
func AddHandler ¶
AddHandler adds the given handler to the server.
func DatabaseDriver ¶
func DatabaseDriver(f DatabaseDriverFunc) Option
DatabaseDriver sets the database driver function for the server.
func MaxMessageSize ¶
MaxMessageSize sets the maximum message size (in bytes) the server can receive.
func ReadBufferSize ¶
ReadBufferSize sets the size of the read buffer (in bytes).
func SSLCertAndKey ¶
SSLCertAndKey adds the given SSL public certificate and private key to the server.
func WriteBufferSize ¶
WriteBufferSize sets the size of the write buffer (in bytes).