database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 13 Imported by: 6

Documentation

Overview

Package database

The Database interface for RDBMS wrapper implementations

Package database

General interface for distributed cache and data structure store (e.g. Redis)

Copyright 2022. Motty Cohen

Database interface for NoSQL Big Data wrapper implementations

Copyright 2022. Motty Cohen

In-memory database implementation of IQuery (used for testing)

Copyright 2022. Motty Cohen

In-memory database query helpers (used for testing)

Copyright 2022. Motty Cohen

In-memory datastore implementation of IDatabase (used for testing)

Copyright 2022. Motty Cohen

In-memory datastore implementation of IQuery (used for testing)

Copyright 2022. Motty Cohen

Database Query interface

Copyright 2022. Motty Cohen

Database Query filter

Copyright 2022. Motty Cohen

Database Query operator

Index

Constants

View Source
const (
	NOT_IMPLEMENTED  = "not implemented"
	NOT_SUPPORTED    = "not supported"
	TABLE_NOT_EXISTS = "table does not exist"
)
View Source
const (
	Eq       QueryOperator = "="
	Neq                    = "!"
	Like                   = "~"
	Gt                     = ">"
	Gte                    = ">="
	Lt                     = "<"
	Lte                    = "<="
	In                     = "*"
	NotIn                  = "-"
	Between                = "#"
	Contains               = "@"
)
View Source
const (
	INDEX_NOT_EXISTS = "index does not exist"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterFunction

type FilterFunction func(raw map[string]any, filter QueryFilter) bool

Signature of a filter function

type IDataCache

type IDataCache interface {

	// Test connectivity for retries number of time with time interval (in seconds) between retries
	Ping(retries uint, intervalInSeconds uint) error

	// Close cache and free resources
	Close()

	// Get the value of a key
	Get(factory EntityFactory, key string) (result Entity, err error)

	// Set value of key with expiration
	Set(key string, entity Entity) (err error)

	// Delete keys
	Del(keys ...string) (err error)

	// Get the value of all the given keys
	MGet(factory EntityFactory, keys ...string) (results []Entity, err error)

	// Set the value of a key only if the key does not exist
	SetNX(key string, entity Entity, expiration time.Duration) (result bool, err error)

	// Set object value to a key with expiration
	SetWithExp(key string, entity Entity, expiration time.Duration) (err error)

	// Rename a key
	Rename(key string, newKey string) (err error)

	// Scan keys from the provided cursor
	Scan(from uint64, match string, count int64) (keys []string, cursor uint64, err error)

	// Check if key exists
	Exists(key string) (result bool, err error)

	// Get the value of a hash field
	HGet(factory EntityFactory, key, field string) (result Entity, err error)

	// Get all the fields in a hash
	HKeys(key string) (fields []string, err error)

	// Get all the fields and values in a hash
	HGetAll(factory EntityFactory, key string) (result map[string]Entity, err error)

	// Set the value of a hash field
	HSet(key, field string, entity Entity) (err error)

	// Delete one or more hash fields
	HDel(key string, fields ...string) (err error)

	// Set the value of a key only if the key does not exist
	HSetNX(key, field string, entity Entity) (result bool, err error)

	// Check if key exists
	HExists(key, field string) (result bool, err error)

	// Append one or multiple values to a list
	RPush(key string, value ...Entity) (err error)

	// Prepend one or multiple values to a list
	LPush(key string, value ...Entity) (err error)

	// Remove and get the last element in a list
	RPop(factory EntityFactory, key string) (entity Entity, err error)

	// Remove and get the first element in a list
	LPop(factory EntityFactory, key string) (entity Entity, err error)

	// Remove and get the last element in a list or block until one is available
	BRPop(factory EntityFactory, timeout time.Duration, keys ...string) (key string, entity Entity, err error)

	// Remove and get the first element in a list or block until one is available
	BLPop(factory EntityFactory, timeout time.Duration, keys ...string) (key string, entity Entity, err error)

	// Get a range of elements from list
	LRange(factory EntityFactory, key string, start, stop int64) (result []Entity, err error)

	// Get the length of a list
	LLen(key string) (result int64)
}

DataCache interface

func NewInMemoryDataCache

func NewInMemoryDataCache() (dc IDataCache, err error)

*

  • Factory method for DB store

type IDatabase

type IDatabase interface {

	// Ping Test database connectivity for retries number of time with time interval (in seconds) between retries
	Ping(retries uint, intervalInSeconds uint) error

	// Get a single entity by ID
	Get(factory EntityFactory, entityID string, keys ...string) (result Entity, err error)

	// List Get multiple entities by IDs
	List(factory EntityFactory, entityIDs []string, keys ...string) (list []Entity, err error)

	// Exists Check if entity exists by ID
	Exists(factory EntityFactory, entityID string, keys ...string) (result bool, err error)

	// Insert new entity
	Insert(entity Entity) (added Entity, err error)

	// Update existing entity
	Update(entity Entity) (updated Entity, err error)

	// Upsert Update entity or create it if it does not exist
	Upsert(entity Entity) (updated Entity, err error)

	// Delete entity by id and shard (key)
	Delete(factory EntityFactory, entityID string, keys ...string) (err error)

	// BulkInsert Insert multiple entities
	BulkInsert(entities []Entity) (affected int64, err error)

	// BulkUpdate Update multiple entities
	BulkUpdate(entities []Entity) (affected int64, err error)

	// BulkUpsert Update or insert multiple entities
	BulkUpsert(entities []Entity) (affected int64, err error)

	// BulkDelete Delete multiple entities by IDs
	BulkDelete(factory EntityFactory, entityIDs []string, keys ...string) (affected int64, err error)

	// SetField Update single field of the document in a single transaction (eliminates the need to fetch - change - update)
	SetField(factory EntityFactory, entityID string, field string, value any, keys ...string) (err error)

	// SetFields Update some fields of the document in a single transaction (eliminates the need to fetch - change - update)
	SetFields(factory EntityFactory, entityID string, fields map[string]any, keys ...string) (err error)

	// Query Utility struct method to build a query
	Query(factory EntityFactory) IQuery

	// Close DB and free resources
	Close()

	// ExecuteDDL Execute DDL - create table and indexes
	ExecuteDDL(ddl map[string][]string) (err error)

	// ExecuteSQL Execute SQL - execute SQL command
	ExecuteSQL(sql string, args ...any) (affected int64, err error)

	// DropTable Drop table and indexes
	DropTable(table string) (err error)

	// PurgeTable Fast delete table content (truncate)
	PurgeTable(table string) (err error)
}

IDatabase Database interface

func NewInMemoryDatabase

func NewInMemoryDatabase() (dbs IDatabase, err error)

*

  • Factory method for DB store

type IDatastore

type IDatastore interface {

	// Test database connectivity for retries number of time with time interval (in seconds) between retries
	Ping(retries uint, intervalInSeconds uint) error

	// Get single entity by ID
	Get(factory EntityFactory, entityID string, keys ...string) (result Entity, err error)

	// Get multiple entities by IDs
	List(factory EntityFactory, entityIDs []string, keys ...string) (list []Entity, err error)

	// Check if entity exists by ID
	Exists(factory EntityFactory, entityID string, keys ...string) (result bool, err error)

	// Insert new entity
	Insert(entity Entity) (added Entity, err error)

	// Update existing entity
	Update(entity Entity) (updated Entity, err error)

	// Update entity or create it if it does not exist
	Upsert(entity Entity) (updated Entity, err error)

	// Delete entity by id and shard (key)
	Delete(factory EntityFactory, entityID string, keys ...string) (err error)

	// Insert multiple entities
	BulkInsert(entities []Entity) (affected int64, err error)

	// Update multiple entities
	BulkUpdate(entities []Entity) (affected int64, err error)

	// Update or insert multiple entities
	BulkUpsert(entities []Entity) (affected int64, err error)

	// Delete multiple entities by IDs
	BulkDelete(factory EntityFactory, entityIDs []string, keys ...string) (affected int64, err error)

	// Update single field of the document in a single transaction (eliminates the need to fetch - change - update)
	SetField(factory EntityFactory, entityID string, field string, value any, keys ...string) (err error)

	// Update some fields of the document in a single transaction (eliminates the need to fetch - change - update)
	SetFields(factory EntityFactory, entityID string, fields map[string]any, keys ...string) (err error)

	// Utility struct method to build a query
	Query(factory EntityFactory) IQuery

	// Close DB and free resources
	Close()

	// Index Actions ---------------------------------------------------------------------------------------------------
	// Test if index exists
	IndexExists(indexName string) (exists bool)

	// Create index by name (without mapping)
	CreateIndex(indexName string) (name string, err error)

	// Create index of entity and add entity field mapping
	CreateEntityIndex(factory EntityFactory, key string) (name string, err error)

	// Drop index
	DropIndex(indexName string) (ack bool, err error)
}

Datastore interface

func NewInMemoryDatastore

func NewInMemoryDatastore() (dbs IDatastore, err error)

*

  • Factory method for Datastore

type IQuery

type IQuery interface {

	// Add callback to apply on each result entity in the query
	Apply(cb func(in Entity) Entity) IQuery

	// Add single field filter
	Filter(filter QueryFilter) IQuery

	// Add list of filters, all of them should be satisfied (AND)
	MatchAll(filters ...QueryFilter) IQuery

	// Add list of filters, any of them should be satisfied (OR)
	MatchAny(filters ...QueryFilter) IQuery

	// Add sort order by field,  expects sort parameter in the following form: field_name (Ascending) or field_name- (Descending)
	Sort(sort string) IQuery

	// Set page number (for pagination)
	Page(page int) IQuery

	// Set page size limit (for pagination)
	Limit(page int) IQuery

	// Execute a query to get list of entities by IDs (the criteria is ignored)
	List(entityIDs []string, keys ...string) (out []Entity, err error)

	// Execute the query based on the criteria, order and pagination
	Find(keys ...string) (out []Entity, total int64, err error)

	// Execute the query based on the criteria, order and pagination and return only the count of matching rows
	Count(keys ...string) (total int64, err error)

	// Execute query based on the where criteria to get a single (the first) result
	FindSingle(keys ...string) (entity Entity, err error)

	// Execute query based on the criteria, order and pagination and return the results as a map of id->Entity
	GetMap(keys ...string) (out map[string]Entity, err error)

	// Execute query based on the where criteria, order and pagination and return the results as a list of Ids
	GetIds(keys ...string) (out []string, err error)

	// Delete the entities satisfying the criteria
	Delete(keys ...string) (total int64, err error)

	// Update single field of all the documents meeting the criteria in a single transaction
	SetField(field string, value any, keys ...string) (total int64, err error)

	// Update multiple fields of all the documents meeting the criteria in a single transaction
	SetFields(fields map[string]any, keys ...string) (total int64, err error)

	// Get the string representation of the query
	ToString() string
}

Database Query interface

type ITable

type ITable interface {

	// Get single entity by ID
	Get(entityID string) (entity Entity, err error)

	// Check if entity exists by ID
	Exists(entityID string) (result bool, err error)

	// Insert entity
	Insert(entity Entity) (added Entity, err error)

	// Update entity
	Update(entity Entity) (added Entity, err error)

	// Update entity or insert if not found
	Upsert(entity Entity) (added Entity, err error)

	// Delete entity
	Delete(entityID string) (err error)

	// Get access to the underlying data structure
	Table() (result map[string]Entity)
}

Database table interface

func NewInMemTable

func NewInMemTable() ITable

type InMemoryDataCache

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

Represent in memory data cache

func (*InMemoryDataCache) BLPop

func (dc *InMemoryDataCache) BLPop(factory EntityFactory, timeout time.Duration, keys ...string) (key string, entity Entity, err error)

Remove and get the first element in a list or block until one is available

func (*InMemoryDataCache) BRPop

func (dc *InMemoryDataCache) BRPop(factory EntityFactory, timeout time.Duration, keys ...string) (key string, value Entity, err error)

Remove and get the last element in a list or block until one is available

func (*InMemoryDataCache) Close

func (dc *InMemoryDataCache) Close()

*

  • Close cache and free resources

func (*InMemoryDataCache) Del

func (dc *InMemoryDataCache) Del(keys ...string) (err error)

Delete keys

func (*InMemoryDataCache) Exists

func (dc *InMemoryDataCache) Exists(key string) (result bool, err error)

Check if key exists

func (*InMemoryDataCache) Get

func (dc *InMemoryDataCache) Get(factory EntityFactory, key string) (result Entity, err error)

Get the value of a key

func (*InMemoryDataCache) HDel

func (dc *InMemoryDataCache) HDel(key string, fields ...string) (err error)

Delete one or more hash fields

func (*InMemoryDataCache) HExists

func (dc *InMemoryDataCache) HExists(key, field string) (result bool, err error)

Check if key exists

func (*InMemoryDataCache) HGet

func (dc *InMemoryDataCache) HGet(factory EntityFactory, key, field string) (result Entity, err error)

Get the value of a hash field

func (*InMemoryDataCache) HGetAll

func (dc *InMemoryDataCache) HGetAll(factory EntityFactory, key string) (result map[string]Entity, err error)

Get all the fields and values in a hash

func (*InMemoryDataCache) HKeys

func (dc *InMemoryDataCache) HKeys(key string) (fields []string, err error)

Get all the fields in a hash

func (*InMemoryDataCache) HSet

func (dc *InMemoryDataCache) HSet(key, field string, entity Entity) (err error)

Set the value of a hash field

func (*InMemoryDataCache) HSetNX

func (dc *InMemoryDataCache) HSetNX(key, field string, entity Entity) (result bool, err error)

Set the value of a key only if the key does not exist

func (*InMemoryDataCache) LLen

func (dc *InMemoryDataCache) LLen(key string) (result int64)

Get the length of a list

func (*InMemoryDataCache) LPop

func (dc *InMemoryDataCache) LPop(factory EntityFactory, key string) (entity Entity, err error)

Remove and get the first element in a list

func (*InMemoryDataCache) LPush

func (dc *InMemoryDataCache) LPush(key string, value ...Entity) (err error)

Prepend (add to the left) one or multiple values to a list

func (*InMemoryDataCache) LRange

func (dc *InMemoryDataCache) LRange(factory EntityFactory, key string, start, stop int64) (result []Entity, err error)

Get a range of elements from list

func (*InMemoryDataCache) MGet

func (dc *InMemoryDataCache) MGet(factory EntityFactory, keys ...string) (results []Entity, err error)

Get the value of all the given keys

func (*InMemoryDataCache) Ping

func (dc *InMemoryDataCache) Ping(retries uint, interval uint) error

*

  • Test cache connectivity
  • @param retries - how many retries are required (max 10)
  • @param interval - time interval (in seconds) between retries (max 60)

func (*InMemoryDataCache) RPop

func (dc *InMemoryDataCache) RPop(factory EntityFactory, key string) (entity Entity, err error)

Remove and get the last element in a list

func (*InMemoryDataCache) RPush

func (dc *InMemoryDataCache) RPush(key string, value ...Entity) (err error)

Append (add to the right) one or multiple values to a list

func (*InMemoryDataCache) Rename

func (dc *InMemoryDataCache) Rename(key string, newKey string) (err error)

Rename a key

func (*InMemoryDataCache) Scan

func (dc *InMemoryDataCache) Scan(from uint64, match string, count int64) (keys []string, cursor uint64, err error)

Scan keys from the provided cursor

func (*InMemoryDataCache) Set

func (dc *InMemoryDataCache) Set(key string, entity Entity) (err error)

Set value of key with expiration

func (*InMemoryDataCache) SetNX

func (dc *InMemoryDataCache) SetNX(key string, entity Entity, expiration time.Duration) (result bool, err error)

Set the value of a key only if the key does not exist

func (*InMemoryDataCache) SetWithExp

func (dc *InMemoryDataCache) SetWithExp(key string, entity Entity, expiration time.Duration) (err error)

Set object value to a key with expiration

type InMemoryDatabase

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

Represent a db with tables

func (*InMemoryDatabase) BulkDelete

func (dbs *InMemoryDatabase) BulkDelete(factory EntityFactory, entityIDs []string, keys ...string) (affected int64, err error)

*

  • Delete multiple entities by id list

func (*InMemoryDatabase) BulkInsert

func (dbs *InMemoryDatabase) BulkInsert(entities []Entity) (affected int64, err error)

*

  • Add multiple entities to data store (all must be of the same type)

func (*InMemoryDatabase) BulkUpdate

func (dbs *InMemoryDatabase) BulkUpdate(entities []Entity) (affected int64, err error)

*

  • Update multiple entities in the data store (all must be of the same type)

func (*InMemoryDatabase) BulkUpsert

func (dbs *InMemoryDatabase) BulkUpsert(entities []Entity) (affected int64, err error)

*

  • Update or insert multiple entities in the data store (all must be of the same type)

func (*InMemoryDatabase) Close

func (dbs *InMemoryDatabase) Close()

*

  • Close DB and free resources

func (*InMemoryDatabase) Delete

func (dbs *InMemoryDatabase) Delete(factory EntityFactory, entityID string, keys ...string) (err error)

*

  • Delete entity by id

func (*InMemoryDatabase) DropTable

func (dbs *InMemoryDatabase) DropTable(table string) (err error)

*

  • Drop table and indexes

func (*InMemoryDatabase) ExecuteDDL

func (dbs *InMemoryDatabase) ExecuteDDL(ddl map[string][]string) (err error)

*

  • Execute DDL - create table and indexes
  • The ddl parameter is a map of strings (table names) to array of strings (list of fields to index)

func (*InMemoryDatabase) ExecuteSQL

func (dbs *InMemoryDatabase) ExecuteSQL(sql string, args ...any) (affected int64, err error)

*

  • Execute SQL command

func (*InMemoryDatabase) Exists

func (dbs *InMemoryDatabase) Exists(factory EntityFactory, entityID string, keys ...string) (result bool, err error)

*

  • Check if entity exists by ID

func (*InMemoryDatabase) Get

func (dbs *InMemoryDatabase) Get(factory EntityFactory, entityID string, keys ...string) (result Entity, err error)

*

  • Get single entity by ID

func (*InMemoryDatabase) Insert

func (dbs *InMemoryDatabase) Insert(entity Entity) (added Entity, err error)

*

  • Add new entity

func (*InMemoryDatabase) List

func (dbs *InMemoryDatabase) List(factory EntityFactory, entityIDs []string, keys ...string) (list []Entity, err error)

*

  • Get list of entities by IDs

func (*InMemoryDatabase) Ping

func (dbs *InMemoryDatabase) Ping(retries uint, interval uint) error

*

  • Test database connectivity
  • @param retries - how many retries are required (max 10)
  • @param interval - time interval (in seconds) between retries (max 60)

func (*InMemoryDatabase) PurgeTable

func (dbs *InMemoryDatabase) PurgeTable(table string) (err error)

*

  • Fast delete table content (truncate)

func (*InMemoryDatabase) Query

func (dbs *InMemoryDatabase) Query(factory EntityFactory) IQuery

*

  • Helper method to construct query

func (*InMemoryDatabase) SetField

func (dbs *InMemoryDatabase) SetField(factory EntityFactory, entityID string, field string, value any, keys ...string) (err error)

*

  • Update single field of the document in a single transaction (eliminates the need to fetch - change - update)

func (*InMemoryDatabase) SetFields

func (dbs *InMemoryDatabase) SetFields(factory EntityFactory, entityID string, fields map[string]any, keys ...string) (err error)

*

  • Update some numeric fields of the document in a single transaction (eliminates the need to fetch - change - update)

func (*InMemoryDatabase) Update

func (dbs *InMemoryDatabase) Update(entity Entity) (updated Entity, err error)

*

  • Update existing entity in the data store

func (*InMemoryDatabase) Upsert

func (dbs *InMemoryDatabase) Upsert(entity Entity) (updated Entity, err error)

*

  • Update existing entity in the data store or add it if it does not exist

type InMemoryDatastore

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

Represent a db with tables

func (*InMemoryDatastore) BulkDelete

func (dbs *InMemoryDatastore) BulkDelete(factory EntityFactory, entityIDs []string, keys ...string) (affected int64, err error)

*

  • Delete multiple entities by id list

func (*InMemoryDatastore) BulkInsert

func (dbs *InMemoryDatastore) BulkInsert(entities []Entity) (affected int64, err error)

*

  • Add multiple entities to data store (all must be of the same type)

func (*InMemoryDatastore) BulkUpdate

func (dbs *InMemoryDatastore) BulkUpdate(entities []Entity) (affected int64, err error)

*

  • Update multiple entities in the data store (all must be of the same type)

func (*InMemoryDatastore) BulkUpsert

func (dbs *InMemoryDatastore) BulkUpsert(entities []Entity) (affected int64, err error)

*

  • Update or insert multiple entities in the data store (all must be of the same type)

func (*InMemoryDatastore) Close

func (dbs *InMemoryDatastore) Close()

*

  • Close Datastore and free resources

func (*InMemoryDatastore) CreateEntityIndex

func (dbs *InMemoryDatastore) CreateEntityIndex(factory EntityFactory, key string) (name string, err error)

*

  • Create index of entity and add entity field mapping

func (*InMemoryDatastore) CreateIndex

func (dbs *InMemoryDatastore) CreateIndex(indexName string) (name string, err error)

*

  • Create index by name

func (*InMemoryDatastore) Delete

func (dbs *InMemoryDatastore) Delete(factory EntityFactory, entityID string, keys ...string) (err error)

*

  • Delete entity by id

func (*InMemoryDatastore) DropIndex

func (dbs *InMemoryDatastore) DropIndex(indexName string) (ack bool, err error)

*

  • Drop index

func (*InMemoryDatastore) Exists

func (dbs *InMemoryDatastore) Exists(factory EntityFactory, entityID string, keys ...string) (result bool, err error)

*

  • Check if entity exists by ID

func (*InMemoryDatastore) Get

func (dbs *InMemoryDatastore) Get(factory EntityFactory, entityID string, keys ...string) (result Entity, err error)

*

  • Get single entity by ID

func (*InMemoryDatastore) IndexExists

func (dbs *InMemoryDatastore) IndexExists(indexName string) (exists bool)

*

  • Test if index exists

func (*InMemoryDatastore) Insert

func (dbs *InMemoryDatastore) Insert(entity Entity) (added Entity, err error)

*

  • Add new entity

func (*InMemoryDatastore) List

func (dbs *InMemoryDatastore) List(factory EntityFactory, entityIDs []string, keys ...string) (list []Entity, err error)

*

  • Get list of entities by IDs

func (*InMemoryDatastore) Ping

func (dbs *InMemoryDatastore) Ping(retries uint, interval uint) error

*

  • Test connectivity for retries number of time with time interval (in seconds) between retries
  • @param retries - how many retries are required (max 10)
  • @param interval - time interval (in seconds) between retries (max 60)

func (*InMemoryDatastore) Query

func (dbs *InMemoryDatastore) Query(factory EntityFactory) IQuery

*

  • Helper method to construct query

func (*InMemoryDatastore) SetField

func (dbs *InMemoryDatastore) SetField(factory EntityFactory, entityID string, field string, value any, keys ...string) (err error)

*

  • Update single field of the document in a single transaction (eliminates the need to fetch - change - update)

func (*InMemoryDatastore) SetFields

func (dbs *InMemoryDatastore) SetFields(factory EntityFactory, entityID string, fields map[string]any, keys ...string) (err error)

*

  • Update some numeric fields of the document in a single transaction (eliminates the need to fetch - change - update)

func (*InMemoryDatastore) Update

func (dbs *InMemoryDatastore) Update(entity Entity) (updated Entity, err error)

*

  • Update existing entity in the data store

func (*InMemoryDatastore) Upsert

func (dbs *InMemoryDatastore) Upsert(entity Entity) (updated Entity, err error)

*

  • Update existing entity in the data store or add it if it does not exist

type InMemoryTable

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

Represent a table in the DB

func (*InMemoryTable) Delete

func (tbl *InMemoryTable) Delete(entityID string) (err error)

Delete entity

func (*InMemoryTable) Exists

func (tbl *InMemoryTable) Exists(entityID string) (result bool, err error)

Check if entity exists by ID

func (*InMemoryTable) Get

func (tbl *InMemoryTable) Get(entityID string) (entity Entity, err error)

Get single entity by ID

func (*InMemoryTable) Insert

func (tbl *InMemoryTable) Insert(entity Entity) (added Entity, err error)

Insert entity

func (*InMemoryTable) Table

func (tbl *InMemoryTable) Table() (result map[string]Entity)

Get access to the underlying data structure

func (*InMemoryTable) Update

func (tbl *InMemoryTable) Update(entity Entity) (added Entity, err error)

Update entity

func (*InMemoryTable) Upsert

func (tbl *InMemoryTable) Upsert(entity Entity) (added Entity, err error)

Update entity or insert if not found

type QueryFilter

type QueryFilter interface {

	// Equal
	Eq(value any) QueryFilter

	// Not equal
	Neq(value any) QueryFilter

	// Like
	Like(value string) QueryFilter

	// Greater
	Gt(value any) QueryFilter

	// Greater or equal
	Gte(value any) QueryFilter

	// Less than
	Lt(value any) QueryFilter

	// Less or equal
	Lte(value any) QueryFilter

	// In
	In(values ...any) QueryFilter

	// Not In
	NotIn(values ...any) QueryFilter

	// Between
	Between(value1, value2 any) QueryFilter

	// Include this filter only if condition is true
	If(value bool) QueryFilter

	// Include this filter only if condition is true
	IsActive() bool

	// Get the field name
	GetField() string

	// Get the criteria operator
	GetOperator() QueryOperator

	// Get the criteria values
	GetValues() []any

	// Get string representation of the value
	GetStringValue(index int) string
}

Query filter interface

func Filter

func Filter(field string) QueryFilter

Filter by field

type QueryOperator

type QueryOperator string

Jump to

Keyboard shortcuts

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