Documentation ¶
Index ¶
- func ApplyCollectionOperators(db *gorm.DB, ctx context.Context) (*gorm.DB, error)
- func ApplyFieldSelection(db *gorm.DB, fs *query.FieldSelection) *gorm.DB
- func ApplyFiltering(db *gorm.DB, f *query.Filtering) (*gorm.DB, error)
- func ApplyPagination(db *gorm.DB, p *query.Pagination) *gorm.DB
- func ApplySorting(db *gorm.DB, s *query.Sorting) *gorm.DB
- func FilterStringToGorm(filter string) (string, []interface{}, error)
- func FilteringToGorm(m *query.Filtering) (string, []interface{}, error)
- func LogicalOperatorToGorm(lop *query.LogicalOperator) (string, []interface{}, error)
- func NewContext(parent context.Context, txn *Transaction) context.Context
- func NullConditionToGorm(c *query.NullCondition) (string, []interface{}, error)
- func NumberConditionToGorm(c *query.NumberCondition) (string, []interface{}, error)
- func StringConditionToGorm(c *query.StringCondition) (string, []interface{}, error)
- func UnaryServerInterceptor(db *gorm.DB) grpc.UnaryServerInterceptor
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyFieldSelection ¶
ApplyFieldSelection applies field selection operator fs to gorm instance db.
func ApplyFiltering ¶
ApplyFiltering applies filtering operator f to gorm instance db.
func ApplyPagination ¶
ApplyPagination applies pagination operator p to gorm instance db.
func ApplySorting ¶
ApplySorting applies sorting operator s to gorm instance db.
func FilterStringToGorm ¶
FilterStringToGorm is a shortcut to parse a filter string using default FilteringParser implementation and call FilteringToGorm on the returned filtering expression.
func FilteringToGorm ¶
FilteringToGorm returns GORM Plain SQL representation of the filtering expression.
func LogicalOperatorToGorm ¶
func LogicalOperatorToGorm(lop *query.LogicalOperator) (string, []interface{}, error)
LogicalOperatorToGorm returns GORM Plain SQL representation of the logical operator.
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(c *query.NullCondition) (string, []interface{}, error)
NullConditionToGorm returns GORM Plain SQL representation of the null condition.
func NumberConditionToGorm ¶
func NumberConditionToGorm(c *query.NumberCondition) (string, []interface{}, error)
NumberConditionToGorm returns GORM Plain SQL representation of the number condition.
func StringConditionToGorm ¶
func StringConditionToGorm(c *query.StringCondition) (string, []interface{}, 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.
Types ¶
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 (*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() 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.