Documentation ¶
Index ¶
- Variables
- func AsConflictError(err error, messageFormat string, args ...interface{}) *errors.Error
- func AsForeignKeyError(err error, messageFormat string, args ...interface{}) *errors.Error
- func AsNotFoundError(err error, messageFormat string, args ...interface{}) *errors.Error
- func Clone(ctx context.Context) context.Context
- func Context() context.Context
- func Copy(ctx context.Context) context.Context
- func CreateInClause(ctx context.Context, sql string, args ...interface{}) (string, error)
- func Escape(str string) string
- func FromContext(ctx context.Context) (orm.QueryExecutor, error)
- func GetTransactionOpNameFromContext(ctx context.Context) string
- func HasCommittedKey(ctx context.Context) bool
- func IsDuplicateKeyError(err error) bool
- func NewContext(ctx context.Context, o orm.QueryExecutor) context.Context
- func PaginationOnRawSQL(query *q.Query, sql string, params []interface{}) (string, []interface{})
- func ParamPlaceholderForIn(n int) string
- func QuerySetter(ctx context.Context, model interface{}, query *q.Query, options ...Option) (orm.QuerySeter, error)
- func QuerySetterForCount(ctx context.Context, model interface{}, query *q.Query, _ ...string) (orm.QuerySeter, error)
- func QuoteLiteral(literal string) string
- func ReadOrCreate(ctx context.Context, md interface{}, col1 string, cols ...string) (created bool, id int64, err error)
- func RegisterModel(models ...interface{})
- func SetTransactionOpNameToContext(ctx context.Context, name string) context.Context
- func WithTransaction(f func(ctx context.Context) error) func(ctx context.Context) error
- func WrapConflictError(err error, format string, args ...interface{}) error
- func WrapNotFoundError(err error, format string, args ...interface{}) error
- type CommittedKey
- type Condition
- type Config
- type Creator
- type Option
- type Params
- type ParamsList
- type QuerySeter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoRows error from the beego orm ErrNoRows = orm.ErrNoRows // ErrOptimisticLock error when update object failed ErrOptimisticLock = errors.New("the object has been modified; please apply your changes to the latest version and try again") )
var ( // Crt is a global instance of ORM creator Crt = NewCreator() )
var NewCondition = orm.NewCondition
NewCondition alias function of orm.NewCondition
Functions ¶
func AsConflictError ¶
AsConflictError checks whether the err is duplicate key error. If it is, wrap it as a src/internal/error.Error with conflict error code, else return nil
func AsForeignKeyError ¶
AsForeignKeyError checks whether the err is violating foreign key constraint error. If it it, wrap it as a src/internal/error.Error with violating foreign key constraint error code, else return nil
func AsNotFoundError ¶
AsNotFoundError checks whether the err is orm.ErrNoRows. If it it, wrap it as a src/internal/error.Error with not found error code, else return nil
func Copy ¶
Copy returns new context with orm and value from parent context but no linkage of parent.
func CreateInClause ¶
CreateInClause creates an IN clause with the provided sql and args to avoid the sql injection The sql should return the ID list with the specific condition(e.g. select id from table1 where column1=?) The sql runs as a prepare statement with the "?" be populated rather than concat string directly The returning in clause is a string like "IN (id1, id2, id3, ...)"
func FromContext ¶
func FromContext(ctx context.Context) (orm.QueryExecutor, error)
FromContext returns orm from context
func GetTransactionOpNameFromContext ¶
GetTransactionOpNameFromContext returns the transaction operation name from context
func HasCommittedKey ¶
HasCommittedKey checks whether exist committed key in context.
func IsDuplicateKeyError ¶
IsDuplicateKeyError check the duplicate key error
func NewContext ¶
NewContext returns new context with orm
func PaginationOnRawSQL ¶
PaginationOnRawSQL append page information to the raw sql It should be called after the order by e.g. select a, b, c from mytable order by a limit ? offset ? it appends the " limit ? offset ? " to sql, and appends the limit value and offset value to the params of this query
func ParamPlaceholderForIn ¶
ParamPlaceholderForIn returns a string that contains placeholders for sql keyword "in" e.g. n=3, returns "?,?,?"
func QuerySetter ¶
func QuerySetterForCount ¶
func QuerySetterForCount(ctx context.Context, model interface{}, query *q.Query, _ ...string) (orm.QuerySeter, error)
QuerySetterForCount creates the query setter used for count with the sort and pagination information ignored
func QuoteLiteral ¶
QuoteLiteral quotes a 'literal' (e.g. a parameter, often used to pass literal to DDL and other statements that do not accept parameters) to be used as part of an SQL statement. For example:
exp_date := pq.QuoteLiteral("2023-01-05 15:00:00Z") err := db.Exec(fmt.Sprintf("CREATE ROLE my_user VALID UNTIL %s", exp_date))
Any single quotes in name will be escaped. Any backslashes (i.e. "\") will be replaced by two backslashes (i.e. "\\") and the C-style escape identifier that PostgreSQL provides ('E') will be prepended to the string.
func ReadOrCreate ¶
func ReadOrCreate(ctx context.Context, md interface{}, col1 string, cols ...string) (created bool, id int64, err error)
ReadOrCreate read or create instance to database, retry to read when met a duplicate key error after the creating
func SetTransactionOpNameToContext ¶
SetTransactionOpNameToContext sets the transaction operation name
func WithTransaction ¶
WithTransaction a decorator which make f run in transaction
func WrapConflictError ¶
WrapConflictError wrap error as ConflictError when it is duplicate key error otherwise return err
func WrapNotFoundError ¶
WrapNotFoundError wrap error as NotFoundError when it is orm.ErrNoRows otherwise return err
Types ¶
type CommittedKey ¶
type CommittedKey struct{}
type Creator ¶
Creator creates ORMer Introducing the "Creator" interface to eliminate the dependency on database