Documentation ¶
Index ¶
- Variables
- func Available(db Database) bool
- func Close(db Database) error
- func Maintenance()
- func Routine()
- type By
- type Database
- type Db
- func (it *Db) AddError(err error) error
- func (it *Db) AddForeignKey(field string, dest string, onDelete string, onUpdate string) Database
- func (it *Db) AddIndex(indexName string, columns ...string) Database
- func (it *Db) AddUniqueIndex(indexName string, columns ...string) Database
- func (it *Db) Assign(attrs ...interface{}) Database
- func (it *Db) Association(column string) *gorm.Association
- func (it *Db) Attrs(attrs ...interface{}) Database
- func (it *Db) AutoMigrate(values ...interface{}) Database
- func (it *Db) Begin() Database
- func (it *Db) Between(t1 time.Time, t2 time.Time) Database
- func (it *Db) Callback() *gorm.Callback
- func (it *Db) ChunkSize() int
- func (it *Db) Close() error
- func (it *Db) Commit() Database
- func (it *Db) CommonDB() gorm.SQLCommon
- func (it *Db) Count(value interface{}) Database
- func (it *Db) Create(value interface{}) Database
- func (it *Db) CreateTable(values ...interface{}) Database
- func (it *Db) DB() *sql.DB
- func (it *Db) DbType() string
- func (it *Db) Debug() Database
- func (it *Db) Delete(value interface{}, where ...interface{}) Database
- func (it *Db) DropColumn(column string) Database
- func (it *Db) DropTable(values ...interface{}) Database
- func (it *Db) DropTableIfExists(values ...interface{}) Database
- func (it *Db) Error() error
- func (it *Db) Exec(sql string, values ...interface{}) Database
- func (it *Db) Find(out interface{}, where ...interface{}) Database
- func (it *Db) First(out interface{}, where ...interface{}) Database
- func (it *Db) FirstOrCreate(out interface{}, where ...interface{}) Database
- func (it *Db) FirstOrInit(out interface{}, where ...interface{}) Database
- func (it *Db) FormatTime(t time.Time) string
- func (it *Db) Get(name string) (interface{}, bool)
- func (it *Db) GetErrors() (errors []error)
- func (it *Db) GormDB() *gorm.DB
- func (it *Db) Group(query string) Database
- func (it *Db) HasTable(value interface{}) bool
- func (it *Db) Having(query string, values ...interface{}) Database
- func (it *Db) InstantSet(name string, value interface{}) Database
- func (it *Db) Joins(query string, args ...interface{}) Database
- func (it *Db) Last(out interface{}, where ...interface{}) Database
- func (it *Db) Limit(value int) Database
- func (it *Db) LogMode(enable bool) Database
- func (it *Db) Loggable() bool
- func (it *Db) Model(value interface{}) Database
- func (it *Db) ModifyColumn(column string, typ string) Database
- func (it *Db) MultipleSelects(args ...string) Database
- func (it *Db) New() Database
- func (it *Db) NewRecord(value interface{}) bool
- func (it *Db) NewScope(value interface{}) *gorm.Scope
- func (it *Db) Not(query interface{}, args ...interface{}) Database
- func (it *Db) Offset(value int) Database
- func (it *Db) Omit(columns ...string) Database
- func (it *Db) Or(query interface{}, args ...interface{}) Database
- func (it *Db) Order(value string, reorder ...bool) Database
- func (it *Db) ParseTime(t string) (time.Time, error)
- func (it *Db) Pluck(column string, value interface{}) Database
- func (it *Db) Preload(column string, conditions ...interface{}) Database
- func (it *Db) Raw(sql string, values ...interface{}) Database
- func (it *Db) RecordNotFound() bool
- func (it *Db) Related(value interface{}, foreignKeys ...string) Database
- func (it *Db) RemoveIndex(indexName string) Database
- func (it *Db) Rollback() Database
- func (it *Db) Row() *sql.Row
- func (it *Db) Rows() (*sql.Rows, error)
- func (it *Db) RowsAffected() int64
- func (it *Db) Save(value interface{}) Database
- func (it *Db) Scan(dest interface{}) Database
- func (it *Db) ScanRows(rows *sql.Rows, result interface{}) error
- func (it *Db) Scopes(funcs ...func(*gorm.DB) *gorm.DB) Database
- func (it *Db) Select(query interface{}, args ...interface{}) Database
- func (it *Db) SelectByTime(increment time.Duration) string
- func (it *Db) Set(name string, value interface{}) Database
- func (it *Db) SetJoinTableHandler(source interface{}, column string, handler gorm.JoinTableHandlerInterface)
- func (it *Db) SetLogger(log gorm.Logger)
- func (it *Db) Since(ago time.Time) Database
- func (it *Db) SingularTable(enable bool)
- func (it *Db) Status() int
- func (it *Db) Table(name string) Database
- func (it *Db) Unscoped() Database
- func (it *Db) Update(attrs ...interface{}) Database
- func (it *Db) UpdateColumn(attrs ...interface{}) Database
- func (it *Db) UpdateColumns(values interface{}) Database
- func (it *Db) Updates(values interface{}, ignoreProtectedAttrs ...bool) Database
- func (it *Db) Where(query interface{}, args ...interface{}) Database
- type DbObject
- type GroupBy
- type GroupByer
- type GroupQuery
- type Sampler
- type TimeGroup
- type TimeValue
- type TimeVar
Constants ¶
This section is empty.
Variables ¶
var ( ByCount = By("COUNT(id) as amount") ByAverage = func(column string, multiplier int) By { switch database.DbType() { case "mysql": return By(fmt.Sprintf("CAST(AVG(%s) as UNSIGNED INT) as amount", column)) case "postgres": return By(fmt.Sprintf("cast(AVG(%s) as int) as amount", column)) default: return By(fmt.Sprintf("cast(AVG(%s) as int) as amount", column)) } } )
Functions ¶
func Maintenance ¶
func Maintenance()
Maintenance will automatically delete old records from 'failures' and 'hits' this function is currently set to delete records 7+ days old every 60 minutes env: REMOVE_AFTER - golang duration parsed time for deleting records older than REMOVE_AFTER duration from now env: CLEANUP_INTERVAL - golang duration parsed time for checking old records routine
Types ¶
type Database ¶
type Database interface { Close() error DB() *sql.DB New() Database NewScope(value interface{}) *gorm.Scope CommonDB() gorm.SQLCommon Callback() *gorm.Callback SetLogger(l gorm.Logger) LogMode(enable bool) Database SingularTable(enable bool) Where(query interface{}, args ...interface{}) Database Or(query interface{}, args ...interface{}) Database Not(query interface{}, args ...interface{}) Database Limit(value int) Database Offset(value int) Database Order(value string, reorder ...bool) Database Select(query interface{}, args ...interface{}) Database Omit(columns ...string) Database Group(query string) Database Having(query string, values ...interface{}) Database Joins(query string, args ...interface{}) Database Scopes(funcs ...func(*gorm.DB) *gorm.DB) Database Unscoped() Database Attrs(attrs ...interface{}) Database Assign(attrs ...interface{}) Database First(out interface{}, where ...interface{}) Database Last(out interface{}, where ...interface{}) Database Find(out interface{}, where ...interface{}) Database Scan(dest interface{}) Database Row() *sql.Row Rows() (*sql.Rows, error) ScanRows(rows *sql.Rows, result interface{}) error Pluck(column string, value interface{}) Database Count(value interface{}) Database Related(value interface{}, foreignKeys ...string) Database FirstOrInit(out interface{}, where ...interface{}) Database FirstOrCreate(out interface{}, where ...interface{}) Database Update(attrs ...interface{}) Database Updates(values interface{}, ignoreProtectedAttrs ...bool) Database UpdateColumn(attrs ...interface{}) Database UpdateColumns(values interface{}) Database Save(value interface{}) Database Create(value interface{}) Database Delete(value interface{}, where ...interface{}) Database Raw(sql string, values ...interface{}) Database Exec(sql string, values ...interface{}) Database Model(value interface{}) Database Table(name string) Database Debug() Database Begin() Database Commit() Database Rollback() Database NewRecord(value interface{}) bool RecordNotFound() bool CreateTable(values ...interface{}) Database DropTable(values ...interface{}) Database DropTableIfExists(values ...interface{}) Database HasTable(value interface{}) bool AutoMigrate(values ...interface{}) Database ModifyColumn(column string, typ string) Database DropColumn(column string) Database AddIndex(indexName string, column ...string) Database AddUniqueIndex(indexName string, column ...string) Database RemoveIndex(indexName string) Database AddForeignKey(field string, dest string, onDelete string, onUpdate string) Database Association(column string) *gorm.Association Preload(column string, conditions ...interface{}) Database Set(name string, value interface{}) Database InstantSet(name string, value interface{}) Database Get(name string) (value interface{}, ok bool) SetJoinTableHandler(source interface{}, column string, handler gorm.JoinTableHandlerInterface) AddError(err error) error GetErrors() (errors []error) // extra Error() error Status() int RowsAffected() int64 Since(time.Time) Database Between(time.Time, time.Time) Database SelectByTime(time.Duration) string MultipleSelects(args ...string) Database FormatTime(t time.Time) string ParseTime(t string) (time.Time, error) DbType() string GormDB() *gorm.DB ChunkSize() int }
Database is an interface which DB implements
func OpenTester ¶
type Db ¶
func (*Db) AddForeignKey ¶
func (*Db) AddUniqueIndex ¶
func (*Db) Association ¶
func (it *Db) Association(column string) *gorm.Association
func (*Db) AutoMigrate ¶
func (*Db) CreateTable ¶
func (*Db) DropColumn ¶
func (*Db) DropTableIfExists ¶
func (*Db) FirstOrCreate ¶
func (*Db) FirstOrInit ¶
func (*Db) FormatTime ¶
FormatTime returns the timestamp in the same format as the DATETIME column in database
func (*Db) InstantSet ¶
func (*Db) MultipleSelects ¶
func (*Db) RecordNotFound ¶
func (*Db) RemoveIndex ¶
func (*Db) RowsAffected ¶
func (*Db) SelectByTime ¶
SelectByTime returns an SQL query that will group "created_at" column by x seconds and returns as "timeframe"
func (*Db) SetJoinTableHandler ¶
func (it *Db) SetJoinTableHandler(source interface{}, column string, handler gorm.JoinTableHandlerInterface)
func (*Db) SingularTable ¶
func (*Db) UpdateColumn ¶
func (*Db) UpdateColumns ¶
type GroupQuery ¶
type GroupQuery struct { Start time.Time End time.Time Group time.Duration Order string Limit int Offset int FillEmpty bool // contains filtered or unexported fields }
func ParseQueries ¶
func ParseQueries(r *http.Request, o isObject) (*GroupQuery, error)
func ParseQueriesForTable ¶
func ParseQueriesForTable(r *http.Request, o isObject, whereTable string) (*GroupQuery, error)
func ParseRequest ¶
func ParseRequest(r *http.Request) (*GroupQuery, error)
func (GroupQuery) Database ¶
func (b GroupQuery) Database() Database
func (GroupQuery) Find ¶
func (b GroupQuery) Find(data interface{}) error
func (*GroupQuery) GraphData ¶
func (b *GroupQuery) GraphData(by By) ([]*TimeValue, error)
GraphData will return all hits or failures
func (*GroupQuery) ToTimeValue ¶
func (b *GroupQuery) ToTimeValue() (*TimeVar, error)
ToTimeValue will format the SQL rows into a JSON format for the API. [{"timestamp": "2006-01-02T15:04:05Z", "amount": 468293}] TODO redo this entire function, use better SQL query to group by time