in_mem_table

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEntry = errors.NewKind("unable to update table due to a missing entry")

ErrNoEntry is returned when an entry is required for the DataEditorView to work, however one cannot be found.

Functions

This section is empty.

Types

type Data

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

Data is used for in-memory tables to store their row data in a way that may be quickly retrieved for queries.

func NewData

func NewData(entryReference Entry, primaryKey Key, secondaryKeys []Key) *Data

NewData returns a new *Data. A primary key must be given, with additional keys (secondary) optional. If a key is given, it must not be defined as a pointer type. The given Entry will be used to in the TableEditor to interact with rows.

func (*Data) Clear

func (data *Data) Clear()

Clear removes all entries.

func (*Data) Count

func (data *Data) Count() int64

Count returns this table's number of rows.

func (*Data) Get

func (data *Data) Get(key Key) []Entry

Get returns the entries matching the given key.

func (*Data) Has

func (data *Data) Has(ctx *sql.Context, entry Entry) bool

Has returns whether the given Entry is found in the table.

func (*Data) Put

func (data *Data) Put(ctx *sql.Context, entry Entry) error

Put adds the given Entry to the data.

func (*Data) Remove

func (data *Data) Remove(ctx *sql.Context, key Key, entry Entry) error

Remove will completely remove the given key and/or Entry. If the given key is not nil, then all matching entries are found and removed. If the given Entry is not nil, then only that Entry is removed.

func (*Data) ToRowIter

func (data *Data) ToRowIter(ctx *sql.Context) sql.RowIter

ToRowIter returns a RowIter containing all of this table's entries as rows.

func (*Data) ToSlice

func (data *Data) ToSlice(ctx *sql.Context) []Entry

ToSlice returns a slice containing all of this table's entries.

type DataEditor

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

DataEditor allows for a table to process alteration statements on its data.

func NewDataEditor

func NewDataEditor(data *Data) *DataEditor

NewDataEditor returns a new *DataEditor.

func (*DataEditor) Close

func (editor *DataEditor) Close(ctx *sql.Context) error

Close implements the sql.Closer interface.

func (*DataEditor) Delete

func (editor *DataEditor) Delete(ctx *sql.Context, row sql.Row) error

Delete implements the sql.RowDeleter interface.

func (*DataEditor) DiscardChanges

func (editor *DataEditor) DiscardChanges(ctx *sql.Context, errorEncountered error) error

DiscardChanges implements the sql.TableEditor interface.

func (*DataEditor) Insert

func (editor *DataEditor) Insert(ctx *sql.Context, row sql.Row) error

Insert implements the sql.RowInserter interface.

func (*DataEditor) StatementBegin

func (editor *DataEditor) StatementBegin(ctx *sql.Context)

StatementBegin implements the sql.TableEditor interface.

func (*DataEditor) StatementComplete

func (editor *DataEditor) StatementComplete(ctx *sql.Context) error

StatementComplete implements the sql.TableEditor interface.

func (*DataEditor) Update

func (editor *DataEditor) Update(ctx *sql.Context, old sql.Row, new sql.Row) (retErr error)

Update implements the sql.RowUpdater interface.

type DataEditorConverter

type DataEditorConverter interface {
	// RowToKey converts the given row into a Key. The Key must resolve to only a single entry.
	RowToKey(ctx *sql.Context, row sql.Row) (Key, error)
	// AddRowToEntry adds the given row to the given Entry, returning a new updated Entry. If the row's data already
	// exists, this should return a primary key violation error.
	AddRowToEntry(ctx *sql.Context, row sql.Row, entry Entry) (Entry, error)
	// RemoveRowFromEntry removes the given row from the given Entry, returning a new updated Entry. If the row's data
	// does not exist, the original Entry should be returned as-is since this is not an error.
	RemoveRowFromEntry(ctx *sql.Context, row sql.Row, entry Entry) (Entry, error)
	// EntryToRows converts the given entry to rows.
	EntryToRows(ctx *sql.Context, entry Entry) ([]sql.Row, error)
}

DataEditorConverter handles the conversion of a row intended for one table to be processed on the entry of another table. This is used in the DataEditorView.

type DataEditorView

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

DataEditorView allows for a table to process alteration statements on the data of another table, as though it was its own data. As a consequence, the DataEditorView may not create entirely new entries on the original table, as it may only modify existing ones. This allows for the fields of an entry to appear as entirely new entries for a different table, as this is simply a view into that data. If an Entry does not exist, then ErrNoEntry is returned.

func NewDataEditorView

func NewDataEditorView(data *Data, converter DataEditorConverter) *DataEditorView

NewDataEditorView returns a new *DataEditorView.

func (*DataEditorView) Close

func (editor *DataEditorView) Close(ctx *sql.Context) error

Close implements the sql.Closer interface.

func (*DataEditorView) Delete

func (editor *DataEditorView) Delete(ctx *sql.Context, row sql.Row) (retErr error)

Delete implements the sql.RowDeleter interface.

func (*DataEditorView) DiscardChanges

func (editor *DataEditorView) DiscardChanges(ctx *sql.Context, errorEncountered error) error

DiscardChanges implements the sql.TableEditor interface.

func (*DataEditorView) Insert

func (editor *DataEditorView) Insert(ctx *sql.Context, row sql.Row) (retErr error)

Insert implements the sql.RowInserter interface.

func (*DataEditorView) StatementBegin

func (editor *DataEditorView) StatementBegin(ctx *sql.Context)

StatementBegin implements the sql.TableEditor interface.

func (*DataEditorView) StatementComplete

func (editor *DataEditorView) StatementComplete(ctx *sql.Context) error

StatementComplete implements the sql.TableEditor interface.

func (*DataEditorView) Update

func (editor *DataEditorView) Update(ctx *sql.Context, old sql.Row, new sql.Row) (retErr error)

Update implements the sql.RowUpdater interface.

type Entry

type Entry interface {
	// NewFromRow takes the given row and returns a new instance of the Entry containing the properties of the given row.
	NewFromRow(ctx *sql.Context, row sql.Row) (Entry, error)
	// UpdateFromRow uses the given row to return a new Entry that is based on the calling Entry. This means that any
	// fields that do not have a direct mapping to or from a sql.Row should be preserved on the new Entry.
	UpdateFromRow(ctx *sql.Context, row sql.Row) (Entry, error)
	// ToRow returns this Entry as a sql.Row.
	ToRow(ctx *sql.Context) sql.Row
	// Equals returns whether the calling entry is equivalent to the given entry. Standard struct comparison may work
	// for some entries, however other implementations may have fields that should not be considered when checking for
	// equality, therefore such implementations can make the comparable fields explicit.
	Equals(ctx *sql.Context, otherEntry Entry) bool
	// Copy returns a duplicate of this Entry.
	Copy(ctx *sql.Context) Entry
	// FromJson converts the given string to the calling Entry type. Returns a new Entry.
	FromJson(ctx *sql.Context, jsonStr string) (Entry, error)
	// ToJson converts the calling Entry to a JSON string.
	ToJson(ctx *sql.Context) (string, error)
}

Entry is an entry in Data. It handles conversions to and from a sql.Row, so that the underlying representation does not have to be a sql.Row. As the sql.Row interface is only important in the context of table operations, the data type stored may be of any type as long as it can convert between itself and sql.Row, as well as testing equality against other entries. All rows will match the schema of the parent table.

type Key

type Key interface {
	// KeyFromEntry returns a new key from the given entry. The new key's type is expected to match the calling key's type.
	KeyFromEntry(ctx *sql.Context, entry Entry) (Key, error)
	// KeyFromRow returns a new key from the given sql.Row. The given row will match the schema of the parent table. The
	// new key's type is expected to match the calling key's type.
	KeyFromRow(ctx *sql.Context, row sql.Row) (Key, error)
}

Key represents a key that will be matched in order to retrieve a row. All implementations of this interface must NOT be a pointer, as pointers have different rules for determining equality.

Jump to

Keyboard shortcuts

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