Skip to content

Commit

Permalink
Updated README with info about new 'Select' function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronnie Lazar committed Oct 30, 2019
1 parent fd4b65d commit 3e3947a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ err := NewUserQuerySet(getGormDB()).
All(&users)
```

### Select specific fields
By default all fields are fetched using the `*` field selector.
using the `select` methd it is possible to limit the SQL statement to fetch specific fields:
```go
var users []User
err := NewUserQuerySet(getGormDB()).Select(UserDBSchema.ID, UserDBSchema.Rating).All(&users)
if err == gorm.ErrRecordNotFound {
// no records were found
}
```

It generates this SQL request for MySQL:
```sql
SELECT id, rating FROM `users` WHERE `users`.deleted_at IS NULL
```


## Update

### Update one record by primary key
Expand Down

0 comments on commit 3e3947a

Please sign in to comment.