orm

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: MIT Imports: 6 Imported by: 13

Documentation

Index

Constants

View Source
const (
	// The alias of an eager loader's parent
	CtxLoadParentAlias ctxKey = iota
	// A schema to use when non was specified during generation
	CtxUseSchema
)

Variables

View Source
var (
	ErrNothingToUpdate   = errors.New("nothing to update")
	ErrCannotRetrieveRow = errors.New("cannot retrieve inserted row")
	ErrCannotPrepare     = errors.New("supplied executor does not implement bob.Preparer")
)

Functions

func Except added in v0.15.0

func Except(cols []string, excludes ...string) []string

Except drops the given column names from the column set

func Only added in v0.15.0

func Only(cols []string, includes ...string) []string

Only drops other column names from the column set

func SkipHooks added in v0.2.3

func SkipHooks(ctx context.Context) context.Context

SkipHooks modifies a context to prevent hooks from running for any query it encounters.

func SkipModelHooks added in v0.22.0

func SkipModelHooks(ctx context.Context) context.Context

SkipModelHooks modifies a context to prevent hooks from running on models.

func SkipQueryHooks added in v0.22.0

func SkipQueryHooks(ctx context.Context) context.Context

SkipQueryHooks modifies a context to prevent hooks from running on querys.

Types

type Columns

type Columns struct {
	// contains filtered or unexported fields
}

func NewColumns

func NewColumns(names ...string) Columns

NewColumns returns a Columns object with the given column names

func (Columns) Except

func (c Columns) Except(cols ...string) Columns

Except drops the given column names from the column set

func (Columns) Names added in v0.3.1

func (c Columns) Names() []string

Names returns the names of the columns

func (Columns) Only

func (c Columns) Only(cols ...string) Columns

Only drops other column names from the column set

func (Columns) WithAggFunc

func (c Columns) WithAggFunc(a, b string) Columns

func (Columns) WithParent

func (c Columns) WithParent(p ...string) Columns

WithPrefix sets the parent of the columns

func (Columns) WithPrefix

func (c Columns) WithPrefix(prefix string) Columns

WithPrefix sets the prefix of the aliases of the column set

func (Columns) WriteSQL

func (c Columns) WriteSQL(w io.Writer, d bob.Dialect, start int) ([]any, error)

type Hook added in v0.2.3

type Hook[T any] func(context.Context, bob.Executor, T) (context.Context, error)

Hook is a function that can be called during lifecycle of an object the context can be modified and returned The caller is expected to use the returned context for subsequent processing

type Hooks added in v0.2.3

type Hooks[T any, K any] struct {
	// contains filtered or unexported fields
}

Hooks is a set of hooks that can be called all at once

func (*Hooks[T, K]) Add added in v0.2.3

func (h *Hooks[T, K]) Add(hook Hook[T])

Add a hook to the set

func (*Hooks[T, K]) Do added in v0.2.3

func (h *Hooks[T, K]) Do(ctx context.Context, exec bob.Executor, o T) (context.Context, error)

Do calls all the registered hooks. if the context is set to skip hooks using SkipHooks, then Do simply returns the context

type RelSetDetails added in v0.6.1

type RelSetDetails struct {
	TableName string
	Mapped    []RelSetMapping
	Position  int
	Start     bool
	End       bool
}

func (RelSetDetails) UniqueExternals added in v0.22.0

func (r RelSetDetails) UniqueExternals() []RelSetMapping

type RelSetMapping added in v0.6.1

type RelSetMapping struct {
	Column         string
	Value          string
	ExternalTable  string
	ExternalColumn string
	ExternalStart  bool
	ExternalEnd    bool
	ExtPosition    int
}

type RelSide added in v0.2.1

type RelSide struct {
	From string `yaml:"from"`
	To   string `yaml:"to"`

	// To make sure the column lengths match and are in the right order,
	// a slice of tupules is expected.
	// bobgen-helpers.GenConfig has a function to spread that into From/ToColumns
	Columns     [][2]string `yaml:"columns"`
	FromColumns []string    `yaml:"-"`
	ToColumns   []string    `yaml:"-"`

	FromWhere []RelWhere `yaml:"from_where"`
	ToWhere   []RelWhere `yaml:"to_where"`

	// If the destination columns contain the key
	// if false, it means the source columns are the foreign key
	ToKey bool `yaml:"to_key"`
	// if the destination is unique
	ToUnique bool `yaml:"to_unique"`
	// If the key is nullable. We need this to know if we can remove the
	// relationship without deleting it
	KeyNullable bool `yaml:"key_nullable"`

	// Kinda hacky, used for preloading
	ToExpr func(context.Context) bob.Expression `json:"-" yaml:"-"`
}

type RelWhere added in v0.6.1

type RelWhere struct {
	Column  string `yaml:"column"`
	Value   string `yaml:"value"`
	GoValue string `yaml:"go_value"`
}

type Relationship

type Relationship struct {
	Name        string    `yaml:"name"`
	ByJoinTable bool      `yaml:"by_join_table"`
	Sides       []RelSide `yaml:"sides"`

	// These can be set through user configuration
	Ignored bool
	// Do not create the inverse of a user configured relationship
	NoReverse bool `yaml:"no_reverse"`

	// if present is used instead of computing from the columns
	// only expected to be set by drivers not by configuration
	// configuration should set aliases though the alias configuration
	Alias string `yaml:"-"`
}

func (Relationship) Foreign added in v0.6.1

func (r Relationship) Foreign() string

func (Relationship) ForeignPosition added in v0.22.0

func (r Relationship) ForeignPosition() int

func (Relationship) InsertEarly added in v0.6.1

func (r Relationship) InsertEarly() bool

func (Relationship) IsRemovable added in v0.6.1

func (r Relationship) IsRemovable() bool

func (Relationship) IsToMany added in v0.6.1

func (r Relationship) IsToMany() bool

func (Relationship) Local added in v0.6.1

func (r Relationship) Local() string

func (Relationship) LocalPosition added in v0.22.0

func (r Relationship) LocalPosition() int

func (Relationship) NeededBridgeTables added in v0.22.0

func (r Relationship) NeededBridgeTables() []string

func (Relationship) NeededMappings added in v0.22.0

func (r Relationship) NeededMappings() []RelSetMapping

func (Relationship) ValuedSides added in v0.6.1

func (r Relationship) ValuedSides() []RelSetDetails

type RelationshipChainError added in v0.6.1

type RelationshipChainError struct {
	Table1  string
	Column1 string
	Value   string
	Table2  string
	Column2 string
}

RelationshipChainError is the error returned when a wrong value is encountered in a relationship chain

func (*RelationshipChainError) Error added in v0.6.1

func (e *RelationshipChainError) Error() string

type Setter added in v0.22.0

type Setter[T any, InsertQ any, UpdateQ any] interface {
	// SetColumns should return the column names that are set
	SetColumns() []string
	// Overwrite the values in T with the set values in the setter
	Overwrite(T)
	// Act as a mod for the update query
	bob.Mod[UpdateQ]
	// Return a mod for the insert query
	Insert() bob.Mod[InsertQ]
}

type SkipModelHooksKey added in v0.22.0

type SkipModelHooksKey struct{}

If set to true, model hooks are skipped

type SkipQueryHooksKey added in v0.22.0

type SkipQueryHooksKey struct{}

If set to true, query hooks are skipped

type Table added in v0.22.0

type Table interface {
	// PrimaryKeyVals returns the values of the primary key columns
	// If a single column, expr.Arg(col) is expected
	// If multiple columns, expr.ArgGroup(col1, col2, ...) is expected
	PrimaryKeyVals() bob.Expression
}

Jump to

Keyboard shortcuts

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