forked from mirror/gorm
README cleanup: Consistent comment prefixing `////` for raw SQL example output.
This commit is contained in:
parent
58ff124210
commit
250de0376b
20
README.md
20
README.md
|
@ -228,13 +228,13 @@ db.Where("name = ?", "jinzhu").Find(&users)
|
||||||
|
|
||||||
db.Where("name <> ?", "jinzhu").Find(&users)
|
db.Where("name <> ?", "jinzhu").Find(&users)
|
||||||
|
|
||||||
// IN
|
//// IN
|
||||||
db.Where("name in (?)", []string{"jinzhu", "jinzhu 2"}).Find(&users)
|
db.Where("name in (?)", []string{"jinzhu", "jinzhu 2"}).Find(&users)
|
||||||
|
|
||||||
// LIKE
|
//// LIKE
|
||||||
db.Where("name LIKE ?", "%jin%").Find(&users)
|
db.Where("name LIKE ?", "%jin%").Find(&users)
|
||||||
|
|
||||||
// AND
|
//// AND
|
||||||
db.Where("name = ? and age >= ?", "jinzhu", "22").Find(&users)
|
db.Where("name = ? and age >= ?", "jinzhu", "22").Find(&users)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -384,14 +384,14 @@ db.Model(User{}).Updates(User{Name: "hello", Age: 18}).RowsAffected
|
||||||
```go
|
```go
|
||||||
// Delete an existing record
|
// Delete an existing record
|
||||||
db.Delete(&email)
|
db.Delete(&email)
|
||||||
// DELETE from emails where id=10;
|
//// DELETE from emails where id=10;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Batch Delete
|
### Batch Delete
|
||||||
|
|
||||||
```go
|
```go
|
||||||
db.Where("email LIKE ?", "%jinzhu%").Delete(Email{})
|
db.Where("email LIKE ?", "%jinzhu%").Delete(Email{})
|
||||||
// DELETE from emails where email LIKE "%jinhu%";
|
//// DELETE from emails where email LIKE "%jinhu%";
|
||||||
```
|
```
|
||||||
|
|
||||||
### Soft Delete
|
### Soft Delete
|
||||||
|
@ -417,7 +417,7 @@ db.Unscoped().Where("age = 20").Find(&users)
|
||||||
|
|
||||||
// Delete record permanently with Unscoped
|
// Delete record permanently with Unscoped
|
||||||
db.Unscoped().Delete(&order)
|
db.Unscoped().Delete(&order)
|
||||||
// DELETE FROM orders WHERE id=10;
|
//// DELETE FROM orders WHERE id=10;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Associations
|
## Associations
|
||||||
|
@ -721,8 +721,8 @@ Scan results into another struct.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
|
|
||||||
var result Result
|
var result Result
|
||||||
|
@ -746,8 +746,8 @@ for rows.Next() {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Total int64
|
Total int64
|
||||||
}
|
}
|
||||||
db.Table("orders").Select("date(created_at) as date, sum(amount) as total").Group("date(created_at)").Having("sum(amount) > ?", 100).Scan(&results)
|
db.Table("orders").Select("date(created_at) as date, sum(amount) as total").Group("date(created_at)").Having("sum(amount) > ?", 100).Scan(&results)
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue