Documentation ¶
Index ¶
- Constants
- Variables
- func Cell2Int64(val xorm.Cell) int64
- func ConvertUtf8ToUtf8mb4() error
- func CountBadSequences() (int64, error)
- func CountByBean(ctx context.Context, bean interface{}) (int64, error)
- func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error)
- func DeleteAllRecords(tableName string) error
- func DeleteBeans(ctx context.Context, beans ...interface{}) (err error)
- func DeleteByBean(ctx context.Context, bean interface{}) (int64, error)
- func DeleteOrphanedObjects(subject, refobject, joinCond string) error
- func DeleteResouceIndex(ctx context.Context, tableName string, groupID int64) error
- func DumpDatabase(filePath, dbType string) error
- func DumpTables(tables []*schemas.Table, w io.Writer, tp ...schemas.DBType) error
- func ErrCancelledf(format string, args ...interface{}) error
- func EstimateCount(ctx context.Context, bean interface{}) (int64, error)
- func Exec(ctx context.Context, sqlAndArgs ...interface{}) (sql.Result, error)
- func FixBadSequences() error
- func GetByBean(ctx context.Context, bean interface{}) (bool, error)
- func GetMaxID(beanOrTableName interface{}) (maxID int64, err error)
- func GetNextResourceIndex(tableName string, groupID int64) (int64, error)
- func GetPaginatedSession(p Paginator) *xorm.Session
- func InitEngine(ctx context.Context) error
- func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine) error) (err error)
- func Insert(ctx context.Context, beans ...interface{}) error
- func IsErrCancelled(err error) bool
- func IsErrNameCharsNotAllowed(err error) bool
- func IsErrNamePatternNotAllowed(err error) bool
- func IsErrNameReserved(err error) bool
- func IsErrNotExist(err error) bool
- func IsErrSSHDisabled(err error) bool
- func IsTableNotEmpty(tableName string) (bool, error)
- func IsUsableName(names, patterns []string, name string) error
- func Iterate(ctx context.Context, tableBean interface{}, cond builder.Cond, ...) error
- func MaxBatchInsertSize(bean interface{}) int
- func NamesToBean(names ...string) ([]interface{}, error)
- func NewXORMLogger(showSQL bool) xormlog.Logger
- func RegisterModel(bean interface{}, initFunc ...func() error)
- func SetDefaultEngine(ctx context.Context, eng *xorm.Engine)
- func SetSessionPagination(sess Engine, p Paginator) *xorm.Session
- func SyncAllTables() error
- func TableInfo(v interface{}) (*schemas.Table, error)
- func TableName(bean interface{}) string
- func TxContext() (*Context, Committer, error)
- func UnsetDefaultEngine()
- func UpsertResourceIndex(ctx context.Context, tableName string, groupID int64) (err error)
- func WithContext(f func(ctx *Context) error) error
- func WithTx(f func(ctx context.Context) error, stdCtx ...context.Context) error
- type AbsoluteListOptions
- type Committer
- type Context
- type Engine
- type Engined
- type ErrCancelled
- type ErrNameCharsNotAllowed
- type ErrNamePatternNotAllowed
- type ErrNameReserved
- type ErrNotExist
- type ErrSSHDisabled
- type ListOptions
- type Paginator
- type ResourceIndex
- type SearchOrderBy
- type XORMLogBridge
- func (l *XORMLogBridge) Debug(v ...interface{})
- func (l *XORMLogBridge) Debugf(format string, v ...interface{})
- func (l *XORMLogBridge) Error(v ...interface{})
- func (l *XORMLogBridge) Errorf(format string, v ...interface{})
- func (l *XORMLogBridge) Info(v ...interface{})
- func (l *XORMLogBridge) Infof(format string, v ...interface{})
- func (l *XORMLogBridge) IsShowSQL() bool
- func (l *XORMLogBridge) Level() xormlog.LogLevel
- func (l *XORMLogBridge) Log(skip int, level log.Level, format string, v ...interface{}) error
- func (l *XORMLogBridge) SetLevel(lvl xormlog.LogLevel)
- func (l *XORMLogBridge) ShowSQL(show ...bool)
- func (l *XORMLogBridge) Warn(v ...interface{})
- func (l *XORMLogBridge) Warnf(format string, v ...interface{})
Constants ¶
const (
// DefaultMaxInSize represents default variables number on IN () in SQL
DefaultMaxInSize = 50
)
const (
// MaxDupIndexAttempts max retry times to create index
MaxDupIndexAttempts = 3
)
Variables ¶
var ( // ErrResouceOutdated represents an error when request resource outdated ErrResouceOutdated = errors.New("resource outdated") // ErrGetResourceIndexFailed represents an error when resource index retries 3 times ErrGetResourceIndexFailed = errors.New("get resource index failed") )
var ( // ErrNameEmpty name is empty error ErrNameEmpty = errors.New("Name is empty") // AlphaDashDotPattern characters prohibited in a user name (anything except A-Za-z0-9_.-) AlphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`) )
var DefaultContext context.Context
DefaultContext is the default context to run xorm queries in will be overwritten by Init with HammerContext
var EnginedContextKey = &contextKey{"engined"}
EnginedContextKey is a context key. It is used with context.Value() to get the current Engined for the context
var ( // HasEngine specifies if we have a xorm.Engine HasEngine bool )
Functions ¶
func Cell2Int64 ¶
Cell2Int64 converts a xorm.Cell type to int64, and handles possible irregular cases.
func ConvertUtf8ToUtf8mb4 ¶
func ConvertUtf8ToUtf8mb4() error
ConvertUtf8ToUtf8mb4 converts database and tables from utf8 to utf8mb4 if it's mysql and set ROW_FORMAT=dynamic
func CountBadSequences ¶
CountBadSequences looks for broken sequences from recreate-table mistakes
func CountByBean ¶
CountByBean counts the number of database records according non-empty fields of the bean as conditions.
func CountOrphanedObjects ¶ added in v1.17.0
CountOrphanedObjects count subjects with have no existing refobject anymore
func DeleteAllRecords ¶
DeleteAllRecords will delete all the records of this table
func DeleteBeans ¶ added in v1.17.0
DeleteBeans deletes all given beans, beans should contain delete conditions.
func DeleteByBean ¶
DeleteByBean deletes all records according non-empty fields of the bean as conditions.
func DeleteOrphanedObjects ¶ added in v1.17.0
DeleteOrphanedObjects delete subjects with have no existing refobject anymore
func DeleteResouceIndex ¶
DeleteResouceIndex delete resource index
func DumpDatabase ¶
DumpDatabase dumps all data from database according the special database SQL syntax to file system.
func DumpTables ¶
DumpTables dump tables information
func ErrCancelledf ¶
ErrCancelledf returns an ErrCancelled for the provided format and args
func EstimateCount ¶ added in v1.17.0
EstimateCount returns an estimate of total number of rows in table
func FixBadSequences ¶
func FixBadSequences() error
FixBadSequences fixes for broken sequences from recreate-table mistakes
func GetByBean ¶
GetByBean filled empty fields of the bean according non-empty fields to query in database.
func GetNextResourceIndex ¶
GetNextResourceIndex retried 3 times to generate a resource index
func GetPaginatedSession ¶
GetPaginatedSession creates a paginated database session
func InitEngine ¶
InitEngine initializes the xorm.Engine and sets it as db.DefaultContext
func InitEngineWithMigration ¶
InitEngineWithMigration initializes a new xorm.Engine and sets it as the db.DefaultContext This function must never call .Sync2() if the provided migration function fails. When called from the "doctor" command, the migration function is a version check that prevents the doctor from fixing anything in the database if the migration level is different from the expected value.
func IsErrCancelled ¶
IsErrCancelled checks if an error is a ErrCancelled.
func IsErrNameCharsNotAllowed ¶
IsErrNameCharsNotAllowed checks if an error is an ErrNameCharsNotAllowed.
func IsErrNamePatternNotAllowed ¶
IsErrNamePatternNotAllowed checks if an error is an ErrNamePatternNotAllowed.
func IsErrNameReserved ¶
IsErrNameReserved checks if an error is a ErrNameReserved.
func IsErrNotExist ¶ added in v1.17.0
IsErrNotExist checks if an error is an ErrNotExist
func IsErrSSHDisabled ¶
IsErrSSHDisabled checks if an error is a ErrSSHDisabled.
func IsTableNotEmpty ¶
IsTableNotEmpty returns true if table has at least one record
func IsUsableName ¶
IsUsableName checks if name is reserved or pattern of name is not allowed based on given reserved names and patterns. Names are exact match, patterns can be prefix or suffix match with placeholder '*'.
func Iterate ¶
func Iterate(ctx context.Context, tableBean interface{}, cond builder.Cond, fun func(idx int, bean interface{}) error) error
Iterate iterates the databases and doing something
func MaxBatchInsertSize ¶
func MaxBatchInsertSize(bean interface{}) int
MaxBatchInsertSize returns the table's max batch insert size
func NamesToBean ¶
NamesToBean return a list of beans or an error
func NewXORMLogger ¶
NewXORMLogger inits a log bridge for xorm
func RegisterModel ¶
func RegisterModel(bean interface{}, initFunc ...func() error)
RegisterModel registers model, if initfunc provided, it will be invoked after data model sync
func SetDefaultEngine ¶
SetDefaultEngine sets the default engine for db
func SetSessionPagination ¶
SetSessionPagination sets pagination for a database session
func SyncAllTables ¶
func SyncAllTables() error
SyncAllTables sync the schemas of all tables, is required by unit test code
func TableName ¶
func TableName(bean interface{}) string
TableName returns the table name according a bean object
func UnsetDefaultEngine ¶
func UnsetDefaultEngine()
UnsetDefaultEngine closes and unsets the default engine We hope the SetDefaultEngine and UnsetDefaultEngine can be paired, but it's impossible now, there are many calls to InitEngine -> SetDefaultEngine directly to overwrite the `x` and DefaultContext without close Global database engine related functions are all racy and there is no graceful close right now.
func UpsertResourceIndex ¶
UpsertResourceIndex the function will not return until it acquires the lock or receives an error.
func WithContext ¶
WithContext represents executing database operations
Types ¶
type AbsoluteListOptions ¶
type AbsoluteListOptions struct {
// contains filtered or unexported fields
}
AbsoluteListOptions absolute options to paginate results
func NewAbsoluteListOptions ¶
func NewAbsoluteListOptions(skip, take int) *AbsoluteListOptions
NewAbsoluteListOptions creates a list option with applied limits
func (*AbsoluteListOptions) GetSkipTake ¶
func (opts *AbsoluteListOptions) GetSkipTake() (skip, take int)
GetSkipTake returns the skip and take values
func (*AbsoluteListOptions) GetStartEnd ¶
func (opts *AbsoluteListOptions) GetStartEnd() (start, end int)
GetStartEnd returns the start and end values
type Context ¶
Context represents a db context
func WithEngine ¶
WithEngine returns a Context from a context.Context and Engine
type Engine ¶
type Engine interface { Table(tableNameOrBean interface{}) *xorm.Session Count(...interface{}) (int64, error) Decr(column string, arg ...interface{}) *xorm.Session Delete(...interface{}) (int64, error) Exec(...interface{}) (sql.Result, error) Find(interface{}, ...interface{}) error Get(beans ...interface{}) (bool, error) ID(interface{}) *xorm.Session In(string, ...interface{}) *xorm.Session Incr(column string, arg ...interface{}) *xorm.Session Insert(...interface{}) (int64, error) Iterate(interface{}, xorm.IterFunc) error Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *xorm.Session SQL(interface{}, ...interface{}) *xorm.Session Where(interface{}, ...interface{}) *xorm.Session Asc(colNames ...string) *xorm.Session Desc(colNames ...string) *xorm.Session Limit(limit int, start ...int) *xorm.Session NoAutoTime() *xorm.Session SumInt(bean interface{}, columnName string) (res int64, err error) Sync2(...interface{}) error Select(string) *xorm.Session NotIn(string, ...interface{}) *xorm.Session OrderBy(interface{}, ...interface{}) *xorm.Session Exist(...interface{}) (bool, error) Distinct(...string) *xorm.Session Query(...interface{}) ([]map[string][]byte, error) Cols(...string) *xorm.Session Context(ctx context.Context) *xorm.Session Ping() error }
Engine represents a xorm engine or session.
func GetEngine ¶
GetEngine will get a db Engine from this context or return an Engine restricted to this context
func SetEnginePagination ¶
SetEnginePagination sets pagination for a database engine
type ErrCancelled ¶
type ErrCancelled struct {
Message string
}
ErrCancelled represents an error due to context cancellation
func (ErrCancelled) Error ¶
func (err ErrCancelled) Error() string
type ErrNameCharsNotAllowed ¶
type ErrNameCharsNotAllowed struct {
Name string
}
ErrNameCharsNotAllowed represents a "character not allowed in name" error.
func (ErrNameCharsNotAllowed) Error ¶
func (err ErrNameCharsNotAllowed) Error() string
type ErrNamePatternNotAllowed ¶
type ErrNamePatternNotAllowed struct {
Pattern string
}
ErrNamePatternNotAllowed represents a "pattern not allowed" error.
func (ErrNamePatternNotAllowed) Error ¶
func (err ErrNamePatternNotAllowed) Error() string
type ErrNameReserved ¶
type ErrNameReserved struct {
Name string
}
ErrNameReserved represents a "reserved name" error.
func (ErrNameReserved) Error ¶
func (err ErrNameReserved) Error() string
type ErrNotExist ¶ added in v1.17.0
type ErrNotExist struct {
ID int64
}
ErrNotExist represents a non-exist error.
func (ErrNotExist) Error ¶ added in v1.17.0
func (err ErrNotExist) Error() string
type ErrSSHDisabled ¶
type ErrSSHDisabled struct{}
ErrSSHDisabled represents an "SSH disabled" error.
func (ErrSSHDisabled) Error ¶
func (err ErrSSHDisabled) Error() string
type ListOptions ¶
ListOptions options to paginate results
func (*ListOptions) GetSkipTake ¶
func (opts *ListOptions) GetSkipTake() (skip, take int)
GetSkipTake returns the skip and take values
func (*ListOptions) GetStartEnd ¶
func (opts *ListOptions) GetStartEnd() (start, end int)
GetStartEnd returns the start and end of the ListOptions
func (*ListOptions) SetDefaultValues ¶
func (opts *ListOptions) SetDefaultValues()
SetDefaultValues sets default values
type ResourceIndex ¶
ResourceIndex represents a resource index which could be used as issue/release and others We can create different tables i.e. issue_index, release_index and etc.
type SearchOrderBy ¶
type SearchOrderBy string
SearchOrderBy is used to sort the result
const ( SearchOrderByAlphabetically SearchOrderBy = "name ASC" SearchOrderByAlphabeticallyReverse SearchOrderBy = "name DESC" SearchOrderByLeastUpdated SearchOrderBy = "updated_unix ASC" SearchOrderByRecentUpdated SearchOrderBy = "updated_unix DESC" SearchOrderByOldest SearchOrderBy = "created_unix ASC" SearchOrderByNewest SearchOrderBy = "created_unix DESC" SearchOrderBySize SearchOrderBy = "size ASC" SearchOrderBySizeReverse SearchOrderBy = "size DESC" SearchOrderByID SearchOrderBy = "id ASC" SearchOrderByIDReverse SearchOrderBy = "id DESC" SearchOrderByStars SearchOrderBy = "num_stars ASC" SearchOrderByStarsReverse SearchOrderBy = "num_stars DESC" SearchOrderByForks SearchOrderBy = "num_forks ASC" SearchOrderByForksReverse SearchOrderBy = "num_forks DESC" )
Strings for sorting result
func (SearchOrderBy) String ¶
func (s SearchOrderBy) String() string
type XORMLogBridge ¶
type XORMLogBridge struct {
// contains filtered or unexported fields
}
XORMLogBridge a logger bridge from Logger to xorm
func (*XORMLogBridge) Debugf ¶
func (l *XORMLogBridge) Debugf(format string, v ...interface{})
Debugf show debug log
func (*XORMLogBridge) Errorf ¶
func (l *XORMLogBridge) Errorf(format string, v ...interface{})
Errorf show error log
func (*XORMLogBridge) Info ¶
func (l *XORMLogBridge) Info(v ...interface{})
Info show information level log
func (*XORMLogBridge) Infof ¶
func (l *XORMLogBridge) Infof(format string, v ...interface{})
Infof show information level log
func (*XORMLogBridge) Level ¶
func (l *XORMLogBridge) Level() xormlog.LogLevel
Level get logger level
func (*XORMLogBridge) SetLevel ¶
func (l *XORMLogBridge) SetLevel(lvl xormlog.LogLevel)
SetLevel set the logger level
func (*XORMLogBridge) ShowSQL ¶
func (l *XORMLogBridge) ShowSQL(show ...bool)
ShowSQL set if record SQL
func (*XORMLogBridge) Warnf ¶
func (l *XORMLogBridge) Warnf(format string, v ...interface{})
Warnf show warnning log