Documentation
¶
Overview ¶
Package metadata provides access to databases and collections information.
Index ¶
- Constants
- type Collection
- type Registry
- func (r *Registry) Close()
- func (r *Registry) Collect(ch chan<- prometheus.Metric)
- func (r *Registry) CollectionCreate(ctx context.Context, dbName, collectionName string) (bool, error)
- func (r *Registry) CollectionDrop(ctx context.Context, dbName, collectionName string) (bool, error)
- func (r *Registry) CollectionGet(ctx context.Context, dbName, collectionName string) (*Collection, error)
- func (r *Registry) CollectionList(ctx context.Context, dbName string) ([]*Collection, error)
- func (r *Registry) CollectionRename(ctx context.Context, dbName, oldCollectionName, newCollectionName string) (bool, error)
- func (r *Registry) DatabaseDrop(ctx context.Context, dbName string) (bool, error)
- func (r *Registry) DatabaseGetExisting(ctx context.Context, dbName string) (*pgxpool.Pool, error)
- func (r *Registry) DatabaseGetOrCreate(ctx context.Context, dbName string) (*pgxpool.Pool, error)
- func (r *Registry) DatabaseList(ctx context.Context) ([]string, error)
- func (r *Registry) Describe(ch chan<- *prometheus.Desc)
Constants ¶
const ( // DefaultColumn is a column name for all fields. DefaultColumn = "_jsonb" // IDColumn is a PostgreSQL path expression for _id field. IDColumn = DefaultColumn + "->'_id'" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
Collection represents collection metadata.
func (*Collection) Marshal ¶
func (c *Collection) Marshal() *types.Document
Marshal returns *types.Document for that collection.
func (*Collection) Unmarshal ¶
func (c *Collection) Unmarshal(doc *types.Document) error
Unmarshal sets collection metadata from *types.Document.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry provides access to PostgreSQL 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 combination 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 ¶
NewRegistry creates a registry for PostgreSQL databases with a given base URI.
func (*Registry) Collect ¶ added in v1.11.0
func (r *Registry) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (*Registry) CollectionCreate ¶ added in v1.11.0
func (r *Registry) CollectionCreate(ctx context.Context, dbName, collectionName string) (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.
If the user is not authenticated, it returns error.
func (*Registry) CollectionDrop ¶ added in v1.11.0
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.
If the user is not authenticated, it returns error.
func (*Registry) CollectionGet ¶ added in v1.11.0
func (r *Registry) CollectionGet(ctx context.Context, dbName, collectionName string) (*Collection, error)
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.
If the user is not authenticated, it returns error.
func (*Registry) CollectionList ¶ added in v1.11.0
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) CollectionRename ¶ added in v1.11.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 update, 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.
If the user is not authenticated, it returns error.
func (*Registry) DatabaseDrop ¶ added in v1.11.0
DatabaseDrop drops the database.
Returned boolean value indicates whether the database was dropped. If database does not exist, (false, nil) is returned.
If the user is not authenticated, it returns error.
func (*Registry) DatabaseGetExisting ¶ added in v1.11.0
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 ¶ added in v1.11.0
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 ¶
DatabaseList returns a sorted list of existing databases.
If the user is not authenticated, it returns error.
func (*Registry) Describe ¶ added in v1.11.0
func (r *Registry) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.