Skip to content

Commit

Permalink
Add enums to readme
Browse files Browse the repository at this point in the history
- Fix a number of indentation and trailing space issues
  • Loading branch information
aarondl committed Nov 12, 2016
1 parent d2eccc9 commit 0cd1b61
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:

```
Expand All @@ -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
Expand Down

0 comments on commit 0cd1b61

Please sign in to comment.