sql

package
v5.0.0-...-0681bf2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SqliteDriver = "sqlite"
	SharedMemDSN = "file::memory:?mode=memory&cache=shared"
)
View Source
const (
	MySQLDriver = "mysql"
)
View Source
const (
	PostgreDriver = "postgres"
)

Variables

View Source
var (
	DefaultConnectionTimeout = 30 * time.Second
	LongConnectionTimeout    = 10 * time.Minute
)
View Source
var (
	TestPrintQueries = false
)

Functions

func GormConvertString

func GormConvertString(db *gorm.DB, neq bool, field string, values ...string) *gorm.DB

GormConvertString creates correct gorm.Queries for field + string value

func NewLogger

func NewLogger(config glog.Config) glog.Interface

NewLogger initialize logger

func OpenPool

func OpenPool(ctx context.Context, uu string) (storage.Storage, error)

func QuoteTo

func QuoteTo(db *gorm.DB, s string) string

QuoteTo is a shortcut to db.QuoteTo

func TableNameFromModel

func TableNameFromModel(db *gorm.DB, model any) string

TableNameFromModel computes table name from model using standard GORM strategy

Types

type Abstract

type Abstract struct {
	*gorm.DB
	// contains filtered or unexported fields
}

func NewAbstract

func NewAbstract(db *gorm.DB) *Abstract

NewAbstract initializes a new Abstract to be used by DAO implementation

func (*Abstract) Migrate

func (a *Abstract) Migrate(ctx context.Context) error

func (*Abstract) MigrateWithCtx

func (a *Abstract) MigrateWithCtx(ctx context.Context, dst ...any) error

MigrateWithCtx triggers AutoMigrate in context

func (*Abstract) Session

func (a *Abstract) Session(ctx context.Context) *gorm.DB

Session creates a gorm session with given context and default config (SkipDefaultTransaction: true)

func (*Abstract) WithModels

func (a *Abstract) WithModels(factory func() []any) *Abstract

WithModels sets the migrateModels factory for auto migration

type AbstractResources

type AbstractResources struct {
	*Abstract
	Resources
}

func NewAbstractResources

func NewAbstractResources(db *gorm.DB) *AbstractResources

func (*AbstractResources) Migrate

func (a *AbstractResources) Migrate(ctx context.Context) error

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

func (BoolInt) Scan

func (b BoolInt) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue interface{}) error

func (BoolInt) Value

func (b BoolInt) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue interface{}) (interface{}, error)

type Dialector

type Dialector struct {
	gorm.Dialector
	Helper
}

func (*Dialector) Translate

func (d *Dialector) Translate(err error) error

type EnumSerial

type EnumSerial struct{}

EnumSerial is a gorm serializer to store proto.Enum as string instead of integer

func (EnumSerial) Scan

func (e EnumSerial) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue interface{}) error

func (EnumSerial) Value

func (e EnumSerial) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue interface{}) (interface{}, error)

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
	FirstAvailableSlot(tableName string, mpath *tree.MPath, levelKey string, mpathes ...string) (string, []any, int64, bool)
}

type ILike

type ILike struct {
	Column interface{}
	Value  interface{}
}

func (ILike) Build

func (eq ILike) Build(builder clause.Builder)

type OrderedUpdate

type OrderedUpdate struct {
	Key   string
	Value interface{}
}

type Resources

type Resources resources.DAO

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

Jump to

Keyboard shortcuts

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