Update readme

This commit is contained in:
Patrick O'brien 2016-09-14 20:42:20 +10:00
parent 7ce5ac18ac
commit 7d377f42ae

View file

@ -80,23 +80,28 @@ Table of Contents
### Features ### Features
- Full model generation - Full model generation
- High performance through generation
- Extremely fast code generation - Extremely fast code generation
- High performance through generation & intelligent caching
- Uses boil.Executor (simple interface, sql.DB, sqlx.DB etc. compatible) - Uses boil.Executor (simple interface, sql.DB, sqlx.DB etc. compatible)
- Easy workflow (models can always be regenerated, full auto-complete) - Easy workflow (models can always be regenerated, full auto-complete)
- Strongly typed querying (usually no converting or binding to pointers) - Strongly typed querying (usually no converting or binding to pointers)
- Hooks (Before/After Create/Select/Update/Delete/Upsert) - Hooks (Before/After Create/Select/Update/Delete/Upsert)
- Automatic CreatedAt/UpdatedAt - Automatic CreatedAt/UpdatedAt
- Table whitelist/blacklist
- Relationships/Associations - Relationships/Associations
- Eager loading (recursive) - Eager loading (recursive)
- Custom struct tags
- Schema support
- Transactions - Transactions
- Raw SQL fallback - Raw SQL fallback
- Compatibility tests (Run against your own DB schema) - Compatibility tests (Run against your own DB schema)
- Debug logging - Debug logging
- Postgres 1d arrays, json, hstore & more
### Supported Databases ### Supported Databases
- PostgreSQL - PostgreSQL
- MySQL
*Note: Seeking contributors for other database engines.* *Note: Seeking contributors for other database engines.*
@ -203,36 +208,36 @@ order:
- `$XDG_CONFIG_HOME/sqlboiler/` - `$XDG_CONFIG_HOME/sqlboiler/`
- `$HOME/.config/sqlboiler/` - `$HOME/.config/sqlboiler/`
We require you pass in the `postgres` configuration via the configuration file rather than env vars. We require you pass in your `postgres` and `mysql` database configuration via the configuration file rather than env vars.
There is no command line argument support for database configuration. Values given under the `postgres` There is no command line argument support for database configuration. Values given under the `postgres` and `mysql`
block are passed directly to the [pq](github.com/lib/pq) driver. Here is a rundown of all the different block are passed directly to the postgres and mysql drivers. Here is a rundown of all the different
values that can go in that section: values that can go in that section:
| Name | Required | Default | | Name | Required | Postgres Default | MySQL Default |
| --- | --- | --- | | --- | --- | --- | --- |
| dbname | yes | none | | dbname | yes | none | none |
| host | yes | none | | host | yes | none | none |
| port | no | 5432 | | port | no | 5432 | 3306 |
| user | yes | none | | user | yes | none | none |
| pass | no | none | | pass | no | none | none |
| sslmode | no | "require" | | sslmode | no | "require" | "true" |
You can also pass in these top level configuration values if you would prefer You can also pass in these top level configuration values if you would prefer
not to pass them through the command line or environment variables: not to pass them through the command line or environment variables:
| Name | Default | | Name | Postgres Default | Mysql Default
| --- | --- | | --- | --- | --- |
| basedir | none | | basedir | none | none |
| schema | "public" | | schema | "public" | *N/A* |
| pkgname | "models" | | pkgname | "models" | "models" |
| output | "models" | | output | "models" | "models" |
| whitelist | [] | | whitelist | [] | [] |
| blacklist | [] | | blacklist | [] | [] |
| tag | [] | | tag | [] | [] |
| debug | false | | debug | false | false |
| no-hooks | false | | no-hooks | false | false |
| no-tests | false | | no-tests | false | false |
| no-auto-timestamps | false | | no-auto-timestamps | false | false |
Example: Example:
@ -258,7 +263,8 @@ Usage:
sqlboiler [flags] <driver> sqlboiler [flags] <driver>
Examples: Examples:
sqlboiler postgres sqlboiler postgres
sqlboiler mysql
Flags: Flags:
-b, --blacklist stringSlice Do not include these tables in your generated package -b, --blacklist stringSlice Do not include these tables in your generated package
@ -274,9 +280,9 @@ Flags:
--no-tests Disable generated go test files --no-tests Disable generated go test files
``` ```
Follow the steps below to do some basic model generation. Once we've generated Follow the steps below to do some basic model generation. Once you've generated
our models, we can run the compatibility tests which will exercise the entirety your models, you can run the compatibility tests which will exercise the entirety
of the generated code. This way we can ensure that our database is compatible of the generated code. This way you can ensure that your database is compatible
with SQLBoiler. If you find there are some failing tests, please check the with SQLBoiler. If you find there are some failing tests, please check the
[Diagnosing Problems](#diagnosing-problems) section. [Diagnosing Problems](#diagnosing-problems) section.
@ -285,8 +291,7 @@ with SQLBoiler. If you find there are some failing tests, please check the
sqlboiler -x goose_migrations postgres sqlboiler -x goose_migrations postgres
# Run the generated tests # Run the generated tests
go test ./models # This requires an administrator postgres user because of some go test ./models
# voodoo we do to disable triggers for the generated test db
``` ```
## Diagnosing Problems ## Diagnosing Problems
@ -296,7 +301,7 @@ The most common causes of problems and panics are:
- Forgetting to exclude tables you do not want included in your generation, like migration tables. - Forgetting to exclude tables you do not want included in your generation, like migration tables.
- Tables without a primary key. All tables require one. - Tables without a primary key. All tables require one.
- Forgetting to put foreign key constraints on your columns that reference other tables. - Forgetting to put foreign key constraints on your columns that reference other tables.
- The compatibility tests that run against your own DB schema require a superuser, ensure the user - The compatibility tests require privileges to create a database for testing purposes, ensure the user
supplied in your `sqlboiler.toml` config has adequate privileges. supplied in your `sqlboiler.toml` config has adequate privileges.
- A nil or closed database handle. Ensure your passed in `boil.Executor` is not nil. - A nil or closed database handle. Ensure your passed in `boil.Executor` is not nil.
- If you decide to use the `G` variant of functions instead, make sure you've initialized your - If you decide to use the `G` variant of functions instead, make sure you've initialized your
@ -349,9 +354,8 @@ ALTER TABLE pilot_languages ADD CONSTRAINT pilots_fkey FOREIGN KEY (pilot_id) RE
ALTER TABLE pilot_languages ADD CONSTRAINT languages_fkey FOREIGN KEY (language_id) REFERENCES languages(id); ALTER TABLE pilot_languages ADD CONSTRAINT languages_fkey FOREIGN KEY (language_id) REFERENCES languages(id);
``` ```
The generated model structs for this schema look like the following. Note that I've included the relationship The generated model structs for this schema look like the following. Note that we've included the relationship
structs as well so you can see how it all pieces together, but these are unexported and not something you should structs as well so you can see how it all pieces together:
ever need to touch directly:
```go ```go
type Pilot struct { type Pilot struct {
@ -359,6 +363,7 @@ type Pilot struct {
Name string `boil:"name" json:"name" toml:"name" yaml:"name"` Name string `boil:"name" json:"name" toml:"name" yaml:"name"`
R *pilotR `boil:"-" json:"-" toml:"-" yaml:"-"` R *pilotR `boil:"-" json:"-" toml:"-" yaml:"-"`
L pilotR `boil:"-" json:"-" toml:"-" yaml:"-"`
} }
type pilotR struct { type pilotR struct {
@ -375,6 +380,7 @@ type Jet struct {
Color string `boil:"color" json:"color" toml:"color" yaml:"color"` Color string `boil:"color" json:"color" toml:"color" yaml:"color"`
R *jetR `boil:"-" json:"-" toml:"-" yaml:"-"` R *jetR `boil:"-" json:"-" toml:"-" yaml:"-"`
L jetR `boil:"-" json:"-" toml:"-" yaml:"-"`
} }
type jetR struct { type jetR struct {
@ -386,6 +392,7 @@ type Language struct {
Language string `boil:"language" json:"language" toml:"language" yaml:"language"` Language string `boil:"language" json:"language" toml:"language" yaml:"language"`
R *languageR `boil:"-" json:"-" toml:"-" yaml:"-"` R *languageR `boil:"-" json:"-" toml:"-" yaml:"-"`
L languageR `boil:"-" json:"-" toml:"-" yaml:"-"`
} }
type languageR struct { type languageR struct {
@ -987,7 +994,6 @@ The `conflictColumns` argument allows you to specify the `ON CONFLICT` columns f
For MySQL, this param will not be generated. For MySQL, this param will not be generated.
Note: Passing a different set of column values to the update component is not currently supported. Note: Passing a different set of column values to the update component is not currently supported.
If this feature is important to you let us know and we can consider adding something for this.
### Reload ### Reload
In the event that your objects get out of sync with the database for whatever reason, In the event that your objects get out of sync with the database for whatever reason,
@ -997,7 +1003,7 @@ attached to the objects.
```go ```go
pilot, _ := models.FindPilot(db, 1) pilot, _ := models.FindPilot(db, 1)
// > Object becomes out of sync for some reason // > Object becomes out of sync for some reason, perhaps async processing
// Refresh the object with the latest data from the db // Refresh the object with the latest data from the db
err := pilot.Reload(db) err := pilot.Reload(db)