model

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNothingToUpdate = errors.New("nothing to update")

Functions

func LoadExceptColumns

func LoadExceptColumns(cols ...string) exceptColumnsOpt

func LoadOnlyColumns

func LoadOnlyColumns(cols ...string) onlyColumnsOpt

func NewEagerLoadSettings

func NewEagerLoadSettings[T any, Ts ~[]T](cols orm.Columns) eagerLoadSettings

Types

type EagerLoadOption

type EagerLoadOption interface {
	ModifyEagerLoader(*eagerLoadSettings)
}

type EagerLoader

type EagerLoader func(ctx context.Context) (bob.Mod[*psql.SelectQuery], scan.MapperMod, []bob.ExtraLoader)

func Preload

func Preload[T any, Ts ~[]T](rel orm.Relationship, cols orm.Columns, opts ...EagerLoadOption) EagerLoader

func (EagerLoader) Apply

func (l EagerLoader) Apply(q *psql.SelectQuery)

func (EagerLoader) ModifyEagerLoader

func (l EagerLoader) ModifyEagerLoader(s *eagerLoadSettings)

type Filterable

type Filterable interface {
	AppendWhere(...any)
}

type Loader

type Loader bob.LoadFunc

func (Loader) Apply

func (l Loader) Apply(q *psql.SelectQuery)

func (Loader) ModifyEagerLoader

func (l Loader) ModifyEagerLoader(s *eagerLoadSettings)

type Table

type Table[T any, Tslice ~[]T, Topt any] struct {
	*View[T, Tslice]

	BeforeInsertHooks orm.Hooks[Topt]
	AfterInsertHooks  orm.Hooks[T]

	BeforeUpsertHooks orm.Hooks[Topt]
	AfterUpsertHooks  orm.Hooks[T]

	BeforeUpdateHooks orm.Hooks[T]
	AfterUpdateHooks  orm.Hooks[T]

	BeforeDeleteHooks orm.Hooks[T]
	AfterDeleteHooks  orm.Hooks[T]
	// contains filtered or unexported fields
}

The table contains extract information from the struct and contains caches ???

func NewTable

func NewTable[T any, Tslice ~[]T, Topt any](name0 string, nameX ...string) Table[T, Tslice, Topt]

func (*Table[T, Tslice, Topt]) Delete

func (t *Table[T, Tslice, Topt]) Delete(ctx context.Context, exec bob.Executor, row T) (int64, error)

Deletes the given model if columns is nil, every column is deleted

func (*Table[T, Tslice, Topt]) DeleteMany

func (t *Table[T, Tslice, Topt]) DeleteMany(ctx context.Context, exec bob.Executor, rows ...T) (int64, error)

Deletes the given models if columns is nil, every column is deleted

func (*Table[T, Tslice, Topt]) Insert

func (t *Table[T, Tslice, Topt]) Insert(ctx context.Context, exec bob.Executor, row Topt) (T, error)

Insert inserts a row into the table with only the set columns in Topt

func (*Table[T, Tslice, Topt]) InsertMany

func (t *Table[T, Tslice, Topt]) InsertMany(ctx context.Context, exec bob.Executor, rows ...Topt) (Tslice, error)

Insert inserts a row into the table with only the set columns in Topt

func (*Table[T, Tslice, Topt]) PKColumns added in v0.5.0

func (t *Table[T, Tslice, Topt]) PKColumns() orm.Columns

Returns a column list

func (*Table[T, Tslice, Topt]) Query

func (t *Table[T, Tslice, Topt]) Query(queryMods ...bob.Mod[*psql.SelectQuery]) *TableQuery[T, Tslice, Topt]

Adds table name et al

func (*Table[T, Tslice, Topt]) Update

func (t *Table[T, Tslice, Topt]) Update(ctx context.Context, exec bob.Executor, cols []string, row T) (int64, error)

Updates the given model if columns is nil, every non-primary-key column is updated NOTE: values from the DB are not refreshed into the model

func (*Table[T, Tslice, Topt]) UpdateMany

func (t *Table[T, Tslice, Topt]) UpdateMany(ctx context.Context, exec bob.Executor, vals Topt, rows ...T) (int64, error)

Updates the given models if columns is nil, every column is updated NOTE: values from the DB are not refreshed into the models

func (*Table[T, Tslice, Topt]) Upsert

func (t *Table[T, Tslice, Topt]) Upsert(ctx context.Context, exec bob.Executor, updateOnConflict bool, conflictCols, updateCols []string, row Topt) (T, error)

Uses the optional columns to know what to insert If conflictCols is nil, it uses the primary key columns If updateCols is nil, it updates all the columns set in Topt if no column is set in Topt (i.e. INSERT DEFAULT VALUES), then it upserts all NonPK columns

func (*Table[T, Tslice, Topt]) UpsertMany

func (t *Table[T, Tslice, Topt]) UpsertMany(ctx context.Context, exec bob.Executor, updateOnConflict bool, conflictCols, updateCols []string, rows ...Topt) (Tslice, error)

Uses the optional columns to know what to insert If conflictCols is nil, it uses the primary key columns If updateCols is nil, it updates all the columns set in Topt if no column is set in Topt (i.e. INSERT DEFAULT VALUES), then it upserts all NonPK columns

type TableQuery

type TableQuery[T any, Ts ~[]T, Topt any] struct {
	ViewQuery[T, Ts]
	// contains filtered or unexported fields
}

func (*TableQuery[T, Tslice, Topt]) DeleteAll

func (t *TableQuery[T, Tslice, Topt]) DeleteAll(ctx context.Context, exec bob.Executor) (int64, error)

DeleteAll deletes all rows matched by the current query NOTE: Hooks cannot be run since the values are never retrieved

func (*TableQuery[T, Tslice, Topt]) UpdateAll

func (t *TableQuery[T, Tslice, Topt]) UpdateAll(ctx context.Context, exec bob.Executor, vals Topt) (int64, error)

UpdateAll updates all rows matched by the current query NOTE: Hooks cannot be run since the values are never retrieved

type View

type View[T any, Tslice ~[]T] struct {
	AfterSelectHooks orm.Hooks[T]
	// contains filtered or unexported fields
}

func NewView

func NewView[T any, Tslice ~[]T](name0 string, nameX ...string) View[T, Tslice]

func (*View[T, Tslice]) Columns

func (t *View[T, Tslice]) Columns() orm.Columns

Returns a column list

func (*View[T, Tslice]) Name

func (t *View[T, Tslice]) Name() psql.Expression

func (*View[T, Tslice]) Query

func (t *View[T, Tslice]) Query(queryMods ...bob.Mod[*psql.SelectQuery]) *ViewQuery[T, Tslice]

Adds table name et al

type ViewQuery

type ViewQuery[T any, Ts ~[]T] struct {
	bob.BaseQuery[*psql.SelectQuery]
	// contains filtered or unexported fields
}

func (*ViewQuery[T, Tslice]) All

func (f *ViewQuery[T, Tslice]) All(ctx context.Context, exec bob.Executor) (Tslice, error)

func (*ViewQuery[T, Tslice]) Count

func (f *ViewQuery[T, Tslice]) Count(ctx context.Context, exec bob.Executor) (int64, error)

func (*ViewQuery[T, Tslice]) Cursor

func (f *ViewQuery[T, Tslice]) Cursor(ctx context.Context, exec bob.Executor) (scan.ICursor[T], error)

func (*ViewQuery[T, Tslice]) Exists

func (f *ViewQuery[T, Tslice]) Exists(ctx context.Context, exec bob.Executor) (bool, error)

func (*ViewQuery[T, Tslice]) One

func (f *ViewQuery[T, Tslice]) One(ctx context.Context, exec bob.Executor) (T, error)

type WhereMod

type WhereMod[Q Filterable, C any] struct {
	// contains filtered or unexported fields
}

func Where

func Where[Q Filterable, C any](name psql.Expression) WhereMod[Q, C]

func (WhereMod[Q, C]) EQ

func (w WhereMod[Q, C]) EQ(val C) bob.Mod[Q]

func (WhereMod[Q, C]) GT

func (w WhereMod[Q, C]) GT(val C) bob.Mod[Q]

func (WhereMod[Q, C]) GTE

func (w WhereMod[Q, C]) GTE(val C) bob.Mod[Q]

func (WhereMod[Q, C]) In added in v0.6.1

func (w WhereMod[Q, C]) In(slice ...C) bob.Mod[Q]

func (WhereMod[Q, C]) LT

func (w WhereMod[Q, C]) LT(val C) bob.Mod[Q]

func (WhereMod[Q, C]) LTE

func (w WhereMod[Q, C]) LTE(val C) bob.Mod[Q]

func (WhereMod[Q, C]) NE

func (w WhereMod[Q, C]) NE(val C) bob.Mod[Q]

func (WhereMod[Q, C]) NotIn added in v0.6.1

func (w WhereMod[Q, C]) NotIn(slice ...C) bob.Mod[Q]

type WhereNullMod

type WhereNullMod[Q interface {
	AppendWhere(e ...any)
}, C any] struct {
	WhereMod[Q, C]
}

func WhereNull

func WhereNull[Q Filterable, C any](name psql.Expression) WhereNullMod[Q, C]

func (WhereNullMod[Q, C]) IsNotNull

func (w WhereNullMod[Q, C]) IsNotNull() bob.Mod[Q]

func (WhereNullMod[Q, C]) IsNull

func (w WhereNullMod[Q, C]) IsNull() bob.Mod[Q]

Jump to

Keyboard shortcuts

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