mirror of https://github.com/go-gorm/gorm.git
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
4c8e6a095a
|
@ -164,7 +164,7 @@ db.NewRecord(user) // => true
|
||||||
|
|
||||||
db.Create(&user)
|
db.Create(&user)
|
||||||
|
|
||||||
// will ruturn false after `user` created
|
// will return false after `user` created
|
||||||
db.NewRecord(user) // => false
|
db.NewRecord(user) // => false
|
||||||
|
|
||||||
// You could use `Save` to create record also if its primary key is null
|
// You could use `Save` to create record also if its primary key is null
|
||||||
|
@ -691,7 +691,7 @@ db.Exec("UPDATE orders SET shipped_at=? WHERE id IN (?)", time.Now, []int64{11,2
|
||||||
|
|
||||||
## Row & Rows
|
## Row & Rows
|
||||||
|
|
||||||
You are even possible to get query result as `*sql.Row` or `*sql.Rows`
|
It is even possible to get query result as `*sql.Row` or `*sql.Rows`
|
||||||
|
|
||||||
```go
|
```go
|
||||||
row := db.Table("users").Where("name = ?", "jinzhu").Select("name, age").Row() // (*sql.Row)
|
row := db.Table("users").Where("name = ?", "jinzhu").Select("name, age").Row() // (*sql.Row)
|
||||||
|
|
10
main.go
10
main.go
|
@ -166,12 +166,18 @@ func (s *DB) Assign(attrs ...interface{}) *DB {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) First(out interface{}, where ...interface{}) *DB {
|
func (s *DB) First(out interface{}, where ...interface{}) *DB {
|
||||||
return s.clone().Limit(1).NewScope(out).InstanceSet("gorm:order_by_primary_key", "ASC").
|
newScope := s.clone().NewScope(out)
|
||||||
|
newScope.Search = newScope.Search.clone()
|
||||||
|
newScope.Search.limit(1)
|
||||||
|
return newScope.InstanceSet("gorm:order_by_primary_key", "ASC").
|
||||||
inlineCondition(where...).callCallbacks(s.parent.callback.queries).db
|
inlineCondition(where...).callCallbacks(s.parent.callback.queries).db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) Last(out interface{}, where ...interface{}) *DB {
|
func (s *DB) Last(out interface{}, where ...interface{}) *DB {
|
||||||
return s.clone().Limit(1).NewScope(out).InstanceSet("gorm:order_by_primary_key", "DESC").
|
newScope := s.clone().NewScope(out)
|
||||||
|
newScope.Search = newScope.Search.clone()
|
||||||
|
newScope.Search.limit(1)
|
||||||
|
return newScope.InstanceSet("gorm:order_by_primary_key", "DESC").
|
||||||
inlineCondition(where...).callCallbacks(s.parent.callback.queries).db
|
inlineCondition(where...).callCallbacks(s.parent.callback.queries).db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue