memory

package
v3.4.30+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector struct {
	base.Connector
	// contains filtered or unexported fields
}

Connector is an in-memory connector. The in-memory connector stores its data like this: map[string]map[string][]map[string]dosa.FieldValue

the first 'string' is the table name (entity name) the second 'string' is the partition key, encoded using encoding/gob to guarantee uniqueness within each 'partition' you have a list of rows ([]map[string]dosa.FieldValue) these rows are kept ordered so that reads are lightning fast and searches are quick too the row itself is a map of field name to value (map[string]dosaFieldValue])

A read-write mutex lock is used to control concurrency, making reads work in parallel but writes are not. There is no attempt to improve the concurrency of the read or write path by adding more granular locks.

NOTE: The memory connector doesn't support TTL. All the data is stored in memory until a manual delete.

func NewConnector

func NewConnector() *Connector

NewConnector creates a new in-memory connector

func (*Connector) CheckSchema

func (c *Connector) CheckSchema(ctx context.Context, scope, namePrefix string, ed []*dosa.EntityDefinition) (int32, error)

CheckSchema is just a stub; there is no schema management for the in memory connector since creating a new one leaves you with no data!

func (*Connector) CreateIfNotExists

func (c *Connector) CreateIfNotExists(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error

CreateIfNotExists inserts a row if it isn't already there. The basic flow is: Find the partition, if it's not there, then create it and insert the row there If the partition is there, and there's data in it, and there's no clustering key, then fail Otherwise, search the partition for the exact same clustering keys. If there, fail if not, then insert it at the right spot (sort.Search does most of the heavy lifting here)

func (*Connector) MultiRead

func (c *Connector) MultiRead(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue, minimumFields []string) ([]*dosa.FieldValuesOrError, error)

MultiRead fetches a series of values at once.

func (*Connector) MultiRemove

func (c *Connector) MultiRemove(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) ([]error, error)

MultiRemove removes a series of values at once.

func (*Connector) MultiUpsert

func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue) ([]error, error)

MultiUpsert upserts a series of values at once.

func (*Connector) Range

func (c *Connector) Range(_ context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error)

Range returns a slice of data from the datastore

func (*Connector) Read

func (c *Connector) Read(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue, minimumFields []string) (map[string]dosa.FieldValue, error)

Read searches for a row. First, it finds the partition, then it searches in the partition for the data, and returns it when it finds it. Again, sort.Search does most of the heavy lifting within a partition

func (*Connector) Remove

func (c *Connector) Remove(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error

Remove deletes a single row There's no way to return an error from this method

func (*Connector) RemoveRange

func (c *Connector) RemoveRange(_ context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition) error

RemoveRange removes all of the elements in the range specified by the entity info and the column conditions.

func (*Connector) Scan

func (c *Connector) Scan(_ context.Context, ei *dosa.EntityInfo, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error)

Scan returns all the rows

func (*Connector) Shutdown

func (c *Connector) Shutdown() error

Shutdown deletes all the data

func (*Connector) Upsert

func (c *Connector) Upsert(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error

Upsert works a lot like CreateIfNotExists but merges the data when it finds an existing row

Jump to

Keyboard shortcuts

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