specs

package
v0.0.0-...-7ba985f Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder[T Model] interface {
	Context() context.Context
	Connector() Connector

	Get(primaryKey any) (T, error)
	Delete(primaryKey any) error

	Create() (err error)
	Update() error

	Find() (T, error)
	FindAll() ([]T, error)

	SetFields(field ...string) Builder[T]
	SetWhere(condition Condition) Builder[T]
	SetLimit(limit int) Builder[T]
	SetOffset(offset int) Builder[T]
	SetOrderBy(fields ...string) Builder[T]

	Count() (total int64, err error)

	Payload() PayloadAugmented[T]

	SetModel(model T) Builder[T]

	Fields() []string
	Wheres() []Condition
}

type BuilderUse

type BuilderUse[T Model] func(ctx context.Context, connector Connector) Builder[T]

type Condition

type Condition interface {
	From() string
	Operator() string
	To() any

	SetFrom(from string) Condition
	SetOperator(operator string) Condition
	SetTo(to any) Condition
}

type Config

type Config interface {
	Name() string
	SetName(name string) Config

	Driver() string
	SetDriver(driver string) Config

	User() string
	SetUser(user string) Config

	Password() string
	SetPassword(password string) Config

	Host() string
	SetHost(host string) Config

	Port() int
	SetPort(port int) Config

	Database() string
	SetDatabase(database string) Config

	Locale() string
	SetLocale(locale string) Config
}

type Connector

type Connector interface {
	Driver

	Config() Config

	Name() string
	SetName(name string) Connector
}

type Driver

type Driver interface {
	New(config Config) error
	Get() *sql.DB

	Select(ctx context.Context, payload Payload) error
}

type DriverField

type DriverField interface {
	Index() int
	Column() string
	Database() string
	Table() string
	Name() string

	IsCustom() bool

	SetIndex(index int) DriverField
	SetColumn(name string) DriverField
	SetTable(name string) DriverField
	SetDatabase(name string) DriverField
	SetName(name string) DriverField

	SetCustom(fn string, args []DriverField) DriverField

	Formatted() (string, error)
}

DriverField is the interface that wraps the basic methods of a field.

type DriverJoin

type DriverJoin interface {
	Validate() error

	Method() string
	From() DriverField
	To() DriverField

	SetMethod(method JoinMethod) DriverJoin
	SetFrom(field DriverField) DriverJoin
	SetTo(field DriverField) DriverJoin

	Formatted() (string, error)
}

type DriverLimit

type DriverLimit interface {
	Offset() int
	Limit() int

	SetOffset(index int) DriverLimit
	SetLimit(index int) DriverLimit

	Formatted() (string, error)
}

type DriverWhere

type DriverWhere interface {
	From() DriverField
	Operator() string
	To() any

	SetFrom(from DriverField) DriverWhere
	SetOperator(operator string) DriverWhere
	SetTo(to any) DriverWhere

	Formatted() (value string, args []any, err error)
}

type ErrFieldNoFoundByColumn

type ErrFieldNoFoundByColumn interface {
	error
	Column() string
	ModelDefinition() ModelDefinition
}

type ErrFieldRequired

type ErrFieldRequired error

type ErrNotFoundError

type ErrNotFoundError error

type ErrPrimaryFieldNotFound

type ErrPrimaryFieldNotFound error

type ErrRequiredFieldJoin

type ErrRequiredFieldJoin interface {
	error
	Fields() []string
}

type ErrUnknownFields

type ErrUnknownFields interface {
	error
	Fields() []string
}

type ErrUnknownOperator

type ErrUnknownOperator interface {
	error
	Operator() string
}

type FieldDefinition

type FieldDefinition interface {
	// Init allows you to initialise the field with its default value recursively (to avoid `nil`)
	Init()
	// Name returns the name of the field
	Name() string
	// Model returns the schema of the field
	Model() ModelDefinition
	// Tags returns the tags of the field
	Tags() map[string]string
	FromSchemaTypeList() []string
	RecursiveFullName() string
	FundamentalName() string
	Column() string
	ForeignKey() string
	Index() int

	GetByColumn() (FieldDefinition, error)
	GetToColumn() (FieldDefinition, error)

	Join() []DriverJoin
	Field() DriverField

	Value() reflect.Value

	Copy() any

	Set(value any)
	Get() any

	HasEmbeddedSchema() bool
	EmbeddedSchema() ModelDefinition

	IsSlice() bool
	FromSlice() bool

	IsPrimaryKey() bool
}

FieldDefinition is the interface that describes a field

type JoinMethod

type JoinMethod int

type Model

type Model interface {
	DatabaseName() string
	TableName() string
}

type ModelDefinition

type ModelDefinition interface {
	Model

	Fields() []FieldDefinition
	FieldByName() map[string]FieldDefinition

	GetFieldByName(name string) (FieldDefinition, ErrNotFoundError)
	GetPrimaryField() (FieldDefinition, ErrPrimaryFieldNotFound)
	GetFieldByColumn(column string) (FieldDefinition, ErrFieldNoFoundByColumn)

	SetFromField(fromField FieldDefinition) ModelDefinition
	FromField() FieldDefinition

	SetIndex(index int) ModelDefinition
	Index() int
	Counter() int

	Parse() ModelDefinition

	TypeName() string

	ModelValue() reflect.Value
	ModelOrigin() reflect.Value

	Copy() Model
}

type NewPayload

type NewPayload[T Model] func(model ...Model) PayloadAugmented[T]

type NewSubBuilder

type NewSubBuilder[T Model] func() SubBuilder[T]

type NewSubBuilderJob

type NewSubBuilderJob[T Model] func(builder Builder[T], fundamentalName string, model ModelDefinition) SubBuilderJob[T]

type Payload

type Payload interface {
	Table() string
	Database() string
	Index() int

	Fields() []DriverField
	Join() []DriverJoin
	Where() []DriverWhere
	Limit() DriverLimit

	SetFields([]DriverField) Payload
	SetJoins([]DriverJoin) Payload
	SetWheres([]DriverWhere) Payload
	SetLimit(DriverLimit) Payload

	Mapping() ([]any, error)
	OnScan([]any) error
}

type PayloadAugmented

type PayloadAugmented[T Model] interface {
	Payload
	Result() []T
}

type SqlIn

type SqlIn func(query string, args ...interface{}) (string, []interface{}, error)

type SubBuilder

type SubBuilder[T Model] interface {
	AddJob(Builder[T], string, ModelDefinition) SubBuilder[T]
	Execute() error
}

type SubBuilderJob

type SubBuilderJob[T Model] interface {
	Execute() error
}

type UseModelDefinition

type UseModelDefinition func(model Model) ModelDefinition

Jump to

Keyboard shortcuts

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