Documentation ¶
Index ¶
- Variables
- func ApplyCollectionOperators(ctx context.Context, db *gorm.DB, obj interface{}, pb proto.Message, ...) (*gorm.DB, error)
- func ApplyFieldSelection(ctx context.Context, db *gorm.DB, fs *query.FieldSelection, obj interface{}) (*gorm.DB, error)
- func ApplyFiltering(ctx context.Context, db *gorm.DB, f *query.Filtering, obj interface{}, ...) (*gorm.DB, map[string]struct{}, error)
- func ApplyPagination(ctx context.Context, db *gorm.DB, p *query.Pagination) *gorm.DB
- func ApplySorting(ctx context.Context, db *gorm.DB, s *query.Sorting, obj interface{}) (*gorm.DB, map[string]struct{}, error)
- func BeginFromContext(ctx context.Context) (*gorm.DB, error)
- func FieldSelectionStringToGorm(ctx context.Context, fs string, obj interface{}) ([]string, error)
- func FieldSelectionToGorm(ctx context.Context, fs *query.FieldSelection, obj interface{}) ([]string, error)
- func FilterStringToGorm(ctx context.Context, filter string, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
- func FilteringToGorm(ctx context.Context, m *query.Filtering, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
- func HandleFieldPath(ctx context.Context, fieldPath []string, obj interface{}) (string, string, error)
- func JoinAssociations(ctx context.Context, db *gorm.DB, assoc map[string]struct{}, obj interface{}) (*gorm.DB, error)
- func JoinInfo(ctx context.Context, obj interface{}, assoc string) (string, []string, []string, error)
- func LogicalOperatorToGorm(ctx context.Context, lop *query.LogicalOperator, obj interface{}, ...) (string, []interface{}, map[string]struct{}, error)
- func MergeWithMask(source, dest interface{}, mask *ptypes.FieldMask) error
- func NewContext(parent context.Context, txn *Transaction) context.Context
- func NullConditionToGorm(ctx context.Context, c *query.NullCondition, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
- func NumberArrayConditionToGorm(ctx context.Context, c *query.NumberArrayCondition, obj interface{}, ...) (string, []interface{}, map[string]struct{}, error)
- func NumberConditionToGorm(ctx context.Context, c *query.NumberCondition, obj interface{}, ...) (string, []interface{}, map[string]struct{}, error)
- func StringArrayConditionToGorm(ctx context.Context, c *query.StringArrayCondition, obj interface{}, ...) (string, []interface{}, map[string]struct{}, error)
- func StringConditionToGorm(ctx context.Context, c *query.StringCondition, obj interface{}, ...) (string, []interface{}, map[string]struct{}, error)
- func UnaryServerInterceptor(db *gorm.DB) grpc.UnaryServerInterceptor
- func VerifyMigrationVersion(db *jgorm.DB, v MigrationVersionValidator) error
- type EmptyFieldPathError
- type MigrationVersionValidator
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ( ErrCtxTxnMissing = errors.New("Database transaction for request missing in context") ErrCtxTxnNoDB = errors.New("Transaction in context, but DB is nil") )
Functions ¶
func ApplyCollectionOperators ¶
func ApplyCollectionOperators(ctx context.Context, db *gorm.DB, obj interface{}, pb proto.Message, f *query.Filtering, s *query.Sorting, p *query.Pagination, fs *query.FieldSelection) (*gorm.DB, error)
ApplyCollectionOperators applies collection operators to gorm instance db.
func ApplyFieldSelection ¶
func ApplyFieldSelection(ctx context.Context, db *gorm.DB, fs *query.FieldSelection, obj interface{}) (*gorm.DB, error)
ApplyFieldSelection applies field selection operator fs to gorm instance db.
func ApplyFiltering ¶
func ApplyFiltering(ctx context.Context, db *gorm.DB, f *query.Filtering, obj interface{}, pb proto.Message) (*gorm.DB, map[string]struct{}, error)
ApplyFiltering applies filtering operator f to gorm instance db.
func ApplyPagination ¶
ApplyPagination applies pagination operator p to gorm instance db.
func ApplySorting ¶
func ApplySorting(ctx context.Context, db *gorm.DB, s *query.Sorting, obj interface{}) (*gorm.DB, map[string]struct{}, error)
ApplySorting applies sorting operator s to gorm instance db.
func BeginFromContext ¶ added in v0.6.0
func FieldSelectionStringToGorm ¶ added in v0.7.0
FieldSelectionStringToGorm is a shortcut to parse a string into FieldSelection struct and receive a list of associations to preload.
func FieldSelectionToGorm ¶ added in v0.7.0
func FieldSelectionToGorm(ctx context.Context, fs *query.FieldSelection, obj interface{}) ([]string, error)
FieldSelectionToGorm receives FieldSelection struct and returns a list of associations to preload.
func FilterStringToGorm ¶
func FilterStringToGorm(ctx context.Context, filter string, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
FilterStringToGorm is a shortcut to parse a filter string using default FilteringParser implementation and call FilteringToGorm on the returned filtering expression.
func FilteringToGorm ¶
func FilteringToGorm(ctx context.Context, m *query.Filtering, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
FilteringToGorm returns GORM Plain SQL representation of the filtering expression.
func HandleFieldPath ¶ added in v0.7.0
func HandleFieldPath(ctx context.Context, fieldPath []string, obj interface{}) (string, string, error)
HandleFieldPath converts fieldPath to appropriate db string for use in where/order by clauses according to obj GORM model. If fieldPath cannot be found in obj then original fieldPath is returned to allow tables joined by a third party. If association join is required to resolve the field path then it's name is returned as a second return value.
func JoinAssociations ¶ added in v0.7.0
func JoinAssociations(ctx context.Context, db *gorm.DB, assoc map[string]struct{}, obj interface{}) (*gorm.DB, error)
JoinAssociations joins obj's associations from assoc to the current gorm query.
func JoinInfo ¶ added in v0.7.0
func JoinInfo(ctx context.Context, obj interface{}, assoc string) (string, []string, []string, error)
JoinInfo extracts the following information for assoc association of obj: - association table name - source join keys - target join keys
func LogicalOperatorToGorm ¶
func LogicalOperatorToGorm(ctx context.Context, lop *query.LogicalOperator, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
LogicalOperatorToGorm returns GORM Plain SQL representation of the logical operator.
func MergeWithMask ¶ added in v0.8.0
MergeWithMask will take the fields of `source` that are included as paths in `mask` and write them to the corresponding fields of `dest`
func NewContext ¶ added in v0.5.0
func NewContext(parent context.Context, txn *Transaction) context.Context
NewContext returns a new Context that carries value txn.
func NullConditionToGorm ¶
func NullConditionToGorm(ctx context.Context, c *query.NullCondition, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
NullConditionToGorm returns GORM Plain SQL representation of the null condition.
func NumberArrayConditionToGorm ¶ added in v0.15.0
func NumberConditionToGorm ¶
func NumberConditionToGorm(ctx context.Context, c *query.NumberCondition, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
NumberConditionToGorm returns GORM Plain SQL representation of the number condition.
func StringArrayConditionToGorm ¶ added in v0.15.0
func StringConditionToGorm ¶
func StringConditionToGorm(ctx context.Context, c *query.StringCondition, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error)
StringConditionToGorm returns GORM Plain SQL representation of the string condition.
func UnaryServerInterceptor ¶ added in v0.5.0
func UnaryServerInterceptor(db *gorm.DB) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns grpc.UnaryServerInterceptor that manages a `*Transaction` instance. New *Transaction instance is created before grpc.UnaryHandler call. Client is responsible to call `txn.Begin()` to open transaction. If call of grpc.UnaryHandler returns with an error the transaction is aborted, otherwise committed.
func VerifyMigrationVersion ¶ added in v0.14.1
func VerifyMigrationVersion(db *jgorm.DB, v MigrationVersionValidator) error
VerifyMigrationVersion checks the schema_migrations table of the db passed against the ValidVersion function of the given validator, returning an error for an invalid version or a dirty database
Types ¶
type EmptyFieldPathError ¶ added in v0.7.0
type EmptyFieldPathError struct { }
func (*EmptyFieldPathError) Error ¶ added in v0.7.0
func (e *EmptyFieldPathError) Error() string
type MigrationVersionValidator ¶ added in v0.14.1
MigrationVersionValidator has a function for checking the database version
func MaxVersionFrom ¶ added in v0.14.1
func MaxVersionFrom(path string) (MigrationVersionValidator, error)
MaxVersionFrom returns a MigrationVersionValidator with a target based on the highest numbered migration file detected in the given directory
func VersionExactly ¶ added in v0.14.1
func VersionExactly(version int64) MigrationVersionValidator
VersionExactly returns a MigrationVersionValidator with a specific target version
func VersionRange ¶ added in v0.14.1
func VersionRange(lower, upper int64) MigrationVersionValidator
VersionRange returns a MigrationVersionValidator with a given lower and upper bound
type Transaction ¶ added in v0.5.0
type Transaction struct {
// contains filtered or unexported fields
}
Transaction serves as a wrapper around `*gorm.DB` instance. It works as a singleton to prevent an application of creating more than one transaction instance per incoming request.
func FromContext ¶ added in v0.5.0
func FromContext(ctx context.Context) (txn *Transaction, ok bool)
FromContext returns the *Transaction value stored in ctx, if any.
func NewTransaction ¶ added in v0.9.0
func NewTransaction(db *gorm.DB) Transaction
func (*Transaction) AddAfterCommitHook ¶ added in v0.7.0
func (t *Transaction) AddAfterCommitHook(hooks ...func(context.Context))
func (*Transaction) Begin ¶ added in v0.5.0
func (t *Transaction) Begin() *gorm.DB
Begin starts new transaction by calling `*gorm.DB.Begin()` Returns new instance of `*gorm.DB` (error can be checked by `*gorm.DB.Error`)
func (*Transaction) Commit ¶ added in v0.5.0
func (t *Transaction) Commit(ctx context.Context) error
Commit finishes transaction by calling `*gorm.DB.Commit()` Reset current transaction and returns an error if any.
func (*Transaction) Rollback ¶ added in v0.5.0
func (t *Transaction) Rollback() error
Rollback terminates transaction by calling `*gorm.DB.Rollback()` Reset current transaction and returns an error if any.