db

package
v0.0.0-...-ae6a5fa Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoDBDefault = errors.New("data is not configured with default database")
	ErrNoDBShards  = errors.New("data is not configured with database shards")
)
View Source
var (
	ErrObjectTypeNotRegistered = errors.New("object type not registered - use RegisterObject before using specific type")
	ErrObjectNotUsingShards    = errors.New("object not using shards while shards are supplied to query")
)

Functions

func Close

func Close() (err error)

func Default

func Default() *sql.DB

func Exec

func Exec(statement string, params ...any) exec

func Open

func Open(version Version) (err error)

func RegisterObject

func RegisterObject[objT Object[idT, shardKeyT], idT ~string, shardKeyT ~string](sharding bool, indexes ...string) (err error)

func Shards

func Shards() []*sql.DB

func Where

func Where(statement string, params ...any) where

Types

type Engine

type Engine string
const (
	EnginePostgres Engine = "postgres"
)

type Lock

type Lock[objT Object[idT, shardKeyT], idT, shardKeyT ~string] struct {
	// contains filtered or unexported fields
}

func (Lock[objT, idT, shardKeyT]) Unlock

func (l Lock[objT, idT, shardKeyT]) Unlock() (err error)

type Object

type Object[idT, shardKeyT ~string] interface {
	Trail() Trail[idT, shardKeyT]
}

type ObjectSet

type ObjectSet[objT Object[idT, shardKeyT], idT, shardKeyT ~string] struct {
	// contains filtered or unexported fields
}

func NewObjectSet

func NewObjectSet[objT Object[idT, shardKeyT], idT ~string, shardKeyT ~string]() ObjectSet[objT, idT, shardKeyT]

func (ObjectSet[objT, idT, shardKeyT]) Delete

func (os ObjectSet[objT, idT, shardKeyT]) Delete(id idT, shardKeys ...shardKeyT) (err error)

func (ObjectSet[objT, idT, shardKeyT]) Exec

func (os ObjectSet[objT, idT, shardKeyT]) Exec(exec exec, shardKeys ...shardKeyT) (err error)

func (ObjectSet[objT, idT, shardKeyT]) Insert

func (os ObjectSet[objT, idT, shardKeyT]) Insert(obj objT) (err error)

func (ObjectSet[objT, idT, shardKeyT]) Lock

func (os ObjectSet[objT, idT, shardKeyT]) Lock(obj objT, desc string) (lock *Lock[objT, idT, shardKeyT], err error)

func (ObjectSet[objT, idT, shardKeyT]) Process

func (os ObjectSet[objT, idT, shardKeyT]) Process(where where, process func(obj objT) error, shardKeys ...shardKeyT) (count int, err error)

func (ObjectSet[objT, idT, shardKeyT]) SafeUpdate

func (os ObjectSet[objT, idT, shardKeyT]) SafeUpdate(from, to objT) (err error)

func (ObjectSet[objT, idT, shardKeyT]) Select

func (os ObjectSet[objT, idT, shardKeyT]) Select(where where, shardKeys ...shardKeyT) (obs []objT, err error)

func (ObjectSet[objT, idT, shardKeyT]) SelectAll

func (os ObjectSet[objT, idT, shardKeyT]) SelectAll() (obs []objT, err error)

func (ObjectSet[objT, idT, shardKeyT]) SelectByID

func (os ObjectSet[objT, idT, shardKeyT]) SelectByID(id idT, shardKeys ...shardKeyT) (obj *objT, err error)

func (ObjectSet[objT, idT, shardKeyT]) Update

func (os ObjectSet[objT, idT, shardKeyT]) Update(obj objT) (err error)

func (ObjectSet[objT, idT, shardKeyT]) Upsert

func (os ObjectSet[objT, idT, shardKeyT]) Upsert(obj objT) (err error)

type Trail

type Trail[idT, shardKeyT ~string] struct {
	ID        idT
	ShardKey  shardKeyT
	CreatedAt time.Time
	CreatedBy string
	UpdatedAt time.Time
	UpdatedBy string
}

type Version

type Version string

Jump to

Keyboard shortcuts

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