Documentation
¶
Overview ¶
Package database provides low-level database connectivity and helpers used by the DAO layer.
Index ¶
- func GetFunctionName(temp interface{}) string
- func GetStructType(data any) string
- func IsValidFieldInStruct(fromField Field, data any) error
- func IsValidTypeForField(field Field, data, forStruct any) error
- type DB
- func (db *DB) Backup(loc string)
- func (db *DB) Count(data any) (int, error)
- func (db *DB) CountWhere(fieldName Field, value any, to any) (int, error)
- func (db *DB) Create(data any) error
- func (db *DB) Delete(data any) error
- func (db *DB) Disconnect()
- func (db *DB) Drop(data any) error
- func (db *DB) GetAll(to any, options ...func(*index.Options)) error
- func (db *DB) PreLoadCache(to any, options ...func(*index.Options)) error
- func (db *DB) Reconnect()
- func (db *DB) Retrieve(fieldName Field, value, to any) error
- func (db *DB) Update(data any) error
- type Field
- type Option
- func WithCacheKey(field Field) Option
- func WithCaching(enabled bool) Option
- func WithEncryption(enabled bool) Option
- func WithIndex(field Field) Option
- func WithIndices(indices []Field) Option
- func WithNameSpace(name string) Option
- func WithPoolSize(size int) Option
- func WithTimeout(seconds int) Option
- func WithVerbose(enabled bool) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFunctionName ¶ added in v1.5.0
func GetFunctionName(temp interface{}) string
GetFunctionName returns the name of the function passed as an argument It uses reflection to obtain the function's program counter and retrieves its name.
func GetStructType ¶ added in v1.5.1
func IsValidFieldInStruct ¶ added in v1.5.1
func IsValidTypeForField ¶ added in v1.5.1
Types ¶
type DB ¶
type DB struct {
Name string
// contains filtered or unexported fields
}
DB represents a database connection and its configuration
func Connect ¶
Connect establishes a database connection with the provided options It is the primary function to initiate a connection using various configuration options.
func ConnectToNamedDB ¶
ConnectToNamedDB establishes a database connection to a named database DEPRECATED: ConnectToNamedDB - Use Connect with WithNameSpace option instead
func (*DB) Backup ¶
Backup creates a backup of the database to the specified location It disconnects the database, performs the backup, and then reconnects. The backup process is timed and logged.
func (*DB) Disconnect ¶
func (db *DB) Disconnect()
Disconnect closes the database connection and removes it from the connection pool It uses a timing mechanism to log the duration of the disconnection process. If disconnection fails, it logs the error and panics with a wrapped disconnect error.
func (*DB) PreLoadCache ¶ added in v1.5.0
type Option ¶ added in v1.5.0
type Option func(*connectionConfig)
Option is a function that configures the database connection
func WithCacheKey ¶ added in v1.5.0
WithCacheKey sets the cache key field for the database connection
func WithCaching ¶ added in v1.5.0
WithCaching enables or disables caching for the database connection
func WithEncryption ¶ added in v1.5.0
WithEncryption enables or disables encryption for the database connection By default, encryption is disabled. Reserved for Future use.
func WithIndex ¶ added in v1.5.0
WithIndex adds a single index field for the database connection Used to create an index on a field for faster querying. Reserved for Future use.
func WithIndices ¶ added in v1.5.0
WithIndices sets the indices for the database connection Used to create indices on fields for faster querying. Reserved for Future use.
func WithNameSpace ¶ added in v1.5.0
WithNameSpace sets the namespace (database name) for the connection
func WithPoolSize ¶ added in v1.5.0
WithPoolSize sets the maximum connection pool size
func WithTimeout ¶ added in v1.5.0
WithTimeout sets the connection timeout in seconds
func WithVerbose ¶ added in v1.5.0
WithVerbose enables or disables verbose logging for the database connection