Add enums to readme

- Fix a number of indentation and trailing space issues
This commit is contained in:
Aaron L 2016-11-11 23:59:21 -08:00
parent d2eccc98ad
commit 0cd1b61926

View file

@ -70,10 +70,11 @@ Table of Contents
* [Upsert](#upsert)
* [Reload](#reload)
* [Exists](#exists)
* [Enums](#enums)
* [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)
* [Benchmarks](#benchmarks)
* [Benchmarks](#benchmarks)
## About SQL Boiler
@ -122,8 +123,8 @@ if err != nil {
return err
}
// If you don't want to pass in db to all generated methods
// you can use boil.SetDB to set it globally, and then use
// If you don't want to pass in db to all generated methods
// you can use boil.SetDB to set it globally, and then use
// the G variant methods like so:
boil.SetDB(db)
users, err := models.UsersG().All()
@ -179,7 +180,7 @@ fmt.Println(len(users.R.FavoriteMovies))
* Go 1.6 minimum, and Go 1.7 for compatibility tests.
* Table names and column names should use `snake_case` format.
* We require `snake_case` table names and column names. This is a recommended default in Postgres,
* We require `snake_case` table names and column names. This is a recommended default in Postgres,
and we agree that it's good form, so we're enforcing this format for all drivers for the time being.
* Join tables should use a *composite primary key*.
* For join tables to be used transparently for relationships your join table must have
@ -1049,7 +1050,7 @@ exists, err := models.Pilots(db, Where("id=?", 5)).Exists()
### Enums
If your MySQL or Postgres tables use enums we will generate constants that hold their values
If your MySQL or Postgres tables use enums we will generate constants that hold their values
that you can use in your queries. For example:
```
@ -1064,20 +1065,20 @@ CREATE TABLE event_one (
An enum type defined like the above, being used by a table, will generate the following enums:
```
```go
const (
WorkdayMonday = "monday"
WorkdayTuesday = "tuesday"
WorkdayWednesday = "wednesday"
WorkdayThursday = "thursday"
WorkdayFriday = "friday"
WorkdayMonday = "monday"
WorkdayTuesday = "tuesday"
WorkdayWednesday = "wednesday"
WorkdayThursday = "thursday"
WorkdayFriday = "friday"
)
```
For Postgres we use `enum type name + title cased` value to generate the const variable name.
For MySQL we use `table name + column name + title cased value` to generate the const variable name.
Note: If your enum holds a value we cannot parse correctly due, to non-alphabet characters for example,
Note: If your enum holds a value we cannot parse correctly due, to non-alphabet characters for example,
it may not be generated. In this event, you will receive errors in your generated tests because
the value randomizer in the test suite does not know how to generate valid enum values. You will
still be able to use your generated library, and it will still work as expected, but the only way