metadata

package
v0.0.0-...-bb56650 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package metadata provides access to databases and collections information.

Index

Constants

View Source
const (
	// DefaultColumn is a column name for all fields.
	DefaultColumn = backends.ReservedPrefix + "sjson"

	// IDColumn is a MySQL path expression for _id field.
	IDColumn = DefaultColumn + "->'$._id'"

	// TableIdxColumn is a column name for MySQL generated column.
	TableIdxColumn = DefaultColumn + "_table"

	// RecordIDColumn is a name for RecordID column to store capped collection record id.
	RecordIDColumn = backends.ReservedPrefix + "record_id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	Name            string
	TableName       string
	Indexes         Indexes
	CappedSize      int64
	CappedDocuments int64
}

Collection represents collection metadata.

Collection value should be immutable to avoid data races. Use [deepCopy] to replace whole value instead of modifying fields of existing value.

func (Collection) Capped

func (c Collection) Capped() bool

Capped returns true if collection is capped.

func (*Collection) Scan

func (c *Collection) Scan(src any) error

Scan implements sql.Scanner interface.

func (Collection) Value

func (c Collection) Value() (driver.Value, error)

Value implements driver.Valuer interface.

type IndexInfo

type IndexInfo struct {
	Name   string
	Index  string
	Key    []IndexKeyPair
	Unique bool
}

IndexInfo represents information about a single index.

type IndexKeyPair

type IndexKeyPair struct {
	Field      string
	Descending bool
}

IndexKeyPair consists of a field name and a sort order that are part of the index.

type Indexes

type Indexes []IndexInfo

Indexes represents information about all indexes in a collection.

type Registry

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

Registry provides access to MySQL databases and collections information.

Exported methods and [getPool] are safe for concurrent use. Other unexported methods are not.

All methods should call [getPool] to check authentication. There is no authorization yet - if username/password is correct, all databases and collections are visible as far as Registry is concerned.

Registry metadata is loaded upon first call by client, using conninfo in the context of the client.

func NewRegistry

func NewRegistry(u string, l *zap.Logger, sp *state.Provider) (*Registry, error)

NewRegistry creates a registry for the MySQL databases with a given base URI.

func (*Registry) Close

func (r *Registry) Close()

Close closes the registry.

func (*Registry) Collect

func (r *Registry) Collect(ch chan<- prometheus.Metric)

Collect impements prometheus.Collector.

func (*Registry) CollectionList

func (r *Registry) CollectionList(ctx context.Context, dbName string) ([]*Collection, error)

CollectionList returns a sorted copy of collections in the database.

If database does not exist, no error is returned.

If the user is not authenticated, it returns error.

func (*Registry) DatabaseDrop

func (r *Registry) DatabaseDrop(ctx context.Context, dbName string) (bool, error)

DatabaseDrop drops the database

Returned boolean value indicates whether the database was dropped. If database does not exist, (false, nil) is returned.

If user is not authenticated, it returns error.

func (*Registry) DatabaseGetExisting

func (r *Registry) DatabaseGetExisting(ctx context.Context, dbName string) (*fsql.DB, error)

DatabaseGetExisting returns a connection to existing database or nil if it doesn't exist.

If the user is not authenticated, it returns error.

func (*Registry) DatabaseGetOrCreate

func (r *Registry) DatabaseGetOrCreate(ctx context.Context, dbName string) (*fsql.DB, error)

DatabaseGetOrCreate returns a connection to existing database or newly created database.

The dbName must be a validated database name.

If the user is not authenticated, it returns error.

func (*Registry) DatabaseList

func (r *Registry) DatabaseList(ctx context.Context) ([]string, error)

DatabaseList returns a sorted list of existing databases.

If the user is not authenticated, it returns an error.

func (*Registry) Describe

func (r *Registry) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

Directories

Path Synopsis
Package pool provides access to MySQL connections.
Package pool provides access to MySQL connections.

Jump to

Keyboard shortcuts

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