doc: add documentation for the sql/schemaconfig feature (#1215)

* Add documentation for the sql/schemaconfig feature

* touch ups
This commit is contained in:
Marwan Sulaiman
2021-01-29 13:40:43 -05:00
committed by GitHub
parent 52cdf98cc2
commit a85e77e5c5

View File

@@ -71,4 +71,19 @@ The `schema/snapshot` option tells `entc` (ent codegen) to store a snapshot of t
and use it to automatically solve merge conflicts when user's schema can't be built.
This option can be added to projects using the `--feature schema/snapshot` flag, but please see
[facebook/ent/issues/852](https://github.com/facebook/ent/issues/852) to get more context about it.
[facebook/ent/issues/852](https://github.com/facebook/ent/issues/852) to get more context about it.
#### Schema Config
The `sql/schemaconfig` option lets you pass alternate SQL database names to models. This is useful when your models don't all live under one database and are spread out across different schemas.
This option can be added to projects using the `--feature sql/schemaconfig` flag. Once you generate the code, you can now use a new option as such:
```golang
c, err := ent.Open(dialect, conn, ent.AlternateSchema(ent.SchemaConfig{
User: "usersdb",
Car: "carsdb",
}))
c.User.Query().All(ctx) // SELECT * FROM `usersdb`.`users`
c.Car.Query().All(ctx) // SELECT * FROM `carsdb`.`cars`
```