keyvaluelib

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: CC0-1.0, CC0-1.0, CC0-1.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConditionArg

func ConditionArg(c *rt.GoCont, n int) (condition.Condition, error)

ConditionArg turns a continuation argument into a condition.Condition.

func QueryArg

func QueryArg(c *rt.GoCont, n int) (*parse.Query, error)

QueryArg turns a continuation argument into a parse.Query.

func RecordArg

func RecordArg(c *rt.GoCont, n int) (record.Record, error)

RecordArg turns a continuation argument into a record.Record.

func RecordToTable

func RecordToTable(r record.Record) *rt.Table

RecordToTable converts the given record.Record to a lua table.

func Register

func Register(name string, f func() *rt.Table)

Register registers the given function that returns a table to be added to the package table using the given name (typically a name of a keyvalue driver). If a function is already registered with the given name then it will be replaced; if the name coincides with one of the package functions or values then it will be overwritten. Note that any function registered after the package is loaded into the Lua runtime will not appear in that instance of the package.

func TableToRecord

func TableToRecord(t *rt.Table) (record.Record, error)

TableToRecord converts the given lua table to a record.Record.

func ValueToCondition

func ValueToCondition(v rt.Value) (condition.Condition, bool)

ValueToCondition turns a lua value to a condition.Condition, if possible.

func ValueToQuery

func ValueToQuery(v rt.Value) (*parse.Query, bool)

ValueToQuery turns a lua value to a *parse.Query, if possible.

func ValueToRecord

func ValueToRecord(v rt.Value) (record.Record, bool)

ValueToRecord turns a lua value to a record.Record, if possible.

func WrapConnectFunc

func WrapConnectFunc(f func(*rt.Thread, *rt.GoCont) (string, error)) func(*rt.Thread, *rt.GoCont) (rt.Cont, error)

WrapConnectFunc wraps the given function so that the returned datasource is opened and returned as a Connection.

Types

type Connection

type Connection struct {
	log.Logable
	metrics.Metricsable
	// contains filtered or unexported fields
}

Connection wraps a keyvalue.Connection.

func ConnectionArg

func ConnectionArg(c *rt.GoCont, n int) (*Connection, error)

ConnectionArg turns a continuation argument into a *Connection.

func ValueToConnection

func ValueToConnection(v rt.Value) (*Connection, bool)

ValueToConnection turns a lua value to a *Connection, if possible.

func (*Connection) Close

func (conn *Connection) Close() error

Close prevents any further queries through this connection.

func (*Connection) ConnectToTable

func (conn *Connection) ConnectToTable(ctx context.Context, name string) (*Table, error)

ConnectToTable connects to the indicated table in the database. A finaliser is set on the table to ensure that it is closed.

func (*Connection) CreateTable

func (conn *Connection) CreateTable(ctx context.Context, 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 (*Connection) DataSource

func (conn *Connection) DataSource() string

DataSource returns the data source string used to establish the connection. Note that this may contain sensitive user data such as a password.

func (*Connection) DeleteTable

func (conn *Connection) DeleteTable(ctx context.Context, name string) error

DeleteTable deletes the indicated table from the database. Does not return an error if the table does not exist.

func (*Connection) DriverName

func (conn *Connection) DriverName() string

DriverName returns the name of the associated driver.

func (*Connection) GetTimeout

func (conn *Connection) GetTimeout() time.Duration

GetTimeout returns the timeout.

func (*Connection) IsClosed

func (conn *Connection) IsClosed() bool

IsClosed returns true iff the connection is closed.

func (*Connection) ListTables

func (conn *Connection) ListTables(ctx context.Context) ([]string, error)

ListTables returns the names of the tables in the database. The names are sorted in increasing order.

func (*Connection) SetTimeout

func (conn *Connection) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout. A negative timeout is interpreted to mean no timeout.

func (*Connection) String

func (conn *Connection) String() string

String returns a string description of the connection.

type Cursor

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

Cursor describes a stream of records as given by a record.Iterator.

func CursorArg

func CursorArg(c *rt.GoCont, n int) (*Cursor, error)

CursorArg turns a continuation argument into a *Cursor.

func NewCursor

func NewCursor(itr record.Iterator) *Cursor

NewCursor wraps the given record.Iterator as a cursor. A finaliser is set of the cursor to ensure that it is closed.

func ValueToCursor

func ValueToCursor(v rt.Value) (*Cursor, bool)

ValueToCursor turns a lua value to a *Cursor, if possible.

func (*Cursor) Advance

func (cur *Cursor) Advance(ctx context.Context) (r record.Record, err error)

Advance advances the cursor. If the end of the cursor is reached, this will return io.EOF.

func (*Cursor) Buffered

func (cur *Cursor) Buffered() bool

Buffered returns true iff the next call to Advance is guaranteed not to block.

func (*Cursor) Close

func (cur *Cursor) Close() error

Close closes the cursor.

func (*Cursor) GetTimeout

func (cur *Cursor) GetTimeout() time.Duration

GetTimeout returns the timeout.

func (*Cursor) IsClosed

func (cur *Cursor) IsClosed() bool

IsClosed returns true iff the cursor is closed.

func (*Cursor) SetTimeout

func (cur *Cursor) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout. A negative timeout is interpreted to mean no timeout.

func (*Cursor) String

func (cur *Cursor) String() string

String returns a string representation of a cursor.

type Table

type Table struct {
	log.Logger
	metrics.Metricser
	// contains filtered or unexported fields
}

Table wraps a keyvalue.Table.

func NewTable

func NewTable(t *keyvalue.Table) *Table

NewTable wraps the given keyvalue.Table as a Table. A finaliser is set on the table to ensure that it is closed.

func TableArg

func TableArg(c *rt.GoCont, n int) (*Table, error)

TableArg turns a continuation argument into a *Table.

func ValueToTable

func ValueToTable(v rt.Value) (*Table, bool)

ValueToTable turns a lua value to a *Table, if possible.

func (*Table) Close

func (t *Table) Close() error

Close closes the connection to the table.

func (*Table) Count

func (t *Table) Count(ctx context.Context, selector record.Record) (int64, error)

Count returns the number of records in the table that match "selector".

func (*Table) CountWhere

func (t *Table) CountWhere(ctx context.Context, cond condition.Condition) (int64, error)

CountWhere returns the number of records in the table that satisfy condition "cond" (which may be nil if there are no conditions).

func (*Table) Delete

func (t *Table) Delete(ctx context.Context, selector record.Record) (int64, error)

Delete deletes those records in the table that match "selector". Returns the number of records deleted.

func (*Table) DeleteWhere

func (t *Table) DeleteWhere(ctx context.Context, cond condition.Condition) (int64, error)

DeleteWhere deletes those records in the table that satisfy condition "cond" (which may be nil if there are no conditions). Returns the number of records deleted.

func (*Table) Describe

func (t *Table) Describe(ctx context.Context) (record.Record, error)

Describe returns a best-guess template for the data in this 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 (*Table) GetTimeout

func (t *Table) GetTimeout() time.Duration

GetTimeout returns the timeout.

func (*Table) Insert

func (t *Table) Insert(ctx context.Context, itr record.Iterator) error

Insert inserts the records in the given iterator into the table.

func (*Table) InsertRecords

func (t *Table) InsertRecords(ctx context.Context, records ...record.Record) error

InsertRecords inserts the given records into the table.

func (*Table) IsClosed

func (t *Table) IsClosed() bool

IsClosed returns true iff the connection to the table is closed.

func (*Table) Name

func (t *Table) Name() string

Name return the table name.

func (*Table) Select

func (t *Table) Select(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy) (record.Iterator, error)

Select returns the records matching "selector", 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 (*Table) SelectLimit

func (t *Table) SelectLimit(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy, n int64) (record.Iterator, error)

SelectLimit returns at most n records matching "selector", 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 (*Table) SelectOne

func (t *Table) SelectOne(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy) (record.Record, error)

SelectOne returns the first record matching "selector", sorted as specified by "order" (which may be nil if there is no sort order required). The returned record will be in the form specified by "template". If no records match, then a nil record will be returned.

func (*Table) SelectOneWhere

func (t *Table) SelectOneWhere(ctx context.Context, template record.Record, cond condition.Condition, order sort.OrderBy) (record.Record, error)

SelectOneWhere returns the first record 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 record will be in the form specified by "template". If no records match, then a nil record will be returned.

func (*Table) SelectWhere

func (t *Table) SelectWhere(ctx context.Context, 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 (*Table) SelectWhereLimit

func (t *Table) SelectWhereLimit(ctx context.Context, template record.Record, cond condition.Condition, order sort.OrderBy, n int64) (record.Iterator, error)

SelectWhereLimit returns at most n 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 (*Table) SetTimeout

func (t *Table) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout. A negative timeout is interpreted to mean no timeout.

func (*Table) String

func (t *Table) String() string

String returns a string description of the table.

func (*Table) Update

func (t *Table) Update(ctx context.Context, replacement record.Record, selector record.Record) (int64, error)

Update updates all records in the table that match "selector" by setting all keys present in "replacement" to the given values. Returns the number of records updated.

func (*Table) UpdateWhere

func (t *Table) UpdateWhere(ctx context.Context, replacement record.Record, cond condition.Condition) (int64, error)

UpdateWhere updates all records in the table that satisfy condition "cond" (which may be nil if there are no conditions) by setting all keys present in "replacement" to the given values. Returns the number of records updated.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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