mysql

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Engine = "mysql"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Datastore

type Datastore struct {
	*QueryBuilder
	// contains filtered or unexported fields
}

Datastore is a MySQL-based implementation of the datastore.Datastore interface

func NewMySQLDatastore

func NewMySQLDatastore(uri string, options ...Option) (*Datastore, error)

NewMySQLDatastore creates a new mysql.Datastore value configured with the MySQL instance specified in through the URI parameter. Supports customization via the various options available in this package.

URI: [scheme://][user[:[password]]@]host[:port][/schema][?attribute1=value1&attribute2=value2... See https://dev.mysql.com/doc/refman/8.0/en/connecting-using-uri-or-key-value-pairs.html

func (*Datastore) CheckRevision

func (mds *Datastore) CheckRevision(ctx context.Context, revision datastore.Revision) error

func (*Datastore) Close

func (mds *Datastore) Close() error

Close closes the data store.

func (*Datastore) DeleteNamespace

func (mds *Datastore) DeleteNamespace(ctx context.Context, nsName string) (datastore.Revision, error)

func (*Datastore) DeleteRelationships

func (mds *Datastore) DeleteRelationships(ctx context.Context, preconditions []*v1.Precondition, filter *v1.RelationshipFilter) (datastore.Revision, error)

func (*Datastore) HeadRevision

func (mds *Datastore) HeadRevision(ctx context.Context) (datastore.Revision, error)

func (*Datastore) IsReady

func (mds *Datastore) IsReady(ctx context.Context) (bool, error)

IsReady returns whether the datastore is ready to accept data. Datastores that require database schema creation will return false until the migrations have been run to create the necessary tables.

fundamentally different from PSQL implementation:

  • checking if the current migration version is compatible is implemented with IsHeadCompatible
  • Database seeding is handled here, so that we can decouple schema migration from data migration and support skeema-based migrations.

func (*Datastore) ListNamespaces

func (mds *Datastore) ListNamespaces(ctx context.Context, revision datastore.Revision) ([]*core.NamespaceDefinition, error)

func (*Datastore) NamespaceCacheKey

func (mds *Datastore) NamespaceCacheKey(namespaceName string, revision datastore.Revision) (string, error)

func (*Datastore) OptimizedRevision

func (mds *Datastore) OptimizedRevision(ctx context.Context) (datastore.Revision, error)

func (*Datastore) QueryTuples

func (mds *Datastore) QueryTuples(
	ctx context.Context,
	filter *v1.RelationshipFilter,
	revision datastore.Revision,
	opts ...options.QueryOptionsOption,
) (iter datastore.TupleIterator, err error)

func (*Datastore) ReadNamespace

func (mds *Datastore) ReadNamespace(ctx context.Context, nsName string, revision datastore.Revision) (*core.NamespaceDefinition, datastore.Revision, error)

func (*Datastore) ReverseQueryTuples

func (mds *Datastore) ReverseQueryTuples(
	ctx context.Context,
	subjectFilter *v1.SubjectFilter,
	revision datastore.Revision,
	opts ...options.ReverseQueryOptionsOption,
) (iter datastore.TupleIterator, err error)

func (*Datastore) Statistics

func (mds *Datastore) Statistics(ctx context.Context) (datastore.Stats, error)

func (*Datastore) Watch

func (mds *Datastore) Watch(ctx context.Context, afterRevision datastore.Revision) (<-chan *datastore.RevisionChanges, <-chan error)

Watch notifies the caller about all changes to tuples.

All events following afterRevision will be sent to the caller.

TODO (@vroldanbet) dupe from postgres datastore - need to refactor

func (*Datastore) WriteNamespace

func (mds *Datastore) WriteNamespace(ctx context.Context, newNamespace *core.NamespaceDefinition) (datastore.Revision, error)

func (*Datastore) WriteTuples

func (mds *Datastore) WriteTuples(ctx context.Context, preconditions []*v1.Precondition, mutations []*v1.RelationshipUpdate) (datastore.Revision, error)

WriteTuples takes a list of existing tuples that must exist, and a list of tuple mutations and applies it to the datastore for the specified namespace.

type Option

type Option func(*mysqlOptions)

Option provides the facility to configure how clients within the MySQL datastore interact with the running MySQL database.

func ConnMaxIdleTime

func ConnMaxIdleTime(idle time.Duration) Option

ConnMaxIdleTime is the duration after which an idle connection will be automatically closed. See https://pkg.go.dev/database/sql#DB.SetConnMaxIdleTime/

This value defaults to having no maximum.

func ConnMaxLifetime

func ConnMaxLifetime(lifetime time.Duration) Option

ConnMaxLifetime is the duration since creation after which a connection will be automatically closed. See https://pkg.go.dev/database/sql#DB.SetConnMaxLifetime

This value defaults to having no maximum.

func DebugAnalyzeBeforeStatistics

func DebugAnalyzeBeforeStatistics() Option

DebugAnalyzeBeforeStatistics signals to the Statistics method that it should run Analyze Table on the relationships table before returning statistics. This should only be used for debug and testing.

Disabled by default.

func GCInterval

func GCInterval(interval time.Duration) Option

GCInterval is the interval at which garbage collection will occur.

This value defaults to 3 minutes.

func GCWindow

func GCWindow(window time.Duration) Option

GCWindow is the maximum age of a passed revision that will be considered valid.

This value defaults to 24 hours.

func MaxOpenConns

func MaxOpenConns(conns int) Option

MaxOpenConns is the maximum size of the connection pool. See https://pkg.go.dev/database/sql#DB.SetMaxOpenConns

This value defaults to having no maximum.

func RevisionFuzzingTimedelta

func RevisionFuzzingTimedelta(delta time.Duration) Option

RevisionFuzzingTimedelta is the time bucket size to which advertised revisions will be rounded.

This value defaults to 5 seconds.

func TablePrefix

func TablePrefix(prefix string) Option

TablePrefix allows defining a MySQL table name prefix.

No prefix is set by default

func WithEnablePrometheusStats

func WithEnablePrometheusStats(enablePrometheusStats bool) Option

WithEnablePrometheusStats marks whether Prometheus metrics provided by Go's database/sql package are enabled.

Prometheus metrics are disabled by default.

type QueryBuilder

type QueryBuilder struct {
	GetLastRevision  sq.SelectBuilder
	GetRevisionRange sq.SelectBuilder

	WriteNamespaceQuery        sq.InsertBuilder
	ReadNamespaceQuery         sq.SelectBuilder
	DeleteNamespaceQuery       sq.UpdateBuilder
	DeleteNamespaceTuplesQuery sq.UpdateBuilder

	QueryTupleIdsQuery    sq.SelectBuilder
	QueryTuplesQuery      sq.SelectBuilder
	DeleteTupleQuery      sq.UpdateBuilder
	QueryTupleExistsQuery sq.SelectBuilder
	WriteTupleQuery       sq.InsertBuilder
	QueryChangedQuery     sq.SelectBuilder
}

QueryBuilder captures all parameterizable queries used by the MySQL datastore implementation

func NewQueryBuilder

func NewQueryBuilder(driver *migrations.MySQLDriver) *QueryBuilder

NewQueryBuilder returns a new QueryBuilder instance. The migration driver is used to determine the names of the tables.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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