metadata

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 21 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 SQLite path expression for _id field.
	IDColumn = DefaultColumn + "->'$._id'"

	// 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 added in v1.7.0

type Collection struct {
	Name      string
	TableName string
	Settings  Settings
}

Collection represents collection metadata.

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

func (Collection) Capped added in v1.14.0

func (c Collection) Capped() bool

Capped returns true if collection is capped.

type CollectionCreateParams added in v1.14.0

type CollectionCreateParams struct {
	DBName          string
	Name            string
	CappedSize      int64
	CappedDocuments int64
	// contains filtered or unexported fields
}

CollectionCreateParams contains parameters for CollectionCreate.

func (*CollectionCreateParams) Capped added in v1.14.0

func (ccp *CollectionCreateParams) Capped() bool

Capped returns true if capped collection creation is requested.

type IndexInfo added in v1.10.0

type IndexInfo struct {
	Name   string         `json:"name"`
	Key    []IndexKeyPair `json:"key"`
	Unique bool           `json:"unique"`
}

IndexInfo represents information about a single index.

type IndexKeyPair added in v1.10.0

type IndexKeyPair struct {
	Field      string `json:"field"`
	Descending bool   `json:"descending"`
}

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

type Registry

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

Registry provides access to SQLite databases and collections information.

Exported methods are safe for concurrent use. Unexported methods are not.

func NewRegistry

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

NewRegistry creates a registry for SQLite databases in the directory specified by SQLite URI.

func (*Registry) Close

func (r *Registry) Close()

Close closes the registry.

func (*Registry) Collect added in v1.7.0

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

Collect implements prometheus.Collector.

func (*Registry) CollectionCreate

func (r *Registry) CollectionCreate(ctx context.Context, params *CollectionCreateParams) (bool, error)

CollectionCreate creates a collection in the database. Database will be created automatically if needed.

Returned boolean value indicates whether the collection was created. If collection already exists, (false, nil) is returned.

func (*Registry) CollectionDrop

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

CollectionDrop drops a collection in the database.

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

func (*Registry) CollectionGet added in v1.7.0

func (r *Registry) CollectionGet(ctx context.Context, dbName, collectionName string) *Collection

CollectionGet returns a copy of collection metadata. It can be safely modified by a caller.

If database or collection does not exist, nil is returned.

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.

func (*Registry) CollectionRename added in v1.9.0

func (r *Registry) CollectionRename(ctx context.Context, dbName, oldCollectionName, newCollectionName string) (bool, error)

CollectionRename renames a collection in the database.

The collection name is updated, but original table name is kept.

Returned boolean value indicates whether the collection was renamed. If database or collection did not exist, (false, nil) is returned.

func (*Registry) DatabaseDrop

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

DatabaseDrop drops the database.

Returned boolean value indicates whether the database was dropped.

func (*Registry) DatabaseGetExisting

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

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

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.

func (*Registry) DatabaseList

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

DatabaseList returns a sorted list of existing databases.

func (*Registry) Describe added in v1.7.0

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

Describe implements prometheus.Collector.

func (*Registry) IndexesCreate added in v1.10.0

func (r *Registry) IndexesCreate(ctx context.Context, dbName, collectionName string, indexes []IndexInfo) error

IndexesCreate creates indexes in the collection.

Existing indexes with given names are ignored.

func (*Registry) IndexesDrop added in v1.10.0

func (r *Registry) IndexesDrop(ctx context.Context, dbName, collectionName string, indexNames []string) error

IndexesDrop removes given connection's indexes.

Non-existing indexes are ignored.

If database or collection does not exist, nil is returned.

type Settings added in v1.10.0

type Settings struct {
	UUID            string      `json:"uuid"`
	Indexes         []IndexInfo `json:"indexes"`
	CappedSize      int64       `json:"cappedSize"`
	CappedDocuments int64       `json:"cappedDocuments"`
}

Settings represents collection settings.

func (*Settings) Scan added in v1.10.0

func (s *Settings) Scan(src any) error

Scan implements sql.Scanner interface.

func (Settings) Value added in v1.10.0

func (s Settings) Value() (driver.Value, error)

Value implements driver.Valuer interface.

Directories

Path Synopsis
Package pool provides access to SQLite databases and their connections.
Package pool provides access to SQLite databases and their connections.

Jump to

Keyboard shortcuts

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