Documentation ¶
Index ¶
- Constants
- func AddSchemaInitQueries(db *fakesqldb.DB, populateTables bool)
- func GetCreateQuery() string
- func GetIdentifier() string
- func GetIdentifierForKeyspace(keyspace string) (string, error)
- func GetName() string
- func Init(ctx context.Context, exec Exec) error
- func MatchesInitQuery(query string) bool
- func SetName(name string)
- type Exec
- type IdentifierCache
Constants ¶
const ( DefaultName = "_vt" StatsKeyPrefix = "SidecarDBDDL" StatsKeyQueryCount = StatsKeyPrefix + "QueryCount" StatsKeyErrorCount = StatsKeyPrefix + "ErrorCount" StatsKeyErrors = StatsKeyPrefix + "Errors" )
Variables ¶
This section is empty.
Functions ¶
func AddSchemaInitQueries ¶
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
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 Init ¶
Init creates or upgrades the sidecar database based on the declarative schema defined for all tables.
func MatchesInitQuery ¶
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!
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!