statping: github.com/hunterlong/statping/database Index | Files

package database

import "github.com/hunterlong/statping/database"

Index

Package Files

database.go grouping.go interface.go routines.go time.go

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))
        }
    }
)

func AmountGreaterThan1000 Uses

func AmountGreaterThan1000(db *gorm.DB) *gorm.DB

func Available Uses

func Available(db Database) bool

func Close Uses

func Close(db Database) error

func Maintenance Uses

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

type By Uses

type By string

func (By) String Uses

func (b By) String() string

type Database Uses

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
    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
}

Database is an interface which DB implements

func Begin Uses

func Begin(db Database, model interface{}) Database

func LogMode Uses

func LogMode(db Database, b bool) Database

func OpenTester Uses

func OpenTester() (Database, error)

func Openw Uses

func Openw(dialect string, args ...interface{}) (db Database, err error)

Openw is a drop-in replacement for Open()

func Wrap Uses

func Wrap(db *gorm.DB) Database

Wrap wraps gorm.DB in an interface

type Db Uses

type Db struct {
    Database *gorm.DB
    Type     string
}

func (*Db) AddError Uses

func (it *Db) AddError(err error) error

func (*Db) AddForeignKey Uses

func (it *Db) AddForeignKey(field string, dest string, onDelete string, onUpdate string) Database

func (*Db) AddIndex Uses

func (it *Db) AddIndex(indexName string, columns ...string) Database

func (*Db) AddUniqueIndex Uses

func (it *Db) AddUniqueIndex(indexName string, columns ...string) Database

func (*Db) Assign Uses

func (it *Db) Assign(attrs ...interface{}) Database

func (*Db) Association Uses

func (it *Db) Association(column string) *gorm.Association

func (*Db) Attrs Uses

func (it *Db) Attrs(attrs ...interface{}) Database

func (*Db) AutoMigrate Uses

func (it *Db) AutoMigrate(values ...interface{}) Database

func (*Db) Begin Uses

func (it *Db) Begin() Database

func (*Db) Between Uses

func (it *Db) Between(t1 time.Time, t2 time.Time) Database

func (*Db) Callback Uses

func (it *Db) Callback() *gorm.Callback

func (*Db) Close Uses

func (it *Db) Close() error

func (*Db) Commit Uses

func (it *Db) Commit() Database

func (*Db) CommonDB Uses

func (it *Db) CommonDB() gorm.SQLCommon

func (*Db) Count Uses

func (it *Db) Count(value interface{}) Database

func (*Db) Create Uses

func (it *Db) Create(value interface{}) Database

func (*Db) CreateTable Uses

func (it *Db) CreateTable(values ...interface{}) Database

func (*Db) DB Uses

func (it *Db) DB() *sql.DB

func (*Db) DbType Uses

func (it *Db) DbType() string

func (*Db) Debug Uses

func (it *Db) Debug() Database

func (*Db) Delete Uses

func (it *Db) Delete(value interface{}, where ...interface{}) Database

func (*Db) DropColumn Uses

func (it *Db) DropColumn(column string) Database

func (*Db) DropTable Uses

func (it *Db) DropTable(values ...interface{}) Database

func (*Db) DropTableIfExists Uses

func (it *Db) DropTableIfExists(values ...interface{}) Database

func (*Db) Error Uses

func (it *Db) Error() error

func (*Db) Exec Uses

func (it *Db) Exec(sql string, values ...interface{}) Database

func (*Db) Find Uses

func (it *Db) Find(out interface{}, where ...interface{}) Database

func (*Db) First Uses

func (it *Db) First(out interface{}, where ...interface{}) Database

func (*Db) FirstOrCreate Uses

func (it *Db) FirstOrCreate(out interface{}, where ...interface{}) Database

func (*Db) FirstOrInit Uses

func (it *Db) FirstOrInit(out interface{}, where ...interface{}) Database

func (*Db) FormatTime Uses

func (it *Db) FormatTime(t time.Time) string

func (*Db) Get Uses

func (it *Db) Get(name string) (interface{}, bool)

func (*Db) GetErrors Uses

func (it *Db) GetErrors() (errors []error)

func (*Db) Group Uses

func (it *Db) Group(query string) Database

func (*Db) HasTable Uses

func (it *Db) HasTable(value interface{}) bool

func (*Db) Having Uses

func (it *Db) Having(query string, values ...interface{}) Database

func (*Db) InstantSet Uses

func (it *Db) InstantSet(name string, value interface{}) Database

func (*Db) Joins Uses

func (it *Db) Joins(query string, args ...interface{}) Database

func (*Db) Last Uses

func (it *Db) Last(out interface{}, where ...interface{}) Database

func (*Db) Limit Uses

func (it *Db) Limit(value int) Database

func (*Db) LogMode Uses

func (it *Db) LogMode(enable bool) Database

func (*Db) Model Uses

func (it *Db) Model(value interface{}) Database

func (*Db) ModifyColumn Uses

func (it *Db) ModifyColumn(column string, typ string) Database

func (*Db) MultipleSelects Uses

func (it *Db) MultipleSelects(args ...string) Database

func (*Db) New Uses

func (it *Db) New() Database

func (*Db) NewRecord Uses

func (it *Db) NewRecord(value interface{}) bool

func (*Db) NewScope Uses

func (it *Db) NewScope(value interface{}) *gorm.Scope

func (*Db) Not Uses

func (it *Db) Not(query interface{}, args ...interface{}) Database

func (*Db) Offset Uses

func (it *Db) Offset(value int) Database

func (*Db) Omit Uses

func (it *Db) Omit(columns ...string) Database

func (*Db) Or Uses

func (it *Db) Or(query interface{}, args ...interface{}) Database

func (*Db) Order Uses

func (it *Db) Order(value string, reorder ...bool) Database

func (*Db) ParseTime Uses

func (it *Db) ParseTime(t string) (time.Time, error)

func (*Db) Pluck Uses

func (it *Db) Pluck(column string, value interface{}) Database

func (*Db) Preload Uses

func (it *Db) Preload(column string, conditions ...interface{}) Database

func (*Db) Raw Uses

func (it *Db) Raw(sql string, values ...interface{}) Database

func (*Db) RecordNotFound Uses

func (it *Db) RecordNotFound() bool

func (*Db) Related Uses

func (it *Db) Related(value interface{}, foreignKeys ...string) Database

func (*Db) RemoveIndex Uses

func (it *Db) RemoveIndex(indexName string) Database

func (*Db) Rollback Uses

func (it *Db) Rollback() Database

func (*Db) Row Uses

func (it *Db) Row() *sql.Row

func (*Db) Rows Uses

func (it *Db) Rows() (*sql.Rows, error)

func (*Db) RowsAffected Uses

func (it *Db) RowsAffected() int64

func (*Db) Save Uses

func (it *Db) Save(value interface{}) Database

func (*Db) Scan Uses

func (it *Db) Scan(dest interface{}) Database

func (*Db) ScanRows Uses

func (it *Db) ScanRows(rows *sql.Rows, result interface{}) error

func (*Db) Scopes Uses

func (it *Db) Scopes(funcs ...func(*gorm.DB) *gorm.DB) Database

func (*Db) Select Uses

func (it *Db) Select(query interface{}, args ...interface{}) Database

func (*Db) SelectByTime Uses

func (it *Db) SelectByTime(increment time.Duration) string

func (*Db) Set Uses

func (it *Db) Set(name string, value interface{}) Database

func (*Db) SetJoinTableHandler Uses

func (it *Db) SetJoinTableHandler(source interface{}, column string, handler gorm.JoinTableHandlerInterface)

func (*Db) SetLogger Uses

func (it *Db) SetLogger(log gorm.Logger)

func (*Db) Since Uses

func (it *Db) Since(ago time.Time) Database

func (*Db) SingularTable Uses

func (it *Db) SingularTable(enable bool)

func (*Db) Table Uses

func (it *Db) Table(name string) Database

func (*Db) Unscoped Uses

func (it *Db) Unscoped() Database

func (*Db) Update Uses

func (it *Db) Update(attrs ...interface{}) Database

func (*Db) UpdateColumn Uses

func (it *Db) UpdateColumn(attrs ...interface{}) Database

func (*Db) UpdateColumns Uses

func (it *Db) UpdateColumns(values interface{}) Database

func (*Db) Updates Uses

func (it *Db) Updates(values interface{}, ignoreProtectedAttrs ...bool) Database

func (*Db) Where Uses

func (it *Db) Where(query interface{}, args ...interface{}) Database

type DbObject Uses

type DbObject interface {
    Create() error
    Update() error
    Delete() error
}

type GroupBy Uses

type GroupBy struct {
    // contains filtered or unexported fields
}

type GroupByer Uses

type GroupByer interface {
    ToTimeValue() (*TimeVar, error)
}

type GroupQuery Uses

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 Uses

func ParseQueries(r *http.Request, o isObject) (*GroupQuery, error)

func (GroupQuery) Database Uses

func (b GroupQuery) Database() Database

func (GroupQuery) Find Uses

func (b GroupQuery) Find(data interface{}) error

func (*GroupQuery) GraphData Uses

func (g *GroupQuery) GraphData(by By) ([]*TimeValue, error)

GraphData will return all hits or failures

func (*GroupQuery) ToTimeValue Uses

func (g *GroupQuery) ToTimeValue() (*TimeVar, error)

type Sampler Uses

type Sampler interface {
    Sample() DbObject
}

type TimeGroup Uses

type TimeGroup interface {
}

type TimeValue Uses

type TimeValue struct {
    Timeframe string `json:"timeframe"`
    Amount    int64  `json:"amount"`
}

type TimeVar Uses

type TimeVar struct {
    // contains filtered or unexported fields
}

func (*TimeVar) FillMissing Uses

func (t *TimeVar) FillMissing(current, end time.Time) ([]*TimeValue, error)

func (*TimeVar) ToValues Uses

func (t *TimeVar) ToValues() ([]*TimeValue, error)

Package database imports 14 packages (graph). Updated 2020-04-08. Refresh now. Tools for package owners.