Documentation
¶
Index ¶
- Constants
- Variables
- func GormConvertString(db *gorm.DB, neq bool, field string, values ...string) *gorm.DB
- func NewLogger(config glog.Config) glog.Interface
- func OpenPool(ctx context.Context, uu string) (storage.Storage, error)
- func QuoteTo(db *gorm.DB, s string) string
- func TableNameFromModel(db *gorm.DB, model any) string
- func WithTxRetry(ctx context.Context, db *gorm.DB, maxRetries int, retryMsg string, ...) error
- type Abstract
- type AbstractResources
- type BoolInt
- type Dialector
- type EnumSerial
- type Helper
- type ILike
- type Meta
- type OrderedUpdate
- type Resources
- type ServerInfos
- type StorageDSN
Constants ¶
const ( SqliteDriver = "sqlite" )
const (
MySQLDriver = "mysql"
)
const (
PostgreDriver = "postgres"
)
Variables ¶
var ( DefaultConnectionTimeout = 30 * time.Second LongConnectionTimeout = 10 * time.Minute )
var (
Drivers = []string{MySQLDriver, PostgreDriver, SqliteDriver}
)
var (
TestPrintQueries = false
)
Functions ¶
func GormConvertString ¶
GormConvertString creates correct gorm.Queries for field + string value
func TableNameFromModel ¶
TableNameFromModel computes table name from model using standard GORM strategy
func WithTxRetry ¶
func WithTxRetry(ctx context.Context, db *gorm.DB, maxRetries int, retryMsg string, fn func(tx *gorm.DB) error) error
WithTxRetry runs fn inside a transaction and retries automatically on transient SQL errors like deadlocks or serialization failures. It works across MySQL, Postgres, and SQLite.
Types ¶
type Abstract ¶
func NewAbstract ¶
NewAbstract initializes a new Abstract to be used by DAO implementation
func (*Abstract) MigrateWithCtx ¶
MigrateWithCtx triggers AutoMigrate in context
func (*Abstract) Session ¶
Session creates a gorm session with given context and default config (SkipDefaultTransaction: true)
func (*Abstract) WithModels ¶
WithModels sets the migrateModels factory for auto migration
type AbstractResources ¶
func NewAbstractResources ¶
func NewAbstractResources(db *gorm.DB) *AbstractResources
func (*AbstractResources) WithModels ¶
func (a *AbstractResources) WithModels(factory func() []any) *AbstractResources
type BoolInt ¶
type BoolInt struct{}
BoolInt is a gorm serializer to store booleans as integers
type EnumSerial ¶
type EnumSerial struct{}
EnumSerial is a gorm serializer to store proto.Enum as string instead of integer
type Helper ¶
type Helper interface {
Concat(...string) string
Hash(...string) string
ParentMPath(levelKey string, mpathes ...string) string
HashParent(nameKey string, levelKey string, mpathes ...string) string
ApplyOrderedUpdates(db *gorm.DB, tableName string, sets []OrderedUpdate, wheres []sql.NamedArg) (int64, error)
MPathOrdering(...string) string
MPathOrderingLastInteger(...string) string
FirstAvailableSlot(tableName string, mpath *tree.MPath, levelKey string, mpathes ...string) (string, []any, int64, bool)
}
type OrderedUpdate ¶
type OrderedUpdate struct {
Key string
Value interface{}
}
type ServerInfos ¶
type StorageDSN ¶
type StorageDSN interface {
// Parse parses standard DSN and extract reserved variables
Parse() error
// Driver returns driver type
Driver() string
// DBName returns the name of the target DB as extracted from the dsn string
DBName() string
// DSN returns clean DSN for opening DB
DSN() string
// OpenDB Opens a DB connection
OpenDB(ctx context.Context) ([]*sql.DB, error)
// Set updates a field from the DSN, like DB, User, Password, etc. it returns an error if the key is not supported
Set(key, value string) error
// GetReservedVar returns a parsed variable if it is set
GetReservedVar(string) string
// Check tests the connection and eventually creates the DB if it does not exists
Check(ctx context.Context, create bool) (*ServerInfos, error)
}
func NewStorageDSN ¶
func NewStorageDSN(dsn string) (StorageDSN, error)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package index provides ready-to-use tables and DAOs for storing hierarchical data using the nested sets pattern
|
Package index provides ready-to-use tables and DAOs for storing hierarchical data using the nested sets pattern |
|
Package resources provides ready-to-use SQL schemes and DAOs for attaching resource policies to any data
|
Package resources provides ready-to-use SQL schemes and DAOs for attaching resource policies to any data |