Documentation
¶
Index ¶
- Constants
- func CreateErr(rdb *gorm.DB) (xstatus.DbStatus, error)
- func DeleteErr(rdb *gorm.DB) (xstatus.DbStatus, error)
- func GenerateOrderByExp(source string, dict PropertyDict) string
- func HookDeletedAt(db *gorm.DB, deletedAtTimestamp string)
- func IsMySQL(db *gorm.DB) bool
- func IsMySQLDuplicateEntryError(err error) bool
- func IsPostgreSQL(db *gorm.DB) bool
- func IsPostgreSQLUniqueViolationError(err error) bool
- func IsSQLite(db *gorm.DB) bool
- func IsSQLiteUniqueConstraintError(err error) bool
- func QueryErr(rdb *gorm.DB) (xstatus.DbStatus, error)
- func UpdateErr(rdb *gorm.DB) (xstatus.DbStatus, error)
- type GormTime
- type GormTime2
- type ILogger
- type LoggerLogger
- type LogrusLogger
- type PropertyDict
- type PropertyValue
- type SilenceLogger
Constants ¶
const ( MySQLDuplicateEntryErrno = 1062 // MySQLDuplicateEntryErrno is MySQL's ER_DUP_ENTRY errno. SQLiteUniqueConstraintErrno = 19 | 8<<8 // SQLiteUniqueConstraintErrno is SQLite's CONSTRAINT_UNIQUE extended errno. PostgreSQLUniqueViolationErrno = "23505" // PostgreSQLUniqueViolationErrno is PostgreSQL's unique_violation errno. )
Reference from http://go-database-sql.org/errors.html.
MySQL: https://github.com/VividCortex/mysqlerr/blob/master/mysqlerr.go and https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.htm, SQLite: https://github.com/mattn/go-sqlite3/blob/master/error.go and http://www.sqlite.org/c3ref/c_abort_rollback.html, PostgreSQL: https://github.com/lib/pq/blob/master/error.go and https://www.postgresql.org/docs/10/errcodes-appendix.html.
const (
// DefaultDeletedAtTimestamp represents the default value of GormTime.DeletedAt.
DefaultDeletedAtTimestamp = "1970-01-01 00:00:01"
)
Variables ¶
This section is empty.
Functions ¶
func CreateErr ¶
CreateErr checks gorm.DB create result, will only return xstatus.DbExisted, xstatus.DbFailed and xstatus.DbSuccess.
func DeleteErr ¶
DeleteErr checks gorm.DB delete result, will only return xstatus.DbFailed, xstatus.DbNotFound and xstatus.DbSuccess.
func GenerateOrderByExp ¶
func GenerateOrderByExp(source string, dict PropertyDict) string
GenerateOrderByExp returns a generated orderBy expresion by given source dto order string (split by ",", such as "name desc, age asc") and PropertyDict. The generated expression is in mysql-sql and neo4j-cypher style, that is "xx ASC", "xx DESC".
func HookDeletedAt ¶
HookDeletedAt hooks gorm.DB to replace the soft-delete callback (including query, row_query, update, delete) using the new deletedAt timestamp.
func IsMySQLDuplicateEntryError ¶
IsMySQLDuplicateEntryError checks if err is MySQL's ER_DUP_ENTRY error.
func IsPostgreSQL ¶
IsPostgreSQL checks if the dialect of given gorm.DB is "postgres".
func IsPostgreSQLUniqueViolationError ¶
IsPostgreSQLUniqueViolationError checks if err is PostgreSQL's unique_violation error.
func IsSQLiteUniqueConstraintError ¶
IsSQLiteUniqueConstraintError checks if err is SQLite's ErrConstraintUnique error.
Types ¶
type GormTime ¶
type GormTime struct { CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index" gorm:"default:'1970-01-01 00:00:01'"` }
GormTime represents a structure of CreatedAt, UpdatedAt, DeletedAt (defaults to "1970-01-01 00:00:01"), is a replacement of gorm.Model.
type GormTime2 ¶
GormTime2 represents a structure of CreatedAt, UpdatedAt, which allow you to customize the DeletedAt field, is a replacement of gorm.Model.
type ILogger ¶
type ILogger interface {
Print(v ...interface{})
}
ILogger represents gorm's internal logger interface.
type LoggerLogger ¶
type LoggerLogger struct {
// contains filtered or unexported fields
}
LoggerLogger represents a gorm's logger, used to log "SQL" and "INFO" message to logrus.StdLogger.
func NewLoggerLogger ¶
func NewLoggerLogger(logger logrus.StdLogger) *LoggerLogger
NewLoggerLogger creates a new LoggerLogger using given logrus.StdLogger. Example:
db, err := gorm.Open("mysql", dsl) db.LogMode(true) // must be true l := log.New(os.Stderr, "", log.LstdFlags) db.SetLogger(xgorm.NewLoggerLogger(l))
func (*LoggerLogger) Print ¶
func (g *LoggerLogger) Print(v ...interface{})
Print logs to logrus.StdLogger, see gorm.LogFormatter for details.
type LogrusLogger ¶
type LogrusLogger struct {
// contains filtered or unexported fields
}
LogrusLogger represents a gorm's logger, used to log "SQL" and "INFO" message to logrus.Logger.
func NewLogrusLogger ¶
func NewLogrusLogger(logger *logrus.Logger) *LogrusLogger
NewLogrusLogger creates a new LogrusLogger using given logrus.Logger. Example:
db, err := gorm.Open("mysql", dsl) db.LogMode(true) // must be true l := logrus.New() l.SetFormatter(&logrus.TextFormatter{}) db.SetLogger(xgorm.NewLogrusLogger(l))
func (*LogrusLogger) Print ¶
func (g *LogrusLogger) Print(v ...interface{})
Print logs to logrus.Logger, see gorm.LogFormatter for details.
type PropertyDict ¶
type PropertyDict = orderby.PropertyDict
PropertyDict represents a DTO-PO PropertyValue dictionary, used in GenerateOrderByExp.
type PropertyValue ¶
type PropertyValue = orderby.PropertyValue
PropertyValue represents a PO entity's property mapping rule.
func NewPropertyValue ¶
func NewPropertyValue(reverse bool, destinations ...string) *PropertyValue
NewPropertyValue creates a PropertyValue by given reverse and destinations.
type SilenceLogger ¶
type SilenceLogger struct{}
SilenceLogger represents a gorm's logger, used to hide "SQL" and "INFO" logs. Note that `gorm.DB.LogMode(false)` will only hide "SQL" message.
func NewSilenceLogger ¶
func NewSilenceLogger() *SilenceLogger
NewSilenceLogger creates a new SilenceLogger. Example:
db, err := gorm.Open("mysql", dsl) db.LogMode(true) // both true and false are ok db.SetLogger(xgorm.NewSilenceLogger())
func (*SilenceLogger) Print ¶
func (g *SilenceLogger) Print(...interface{})
Print does nothing for log.