From 3e3947a12289147673b1c8755e121d3325712ad3 Mon Sep 17 00:00:00 2001 From: Ronnie Lazar Date: Wed, 30 Oct 2019 16:15:09 +0200 Subject: [PATCH] Updated README with info about new 'Select' function --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index edd0ee6..7c6d06b 100644 --- a/README.md +++ b/README.md @@ -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