From 7f73480a35c8c54897c08067dedb4af3184dd79d Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 25 Oct 2013 18:31:10 +0800 Subject: [PATCH] Build basic architecture --- main.go | 67 ++++++++++++++++++++++++++------------------------------- orm.go | 57 ++++++++++++++++++++++++++---------------------- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/main.go b/main.go index f271a233..5e2b770f 100644 --- a/main.go +++ b/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 } diff --git a/orm.go b/orm.go index d03849b6..a9dedfd5 100644 --- a/orm.go +++ b/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 "" }