models

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBackendNotFound = errors.New("backend not found")
)

Functions

func NewBackendRegistry

func NewBackendRegistry[T BaseQuerier[T]]() *backendRegistry[T]

Types

type Backend

type Backend[T any] interface {
	CreateTable(*sql.DB) error
	NewQuerySet(*sql.DB) (T, error)
	Prepare(ctx context.Context, db *sql.DB) (T, error)
}

type BaseBackend

type BaseBackend[T any] struct {
	CreateTableQuery string
	NewQuerier       func(*sql.DB) (T, error)
	PreparedQuerier  func(ctx context.Context, d *sql.DB) (T, error)
}

func (*BaseBackend[T]) CreateTable

func (b *BaseBackend[T]) CreateTable(db *sql.DB) error

func (*BaseBackend[T]) NewQuerySet

func (b *BaseBackend[T]) NewQuerySet(db *sql.DB) (T, error)

func (*BaseBackend[T]) Prepare

func (b *BaseBackend[T]) Prepare(ctx context.Context, d *sql.DB) (T, error)

type BaseQuerier

type BaseQuerier[T any] interface {
	WithTx(tx *sql.Tx) T
	Close() error
}

type BaseSQLField

type BaseSQLField[DBType, GoType any] struct {
	ConvertToDB func(*GoType) (DBType, error)
	ConvertToGO func(DBType) (*GoType, error)
	// contains filtered or unexported fields
}

func EmailField

func EmailField() *BaseSQLField[string, mail.Address]

func NewBaseSQLField

func NewBaseSQLField[DBType, GoType any](convertToDB func(*GoType) (DBType, error), convertToGO func(DBType) (*GoType, error)) *BaseSQLField[DBType, GoType]

func (*BaseSQLField[DBType, GoType]) Scan

func (f *BaseSQLField[DBType, GoType]) Scan(value interface{}) error

func (*BaseSQLField[DBType, GoType]) Value

func (f *BaseSQLField[DBType, GoType]) Value() (driver.Value, error)

type Deleter

type Deleter interface {
	Delete(c context.Context) error
}

type Model

type Model interface {
	attrs.Definer
	Saver
	Deleter
}

type Reloader

type Reloader interface {
	Reload(c context.Context) error
}

type SQLField

type SQLField interface {
	driver.Valuer
	sql.Scanner
}

type Saver

type Saver interface {
	Save(c context.Context) error
}

type Updater

type Updater interface {
	Update(c context.Context) error
}

Jump to

Keyboard shortcuts

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