orm

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// A schema to use when non was specified during generation
	CtxUseSchema ctxKey = iota
)

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

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(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error)

type ExecQuery added in v0.29.0

type ExecQuery[Q expression, T any, Ts ~[]T] struct {
	bob.BaseQuery[Q]
	Scanner scan.Mapper[T]
	Hooks   *bob.Hooks[Q, bob.SkipQueryHooksKey]
}

func (ExecQuery[Q, T, Ts]) Clone added in v0.29.0

func (q ExecQuery[Q, T, Ts]) Clone() ExecQuery[Q, T, Ts]

func (ExecQuery[Q, T, Ts]) Exec added in v0.29.0

func (q ExecQuery[Q, T, Ts]) Exec(ctx context.Context, exec bob.Executor) (int64, error)

Execute the query

func (ExecQuery[Q, T, Ts]) RunHooks added in v0.29.0

func (q ExecQuery[Q, T, Ts]) RunHooks(ctx context.Context, exec bob.Executor) (context.Context, error)

type Model added in v0.29.0

type Model 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
}

type Query added in v0.29.0

type Query[Q expression, T any, Ts ~[]T] struct {
	ExecQuery[Q, T, Ts]
}

func (Query[Q, T, Ts]) All added in v0.29.0

func (q Query[Q, T, Ts]) All(ctx context.Context, exec bob.Executor) (Ts, error)

All matching rows

func (Query[Q, T, Ts]) Clone added in v0.29.0

func (q Query[Q, T, Ts]) Clone() Query[Q, T, Ts]

func (Query[Q, T, Ts]) Cursor added in v0.29.0

func (q Query[Q, T, Ts]) Cursor(ctx context.Context, exec bob.Executor) (scan.ICursor[T], error)

Cursor to scan through the results

func (Query[Q, T, Ts]) One added in v0.29.0

func (q Query[Q, T, Ts]) One(ctx context.Context, exec bob.Executor) (T, error)

First matching row

type RelSetDetails added in v0.6.1

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

func (RelSetDetails) Columns added in v0.23.0

func (r RelSetDetails) Columns() []string

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          [2]string // [0] is the SQL value, [1] is the Go value
	ExternalTable  string
	ExternalColumn string
	ExtPosition    int
	ExternalStart  bool
	ExternalEnd    bool
}

func (RelSetMapping) HasValue added in v0.23.0

func (r RelSetMapping) HasValue() bool

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"`

	// These are columns that exist in the database, but should not be
	// considered by the relationship when determining if it is a join table
	// the columns are never set or read, so make sure they have a default value
	// or operations will fail
	// the first slice is for the from table, the second is for the to table
	IgnoredColumns [2][]string `yaml:"-"`

	// if the origin is unique
	FromUnique bool `yaml:"-"`
	// if the destination is unique
	ToUnique bool `yaml:"-"`

	// Which side to modify, "from" or "to"
	// If not set, it will try to "guess" which side to modify
	// - if only one of the sides contains a primary key,
	//   it will choose to modify the other side
	// - If (both or none) of them contains a primary key,
	//   it will try with "Unique" columns
	// - If it still cannot choose, it defaults to "to"
	Modify string `yaml:"modify"`

	// If the key is nullable. We need this to know if we can remove the
	// relationship without deleting it
	// this is set in Relationships.init()
	KeyNullable bool `yaml:"-"`
}

type RelWhere added in v0.6.1

type RelWhere struct {
	Column   string `yaml:"column"`
	SQLValue string `yaml:"sql_value"`
	GoValue  string `yaml:"go_value"`
}

type Relationship

type Relationship struct {
	Name  string    `yaml:"name"`
	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"`
	// Makes sure the factories does not require the relationship to be set.
	// Useful if you're not using foreign keys
	NeverRequired bool `yaml:"never_required"`
}

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) NeedsMany added in v0.23.0

func (r Relationship) NeedsMany(position int) bool

NeedsMany returns true if the table on this side needs to be many

func (Relationship) Validate added in v0.23.0

func (r Relationship) Validate() error

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 SchemaTable added in v0.29.0

type SchemaTable string

func (SchemaTable) WriteSQL added in v0.29.0

func (s SchemaTable) WriteSQL(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error)

type Setter added in v0.22.0

type Setter[T, InsertQ, UpdateQ any] interface {
	// SetColumns should return the column names that are set
	SetColumns() []string
	// Act as a mod for the insert query
	// the BeforeInsertHooks MUST be run here
	bob.Mod[InsertQ]
	// Return a mod for the update query
	// this should add "SET col1 = val1, col2 = val2, ..."
	UpdateMod() bob.Mod[UpdateQ]
}

Jump to

Keyboard shortcuts

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