types

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorRowQueryDiffLenght        = "only one query per row is allowed"
	ErrorEmptyRow                  = "rows cannot be empty"
	ErrorMultipleQueryForSingleRow = "multiple queries for one row"
	ErrorMultipleDBM               = "only one filter is supported"
	ErrorReconnecting              = "error reconnecting"
	ErrorIndexEmpty                = "index keys cannot be empty"
	ErrorIndexAlreadyExist         = "index already exists with a different name"
	ErrorIndexComposedTTL          = "TTL indexes are single-field indexes, compound indexes do not support TTL"
	ErrorSessionClosed             = "session closed"
	ErrorRowOptDiffLenght          = "only one options per row is allowed"
	ErrorCollectionNotFound        = "collection not found"
)
View Source
const (
	DEFAULT_CONN_TIMEOUT = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOpts

type ClientOpts struct {
	// ConnectionString is the expression used to connect to a storage db server.
	// It contains parameters such as username, hostname, password and port
	ConnectionString string
	// UseSSL is SSL connection is required to connect
	UseSSL bool
	// This setting allows the use of self-signed certificates when connecting to an encrypted storage database.
	SSLInsecureSkipVerify bool
	// Ignore hostname check when it differs from the original (for example with SSH tunneling).
	// The rest of the TLS verification will still be performed
	SSLAllowInvalidHostnames bool
	// Path to the PEM file with trusted root certificates
	SSLCAFile string
	// Path to the PEM file which contains both client certificate and private key. This is required for Mutual TLS.
	SSLPEMKeyfile string
	// Sets the session consistency for the storage connection
	SessionConsistency string
	// Sets the connection timeout to the database. Defaults to 10s.
	ConnectionTimeout int
	// DirectConnection informs whether to establish connections only with the specified seed servers,
	// or to obtain information for the whole cluster and establish connections with further servers too.
	// If true, the client will only connect to the host provided in the ConnectionString
	// and won't attempt to discover other hosts in the cluster. Useful when network restrictions
	// prevent discovery, such as with SSH tunneling. Default is false.
	DirectConnection bool
	// type of database/driver
	Type string
}

func (*ClientOpts) GetTLSConfig

func (opts *ClientOpts) GetTLSConfig() (*tls.Config, error)

GetTLSConfig returns the TLS config given the configuration specified in ClientOpts. It loads certificates if necessary.

type DBObject

type DBObject interface {
	DBID() ObjectID
	SetDBID(id ObjectID)
}

type DBTable

type DBTable interface {
	TableName() string
}

DBTable is an interface that should be implemented by database models in order to perform CRUD operations

type ObjectID

type ObjectID interface {
	Hex() string
	String() string
	Timestamp() time.Time
	MarshalJSON() ([]byte, error)
	UnmarshalJSON([]byte) error
	MarshalText() ([]byte, error)
	UnmarshalText([]byte) error
}

ObjectID interface to be implemented by each db driver

type PersistentStorage

type PersistentStorage interface {
	// Insert a DbObject into the database
	Insert(context.Context, ...model.DBObject) error
	// Delete a DbObject from the database
	Delete(context.Context, model.DBObject, ...model.DBM) error
	// Update a DbObject in the database
	Update(context.Context, model.DBObject, ...model.DBM) error
	// Count counts all rows for a DBTable if no filter model.DBM given.
	// If a filter model.DBM is specified it will count the rows given the built query for that filter.
	// If multiple filters model.DBM are specified, it will return an error.
	// In case of an error, the count result is going to be 0.
	Count(ctx context.Context, row model.DBObject, filter ...model.DBM) (count int, error error)
	// Query one or multiple DBObjects from the database
	Query(context.Context, model.DBObject, interface{}, model.DBM) error
	// BulkUpdate updates multiple rows
	BulkUpdate(context.Context, []model.DBObject, ...model.DBM) error
	// UpdateAll executes the update query model.DBM over
	// the elements filtered by query model.DBM in the row model.DBObject collection
	UpdateAll(ctx context.Context, row model.DBObject, query, update model.DBM) error
	// Drop drops the collection given the TableName() of the model.DBObject
	Drop(context.Context, model.DBObject) error
	// CreateIndex creates an model.Index in row model.DBObject TableName()
	CreateIndex(ctx context.Context, row model.DBObject, index model.Index) error
	// GetIndexes returns all the model.Index associated to row model.DBObject
	GetIndexes(ctx context.Context, row model.DBObject) ([]model.Index, error)
	// Ping checks if the database is reachable
	Ping(context.Context) error
	// HasTable checks if the table/collection exists
	HasTable(context.Context, string) (bool, error)
	// DropDatabase removes the database
	DropDatabase(ctx context.Context) error
	// Migrate creates the table/collection if it doesn't exist
	Migrate(context.Context, []model.DBObject, ...model.DBM) error
	// DBTableStats retrieves statistics for a specified table in the database.
	// The function takes a context.Context and an model.DBObject as input parameters,
	// where the DBObject represents the table to get stats for.
	// The result is decoded into a model.DBM object, along with any error that occurred during the command execution.
	// Example: stats["capped"] -> true
	DBTableStats(ctx context.Context, row model.DBObject) (model.DBM, error)
	// Aggregate performs an aggregation query on the row model.DBObject collection
	// query is the aggregation pipeline to be executed
	// it returns the aggregation result and an error if any
	Aggregate(ctx context.Context, row model.DBObject, query []model.DBM) ([]model.DBM, error)
	// CleanIndexes removes all the indexes from the row model.DBObject collection
	CleanIndexes(ctx context.Context, row model.DBObject) error
	// Upsert performs an upsert operation on the row model.DBObject collection
	// query is the filter to be used to find the document to update
	// update is the update to be applied to the document
	// row is modified with the result of the operation
	Upsert(ctx context.Context, row model.DBObject, query, update model.DBM) error
	// GetDatabaseInfo returns information of the database to which the driver is connecting to
	GetDatabaseInfo(ctx context.Context) (utils.Info, error)
	// GetTables return the list of collections for a given database
	GetTables(ctx context.Context) ([]string, error)
	// DropTable drops a table/collection from the database. Returns the number of affected rows and error
	DropTable(ctx context.Context, name string) (int, error)
}

type StorageLifecycle

type StorageLifecycle interface {
	// Connects to a db instance
	Connect(*ClientOpts) error

	// Close cleans up possible resources after we stop using storage driver.
	Close() error

	// DBType returns the type of the registered storage driver.
	DBType() utils.DBType
}

Jump to

Keyboard shortcuts

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