Skip to content

Commit

Permalink
Move all chain method to main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Nov 16, 2013
1 parent 7912631 commit 3cfa19b
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 100 deletions.
30 changes: 0 additions & 30 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ func (s *Chain) Model(model interface{}) *Chain {
return s
}

func (s *Chain) Where(querystring interface{}, args ...interface{}) *Chain {
s.whereClause = append(s.whereClause, map[string]interface{}{"query": querystring, "args": args})
return s
}

func (s *Chain) Not(querystring interface{}, args ...interface{}) *Chain {
s.notClause = append(s.notClause, map[string]interface{}{"query": querystring, "args": args})
return s
}

func (s *Chain) Limit(value interface{}) *Chain {
if str, err := getInterfaceAsString(value); err == nil {
s.limitStr = str
Expand Down Expand Up @@ -151,16 +141,6 @@ func (s *Chain) Exec(sql string) *Chain {
return s
}

func (s *Chain) First(out interface{}, where ...interface{}) *Chain {
s.do(out).where(where...).first()
return s
}

func (s *Chain) Last(out interface{}, where ...interface{}) *Chain {
s.do(out).where(where...).last()
return s
}

func (s *Chain) Attrs(attrs ...interface{}) *Chain {
s.initAttrs = append(s.initAttrs, toSearchableMap(attrs...))
return s
Expand Down Expand Up @@ -196,21 +176,11 @@ func (s *Chain) FirstOrCreate(out interface{}, where ...interface{}) *Chain {
return s
}

func (s *Chain) Find(out interface{}, where ...interface{}) *Chain {
s.do(out).where(where...).query()
return s
}

func (s *Chain) Pluck(column string, value interface{}) (orm *Chain) {
s.do(s.value).pluck(column, value)
return s
}

func (s *Chain) Or(querystring interface{}, args ...interface{}) *Chain {
s.orClause = append(s.orClause, map[string]interface{}{"query": querystring, "args": args})
return s
}

func (s *Chain) Unscoped() *Chain {
s.unscoped = true
return s
Expand Down
10 changes: 9 additions & 1 deletion do.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type Do struct {
chain *Chain
db sqlCommon
db *DB
guessedTableName string
specifiedTableName string
startedTransaction bool
Expand Down Expand Up @@ -732,6 +732,14 @@ func (s *Do) commit_or_rollback() {
}
}

func (s *Do) initialize() {
// TODO initializeWithSearchCondition
}

func (s *Do) updateAttrs_() {
// TODO return false if no updates
}

func (s *Do) initializeWithSearchCondition() {
for _, clause := range s.whereClause {
switch value := clause["query"].(type) {
Expand Down
6 changes: 4 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package gorm
import "errors"

var (
RecordNotFound = errors.New("Record Not Found")
InvalidSql = errors.New("Invalid SQL")
RecordNotFound = errors.New("Record Not Found")
InvalidSql = errors.New("Invalid SQL")
NoNewAttrs = errors.New("No new Attributes")
NoValidTransaction = errors.New("No valid transaction")
)
Loading

0 comments on commit 3cfa19b

Please sign in to comment.