database

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIterStop = fmt.Errorf("stop iteration")
)

Functions

func Cursor

func Cursor[E Entity](db *DynamicDB, ent E, query string, args ...any) *cursor[E]

func DataDir

func DataDir() string

Types

type Collection

type Collection[E Entity] struct {
	DB   *DynamicDB
	Ent  E
	Type reflect.Type
}

func Manage

func Manage[E Entity](db *DynamicDB, ent E) *Collection[E]

func (*Collection[E]) Count

func (c *Collection[E]) Count() (count int)

func (*Collection[E]) Delete

func (c *Collection[E]) Delete(ent E) error

func (*Collection[E]) Find

func (c *Collection[E]) Find(query string, args ...any) (E, error)

func (*Collection[E]) Get

func (c *Collection[E]) Get(id string) (E, error)

func (*Collection[E]) Index added in v1.3.0

func (c *Collection[E]) Index(columns ...string) error

Index creates an index on the collection's table Example: Repositories.Index("UserID", "Visibility")

func (*Collection[E]) Insert

func (c *Collection[E]) Insert(ent E) (E, error)

func (*Collection[E]) New

func (c *Collection[E]) New() E

func (*Collection[E]) Search

func (c *Collection[E]) Search(query string, args ...any) ([]E, error)

func (*Collection[E]) UniqueIndex added in v1.3.0

func (c *Collection[E]) UniqueIndex(columns ...string) error

UniqueIndex creates a unique index on the collection's table Example: Permissions.UniqueIndex("RepoID", "UserID")

func (*Collection[E]) Update

func (c *Collection[E]) Update(ent E) error

type Database

type Database interface {
	// modeling api
	Model() Model
	NewModel(id string) Model

	// querying api
	Query(string, ...any) *Iter
}

type DynamicDB

type DynamicDB struct {
	Database
	Ents  []Entity
	Repos map[string]*Collection[Entity]
}

func Dynamic

func Dynamic(engine Database, opts ...DynamicDBOption) *DynamicDB

func (*DynamicDB) Delete

func (db *DynamicDB) Delete(ent Entity) error

func (*DynamicDB) Fields

func (db *DynamicDB) Fields(ent Entity) (fields []string, types []string, defaults []string)

func (*DynamicDB) Get

func (db *DynamicDB) Get(id string, ent Entity) error

func (*DynamicDB) Index added in v1.3.0

func (db *DynamicDB) Index(table string, columns ...string) error

Index creates an index on the specified table and columns Example: db.Index("users", "email") creates idx_users_email

func (*DynamicDB) Insert

func (db *DynamicDB) Insert(ent Entity) error

func (*DynamicDB) Model

func (db *DynamicDB) Model() Model

func (*DynamicDB) NewModel

func (db *DynamicDB) NewModel(id string) Model

func (*DynamicDB) Reflect

func (db *DynamicDB) Reflect(ent Entity) (fields []string, values []any, addrs []any)

func (*DynamicDB) Register

func (db *DynamicDB) Register(ent Entity) error

func (*DynamicDB) UniqueIndex added in v1.3.0

func (db *DynamicDB) UniqueIndex(table string, columns ...string) error

UniqueIndex creates a unique index on the specified table and columns Example: db.UniqueIndex("users", "email") creates uniq_users_email

func (*DynamicDB) Update

func (db *DynamicDB) Update(ent Entity) error

type DynamicDBOption

type DynamicDBOption func(*DynamicDB)

func WithModel

func WithModel(ent Entity) DynamicDBOption

type Entity

type Entity interface {
	Table() string
	GetModel() *Model
}

type Iter

type Iter struct {
	Conn *sql.DB
	Text string
	Args []any
}

func (*Iter) All

func (i *Iter) All(fn reader) error

func (*Iter) Exec

func (i *Iter) Exec() error

func (*Iter) Page

func (i *Iter) Page(limit int, fn reader) (more bool, err error)

func (*Iter) Scan

func (i *Iter) Scan(args ...any) error

type Model

type Model struct {
	DB        Database
	ID        string
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*Model) GetModel

func (m *Model) GetModel() *Model

func (*Model) SetDB

func (m *Model) SetDB(d Database)

type ScanFunc

type ScanFunc func(...any) error

Directories

Path Synopsis
engines

Jump to

Keyboard shortcuts

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