sidecardb

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultName = "_vt"

	StatsKeyPrefix     = "SidecarDBDDL"
	StatsKeyQueryCount = StatsKeyPrefix + "QueryCount"
	StatsKeyErrorCount = StatsKeyPrefix + "ErrorCount"
	StatsKeyErrors     = StatsKeyPrefix + "Errors"
)

Variables

This section is empty.

Functions

func AddSchemaInitQueries

func AddSchemaInitQueries(db *fakesqldb.DB, populateTables bool)

AddSchemaInitQueries adds sidecar database schema related queries to a mock db. This is for unit tests only!

func GetCreateQuery added in v0.17.0

func GetCreateQuery() string

GetCreateQuery returns the CREATE DATABASE SQL statement used to create the sidecar database.

func GetIdentifier added in v0.17.0

func GetIdentifier() string

GetIdentifier returns the sidecar database name as an SQL identifier string, most importantly this means that it will be properly escaped if/as needed.

func GetIdentifierForKeyspace added in v0.17.0

func GetIdentifierForKeyspace(keyspace string) (string, error)

GetIdentifierForKeyspace is a convenience function -- combining GetIdentifierCache() and IdentifierCache.Get(keyspace) -- which returns the sidecar database identifier as an sqlparser string for the provided keyspace.

func GetName added in v0.17.0

func GetName() string

func Init

func Init(ctx context.Context, exec Exec) error

Init creates or upgrades the sidecar database based on the declarative schema defined for all tables.

func MatchesInitQuery

func MatchesInitQuery(query string) bool

MatchesInitQuery returns true if the query has one of the test patterns as a substring or it matches a provided regexp. This is for unit tests only!

func SetName added in v0.17.0

func SetName(name string)

Types

type Exec

type Exec func(ctx context.Context, query string, maxRows int, useDB bool) (*sqltypes.Result, error)

Exec is a callback that has to be passed to Init() to execute the specified query within the database.

type IdentifierCache added in v0.17.0

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

IdentifierCache provides a read through cache of sidecar database identifiers; loading the values from an opaque backend database using a provided load function.

func GetIdentifierCache added in v0.17.0

func GetIdentifierCache() (*IdentifierCache, error)

func NewIdentifierCache added in v0.17.0

func NewIdentifierCache(loadFunc func(context.Context, string) (string, error)) (*IdentifierCache, bool)

NewIdentifierCache returns an initialized cache. This is a singleton so if you call New multiple times you will get the same instance. If the cache has already been initialized then it will return false indicating that your New call did not create a new instance.

func (*IdentifierCache) Clear added in v0.17.0

func (ic *IdentifierCache) Clear()

Clear empties out the cache.

func (*IdentifierCache) Delete added in v0.17.0

func (ic *IdentifierCache) Delete(keyspace string)

Delete removes an entry from the cache. It is idempotent and will always delete the entry IF it exists.

func (*IdentifierCache) Destroy added in v0.17.0

func (ic *IdentifierCache) Destroy()

Destroy clears the existing cache and sets the singleton instance to nil so that a new cache can be created. NOTE: this should ONLY be used in unit tests and NOT in production as it breaks the singleton pattern!

func (*IdentifierCache) Get added in v0.17.0

func (ic *IdentifierCache) Get(keyspace string) (string, error)

Get returns an sqlparser string built from an IdentifierCS using the sidecar database name stored in the database. This provides a read through cache.

Jump to

Keyboard shortcuts

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