mirror of https://github.com/go-gorm/gorm.git
Build basic architecture
This commit is contained in:
parent
2d6fa2c96d
commit
7f73480a35
67
main.go
67
main.go
|
@ -8,76 +8,71 @@ type DB struct {
|
|||
|
||||
func Open(driver, source string) (db *DB, err error) {
|
||||
db.Db, err = sql.Open(driver, source)
|
||||
// SetMaxIdleConns pools
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) buildORM() (orm *Orm, err error) {
|
||||
func (s *DB) buildORM() (orm *Orm) {
|
||||
orm.Db = s.Db
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Where(querystring interface{}, args ...interface{}) (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Where(querystring interface{}, args ...interface{}) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Where(querystring, args)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) First() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) First(out interface{}) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.First(out)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Find() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Find(out interface{}) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Find(out)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Limit() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Limit(value interface{}) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Limit(value)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Offset() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Offset(value interface{}) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Offset(value)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Order() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Order(value interface{}) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Order(value)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Or() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Select(querystring string) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Select(querystring)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Not() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Save(value interface{}) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Save(value)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Count() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Delete(value interface{}) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Delete(value)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Select() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Save() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Delete() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
return
|
||||
}
|
||||
|
||||
func (s *DB) Exec() (orm *Orm, err error) {
|
||||
orm, err = s.buildORM()
|
||||
func (s *DB) Exec(sql string) (orm *Orm) {
|
||||
orm = s.buildORM()
|
||||
orm.Exec(sql)
|
||||
return
|
||||
}
|
||||
|
|
57
orm.go
57
orm.go
|
@ -10,56 +10,61 @@ type Orm struct {
|
|||
PrimaryKey string
|
||||
OffsetInt int64
|
||||
LimitInt int64
|
||||
Error bool
|
||||
}
|
||||
|
||||
func (s *Orm) Where(querystring interface{}, args ...interface{}) (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Where(querystring interface{}, args ...interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) First() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) First(out interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Find() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Find(out interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Limit() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Limit(value interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Offset() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Offset(value interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Order() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Order(value interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Or() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Or(querystring interface{}, args ...interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Not() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Not(querystring interface{}, args ...interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Count() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Count() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *Orm) Select() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Select(querystring string) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Save() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Save(value interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Delete() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Delete(value interface{}) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Exec() (*Orm, error) {
|
||||
return s, nil
|
||||
func (s *Orm) Exec(sql string) *Orm {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Orm) Explain() string {
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue