Documentation ¶
Index ¶
- Variables
- func Drivers() map[string]Driver
- func Register(driver Driver) error
- type Condition
- type Connection
- type ConnectionPool
- func (cp *ConnectionPool) CloseAll() error
- func (cp *ConnectionPool) CloseConnection(index uint) error
- func (cp *ConnectionPool) Connect(ctx context.Context) (Connection, uint, error)
- func (cp *ConnectionPool) GetConnection(index uint) (Connection, error)
- func (cp *ConnectionPool) GetConnectionLength() uint
- func (cp *ConnectionPool) GetConnector() *Connector
- type Connector
- type DataCollectionDetail
- type DatabaseDetail
- func (d DatabaseDetail) AllDataCollectionsExcept(names ...string) []DataCollectionDetail
- func (d DatabaseDetail) GetDataCollection(name string) (DataCollectionDetail, error)
- func (d DatabaseDetail) GetDataCollections() []DataCollectionDetail
- func (d DatabaseDetail) GetDatabaseName() string
- func (d DatabaseDetail) OnlyDataCollections(names ...string) []DataCollectionDetail
- type DefaultFilterBuilder
- func (fb *DefaultFilterBuilder) BuildFilterSQL(dataCollection string) string
- func (fb *DefaultFilterBuilder) GetAllFilters() map[string][]*Filter
- func (fb *DefaultFilterBuilder) GetFilters(dataCollection string) []*Filter
- func (fb *DefaultFilterBuilder) GetRootFilters() []*Filter
- func (fb *DefaultFilterBuilder) ResetAllFilters()
- func (fb *DefaultFilterBuilder) ResetFilters(dataCollection string)
- func (fb *DefaultFilterBuilder) ResetRootFilters()
- func (fb *DefaultFilterBuilder) Where(dataCollection, key string, value string) FilterableConnection
- func (fb *DefaultFilterBuilder) WhereCondition(dataCollection string, condition Condition, key string, value string) FilterableConnection
- func (fb *DefaultFilterBuilder) WhereRoot(key string, value string) FilterableConnection
- func (fb *DefaultFilterBuilder) WhereRootCondition(condition Condition, key, value string) FilterableConnection
- type DefaultSortBuilder
- func (sb *DefaultSortBuilder) BuildSortSQL(dataCollection string) string
- func (sb *DefaultSortBuilder) GetAllSorts() map[string][]*Sort
- func (sb *DefaultSortBuilder) GetRootSorts() []*Sort
- func (sb *DefaultSortBuilder) GetSorts(dataCollection string) []*Sort
- func (sb *DefaultSortBuilder) OrderBy(dataCollection, key string, direction ...Direction) SortableConnection
- func (sb *DefaultSortBuilder) OrderByRoot(key string, direction ...Direction) SortableConnection
- func (sb *DefaultSortBuilder) ResetAllSorts()
- func (sb *DefaultSortBuilder) ResetSorts(dataCollection string)
- type Direction
- type Driver
- type Filter
- type FilterableConnection
- type Manager
- type ReadableConnection
- type Sort
- type SortableConnection
- type WritableConnection
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnectionNotReadable = errors.New("connection is not readable") ErrConnectionNotWritable = errors.New("connection not writable") ErrConnectionIsClosed = errors.New("connection is closed") )
var ErrConnectionPoolOutOfIndex = errors.New("connection pool out of index")
var ErrDriverNotFound = errors.New("driver not found")
Functions ¶
Types ¶
type Condition ¶
type Condition uint8
Condition is a connection to a database.
func GetConditionFromString ¶
type Connection ¶
type Connection interface { // Close closes the connection. Close() error // IsClosed returns true if the connection is closed. IsClosed() bool // Ping pings the database. // This is used to check if the connection is still alive. // If the connection was closed before, the ErrConnectionIsClosed should be returned. Ping() error // GetDetails returns the details of the database. GetDetails(ctx context.Context) (DatabaseDetail, error) }
Connection is a connection to a database.
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool is a pool of connections. It's used to manage connections to the database.
func NewConnectionPool ¶
func NewConnectionPool(connector *Connector) *ConnectionPool
NewConnectionPool returns a new connection pool.
func (*ConnectionPool) CloseAll ¶
func (cp *ConnectionPool) CloseAll() error
CloseAll closes all connections in the pool.
func (*ConnectionPool) CloseConnection ¶
func (cp *ConnectionPool) CloseConnection(index uint) error
CloseConnection closes a connection in the pool.
func (*ConnectionPool) Connect ¶
func (cp *ConnectionPool) Connect(ctx context.Context) (Connection, uint, error)
Connect connects to the database.
func (*ConnectionPool) GetConnection ¶
func (cp *ConnectionPool) GetConnection(index uint) (Connection, error)
GetConnection returns a connection from the pool.
func (*ConnectionPool) GetConnectionLength ¶
func (cp *ConnectionPool) GetConnectionLength() uint
GetConnectionLength returns the length of the connections.
func (*ConnectionPool) GetConnector ¶
func (cp *ConnectionPool) GetConnector() *Connector
GetConnector returns the connector.
type Connector ¶
type Connector struct { DefaultSortBuilder DefaultFilterBuilder // contains filtered or unexported fields }
Connector is database connector. It's used to connect to the database quickly with predefined credentials, filters, and sorts.
func NewConnector ¶
NewConnector returns a new connector.
func (*Connector) Connect ¶
func (c *Connector) Connect(ctx context.Context) (Connection, error)
Connect connects to the database.
func (*Connector) IsReadable ¶
IsReadable returns true if the connection is readable.
func (*Connector) IsWritable ¶
IsWritable returns true if the connection is writable.
type DataCollectionDetail ¶
DataCollectionDetail is the details of a data collection.
func (DataCollectionDetail) GetDataCollectionName ¶
func (d DataCollectionDetail) GetDataCollectionName() string
func (DataCollectionDetail) GetDataMap ¶
func (d DataCollectionDetail) GetDataMap() *data.Map
func (DataCollectionDetail) GetDataSetCount ¶
func (d DataCollectionDetail) GetDataSetCount() int
type DatabaseDetail ¶
type DatabaseDetail struct { Name string DataCollections []DataCollectionDetail }
DatabaseDetail is the details of a data batch.
func (DatabaseDetail) AllDataCollectionsExcept ¶
func (d DatabaseDetail) AllDataCollectionsExcept(names ...string) []DataCollectionDetail
AllDataCollectionsExcept returns all data collections except the ones with matching names. If no names are provided, all data collections will be returned. If provided names are not found, they will be ignored.
func (DatabaseDetail) GetDataCollection ¶
func (d DatabaseDetail) GetDataCollection(name string) (DataCollectionDetail, error)
func (DatabaseDetail) GetDataCollections ¶
func (d DatabaseDetail) GetDataCollections() []DataCollectionDetail
func (DatabaseDetail) GetDatabaseName ¶
func (d DatabaseDetail) GetDatabaseName() string
func (DatabaseDetail) OnlyDataCollections ¶
func (d DatabaseDetail) OnlyDataCollections(names ...string) []DataCollectionDetail
OnlyDataCollections returns only the data collections with matching names. If no names are provided, all data collections will be returned. If provided names are not found, they will be ignored.
type DefaultFilterBuilder ¶
type DefaultFilterBuilder struct {
// contains filtered or unexported fields
}
DefaultFilterBuilder is a default implementation of FilterableConnection. That can be used as embedded struct in a driver to implement simple filterable connection. And also this builder can build sql query from the filters.
func (*DefaultFilterBuilder) BuildFilterSQL ¶
func (fb *DefaultFilterBuilder) BuildFilterSQL(dataCollection string) string
func (*DefaultFilterBuilder) GetAllFilters ¶
func (fb *DefaultFilterBuilder) GetAllFilters() map[string][]*Filter
GetAllFilters returns all data collections filters without applying root filters.
func (*DefaultFilterBuilder) GetFilters ¶
func (fb *DefaultFilterBuilder) GetFilters(dataCollection string) []*Filter
func (*DefaultFilterBuilder) GetRootFilters ¶
func (fb *DefaultFilterBuilder) GetRootFilters() []*Filter
GetRootFilters returns root filters.
func (*DefaultFilterBuilder) ResetAllFilters ¶
func (fb *DefaultFilterBuilder) ResetAllFilters()
func (*DefaultFilterBuilder) ResetFilters ¶
func (fb *DefaultFilterBuilder) ResetFilters(dataCollection string)
func (*DefaultFilterBuilder) ResetRootFilters ¶
func (fb *DefaultFilterBuilder) ResetRootFilters()
func (*DefaultFilterBuilder) Where ¶
func (fb *DefaultFilterBuilder) Where(dataCollection, key string, value string) FilterableConnection
func (*DefaultFilterBuilder) WhereCondition ¶
func (fb *DefaultFilterBuilder) WhereCondition(dataCollection string, condition Condition, key string, value string) FilterableConnection
func (*DefaultFilterBuilder) WhereRoot ¶
func (fb *DefaultFilterBuilder) WhereRoot(key string, value string) FilterableConnection
WhereRoot is a general filter that is not related to any data collection. and will apply to all data collections.
func (*DefaultFilterBuilder) WhereRootCondition ¶
func (fb *DefaultFilterBuilder) WhereRootCondition(condition Condition, key, value string) FilterableConnection
WhereRootCondition is a general filter that is not related to any data collection. and will apply to all data collections.
type DefaultSortBuilder ¶
type DefaultSortBuilder struct {
// contains filtered or unexported fields
}
DefaultSortBuilder is the default implementation of SortableConnection. That can be used as embedded struct in a driver to implement simple filterable connection. And also this builder can build sql query from the sorts.
func (*DefaultSortBuilder) BuildSortSQL ¶
func (sb *DefaultSortBuilder) BuildSortSQL(dataCollection string) string
BuildSortSQL builds the sort SQL.
func (*DefaultSortBuilder) GetAllSorts ¶
func (sb *DefaultSortBuilder) GetAllSorts() map[string][]*Sort
GetAllSorts returns all sorts of the builder.
func (*DefaultSortBuilder) GetRootSorts ¶
func (sb *DefaultSortBuilder) GetRootSorts() []*Sort
func (*DefaultSortBuilder) GetSorts ¶
func (sb *DefaultSortBuilder) GetSorts(dataCollection string) []*Sort
GetSorts returns the sorts of the builder.
func (*DefaultSortBuilder) OrderBy ¶
func (sb *DefaultSortBuilder) OrderBy(dataCollection, key string, direction ...Direction) SortableConnection
OrderBy adds a sort to the builder.
func (*DefaultSortBuilder) OrderByRoot ¶
func (sb *DefaultSortBuilder) OrderByRoot(key string, direction ...Direction) SortableConnection
func (*DefaultSortBuilder) ResetAllSorts ¶
func (sb *DefaultSortBuilder) ResetAllSorts()
ResetAllSorts resets all data collection sorts.
func (*DefaultSortBuilder) ResetSorts ¶
func (sb *DefaultSortBuilder) ResetSorts(dataCollection string)
ResetSorts resets the specified sorts of a data collection.
type Direction ¶
type Direction uint8
Direction is direction of a sort.
func GetDirectionFromString ¶
GetDirectionFromString returns the direction from a string.
type Driver ¶
type Driver interface { // GetDriverName returns the name of the driver. GetDriverName() string // IsWritable returns true if the driver is writable. // If the driver is writable, returned Connection will implement WritableConnection. IsWritable() bool // IsReadable returns true if the driver is readable. // If the driver is readable, returned Connection will implement ReadableConnection. IsReadable() bool // Open opens a connection to the database. Open(ctx context.Context, dsn string) (Connection, error) }
Driver is a driver for a database.
type Filter ¶
Filter is a filter for a query.
func (*Filter) GetCondition ¶
GetCondition returns the condition of the filter.
type FilterableConnection ¶
type FilterableConnection interface { Where(dataCollection, key string, value string) FilterableConnection WhereRoot(key, value string) FilterableConnection WhereCondition(dataCollection string, condition Condition, key string, value string) FilterableConnection WhereRootCondition(condition Condition, key string, value string) FilterableConnection GetFilters(dataCollection string) []*Filter GetAllFilters() map[string][]*Filter GetRootFilters() []*Filter ResetFilters(dataCollection string) ResetAllFilters() ResetRootFilters() }
FilterableConnection is a connection that can be filtered.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a manager for drivers.
type ReadableConnection ¶
type ReadableConnection interface { Connection // Embeds Connection // Read reads a batch of data from the database. Read(ctx context.Context, dataCollection string, startOffset, endOffset uint64) (*data.Batch, error) }
ReadableConnection is a connection to a database that can read data.
type Sort ¶
Sort is a sort for a query.
func (*Sort) GetDirection ¶
GetDirection returns the direction of the sort.
type SortableConnection ¶
type SortableConnection interface { OrderBy(dataCollection, key string, direction ...Direction) SortableConnection OrderByRoot(key string, direction ...Direction) SortableConnection GetSorts(dataCollection string) []*Sort GetAllSorts() map[string][]*Sort GetRootSorts() []*Sort ResetSorts(dataCollection string) ResetAllSorts() }
SortableConnection is a connection that can be sorted.
type WritableConnection ¶
type WritableConnection interface { Connection // Embeds Connection // Write writes a batch of data to the database. // If the data set is duplicated or unique constraint is violated, ErrDataSetDuplicate should be returned. Write(ctx context.Context, dataCollection string, dataBatch *data.Batch) error }
WritableConnection is a connection to a database that can write data.