From cc47da44fb4b5c243f48f80ea8f7b9914fad4dff Mon Sep 17 00:00:00 2001 From: Aaron L Date: Tue, 27 Jun 2017 21:10:47 -0700 Subject: [PATCH] Amend readme for constants --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 921d4b5..6e07429 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Table of Contents * [Reload](#reload) * [Exists](#exists) * [Enums](#enums) + * [Constants](#constants) * [FAQ](#faq) * [Won't compiling models for a huge database be very slow?](#wont-compiling-models-for-a-huge-database-be-very-slow) * [Missing imports for generated package](#missing-imports-for-generated-package) @@ -1223,6 +1224,41 @@ still be able to use your generated library, and it will still work as expected, to get the tests to pass in this event is to either use a parsable enum value or use a regular column instead of an enum. +### Constants + +The models package will also contain some structs that contain all of the table and column +names harvested from the database at generation time. + +For table names they're generated under `models.TableNames`: + +```go +// Generated code from models package +var TableNames = struct { + Messages string + Purchases string +}{ + Messages: "messages", + Purchases: "purchases", +} + +// Usage example: +fmt.Println(models.TableNames.Messages) +``` + +```go +// Generated code from models package +var MessageColumns = struct { + ID string + PurchaseID string +}{ + ID: "id", + PurchaseID: "purchase_id", +} + +// Usage example: +fmt.Println(models.MessageColumns.ID) +``` + ## FAQ #### Won't compiling models for a huge database be very slow?