mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
doc: rename cmd entc to ent (#997)
This commit is contained in:
@@ -5,19 +5,19 @@ title: Introduction
|
||||
|
||||
## Installation
|
||||
|
||||
`ent` comes with a codegen tool called `entc`. In order to install
|
||||
`entc` run the following command:
|
||||
The project comes with a codegen tool called `ent`. In order to install
|
||||
`ent` run the following command:
|
||||
|
||||
```bash
|
||||
go get github.com/facebook/ent/cmd/entc
|
||||
go get github.com/facebook/ent/cmd/ent
|
||||
```
|
||||
|
||||
## Initialize A New Schema
|
||||
|
||||
In order to generate one or more schema templates, run `entc init` as follows:
|
||||
In order to generate one or more schema templates, run `ent init` as follows:
|
||||
|
||||
```bash
|
||||
entc init User Pet
|
||||
go run github.com/facebook/ent/cmd/ent init User Pet
|
||||
```
|
||||
|
||||
`init` will create the 2 schemas (`user.go` and `pet.go`) under the `ent/schema` directory.
|
||||
@@ -27,7 +27,7 @@ is to have an `ent` directory under the root directory of the project.
|
||||
## Generate Assets
|
||||
|
||||
After adding a few [fields](schema-fields.md) and [edges](schema-edges.md), you want to generate
|
||||
the assets for working with your entities. Run `entc generate` from the root directory of the project,
|
||||
the assets for working with your entities. Run `ent generate` from the root directory of the project,
|
||||
or use `go generate`:
|
||||
|
||||
|
||||
@@ -45,11 +45,11 @@ The `generate` command generates the following assets for the schemas:
|
||||
|
||||
## Version Compatibility Between `entc` And `ent`
|
||||
|
||||
When working with `entc` in a project, you want to make sure that the version being
|
||||
used by `entc` is **identical** to the `ent` version used by your project.
|
||||
When working with `ent` CLI in a project, you want to make sure the version being
|
||||
used by the CLI is **identical** to the `ent` version used by your project.
|
||||
|
||||
One of the options for achieving this is asking `go generate` to use the version
|
||||
mentioned in the `go.mod` file when running `entc`. If your project does not use
|
||||
mentioned in the `go.mod` file when running `ent`. If your project does not use
|
||||
[Go modules](https://github.com/golang/go/wiki/Modules#quick-start), setup one as follows:
|
||||
|
||||
```console
|
||||
@@ -59,7 +59,7 @@ go mod init <project>
|
||||
And then, re-run the following command in order to add `ent` to your `go.mod` file:
|
||||
|
||||
```console
|
||||
go get github.com/facebook/ent/cmd/entc
|
||||
go get github.com/facebook/ent/cmd/ent
|
||||
```
|
||||
|
||||
Add a `generate.go` file to your project under `<project>/ent`:
|
||||
@@ -67,25 +67,25 @@ Add a `generate.go` file to your project under `<project>/ent`:
|
||||
```go
|
||||
package ent
|
||||
|
||||
//go:generate go run github.com/facebook/ent/cmd/entc generate ./schema
|
||||
//go:generate go run github.com/facebook/ent/cmd/ent generate ./schema
|
||||
```
|
||||
|
||||
Finally, you can run `go generate ./ent` from the root directory of your project
|
||||
in order to run `entc` code generation on your project schemas.
|
||||
in order to run `ent` code generation on your project schemas.
|
||||
|
||||
## Code Generation Options
|
||||
|
||||
For more info about codegen options, run `entc generate -h`:
|
||||
For more info about codegen options, run `ent generate -h`:
|
||||
|
||||
```console
|
||||
generate go code for the schema directory
|
||||
|
||||
Usage:
|
||||
entc generate [flags] path
|
||||
ent generate [flags] path
|
||||
|
||||
Examples:
|
||||
entc generate ./ent/schema
|
||||
entc generate github.com/a8m/x
|
||||
ent generate ./ent/schema
|
||||
ent generate github.com/a8m/x
|
||||
|
||||
Flags:
|
||||
--feature strings extend codegen with additional features
|
||||
@@ -99,24 +99,24 @@ Flags:
|
||||
|
||||
## Storage Options
|
||||
|
||||
`entc` can generate assets for both SQL and Gremlin dialect. The default dialect is SQL.
|
||||
`ent` can generate assets for both SQL and Gremlin dialect. The default dialect is SQL.
|
||||
|
||||
## External Templates
|
||||
|
||||
`entc` accepts external Go templates to execute. If the template name is already defined by
|
||||
`entc`, it will override the existing one. Otherwise, it will write the execution output to
|
||||
`ent` accepts external Go templates to execute. If the template name already defined by
|
||||
`ent`, it will override the existing one. Otherwise, it will write the execution output to
|
||||
a file with the same name as the template. The flag format supports `file`, `dir` and `glob`
|
||||
as follows:
|
||||
|
||||
```console
|
||||
entc generate --template <dir-path> --template glob="path/to/*.tmpl" ./ent/schema
|
||||
go run github.com/facebook/ent/cmd/ent generate --template <dir-path> --template glob="path/to/*.tmpl" ./ent/schema
|
||||
```
|
||||
|
||||
More information and examples can be found in the [external templates doc](templates.md).
|
||||
|
||||
## Use `entc` As A Package
|
||||
|
||||
Another option for running `entc` is to use it as a package as follows:
|
||||
Another option for running `ent` CLI is to use it as a package as follows:
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -148,7 +148,7 @@ The full example exists in [GitHub](https://github.com/facebook/ent/tree/master/
|
||||
In order to get a description of your graph schema, run:
|
||||
|
||||
```bash
|
||||
entc describe ./ent/schema
|
||||
go run github.com/facebook/ent/cmd/ent describe ./ent/schema
|
||||
```
|
||||
|
||||
An example for the output is as follows:
|
||||
|
||||
@@ -3,7 +3,7 @@ id: crud
|
||||
title: CRUD API
|
||||
---
|
||||
|
||||
As mentioned in the [introduction](code-gen.md) section, running `entc` on the schemas,
|
||||
As mentioned in the [introduction](code-gen.md) section, running `ent` on the schemas,
|
||||
will generate the following assets:
|
||||
|
||||
- `Client` and `Tx` objects used for interacting with the graph.
|
||||
|
||||
@@ -20,11 +20,11 @@ and maintain applications with large data-models and sticks with the following p
|
||||
## Installation
|
||||
|
||||
```console
|
||||
go get github.com/facebook/ent/cmd/entc
|
||||
go get github.com/facebook/ent/cmd/ent
|
||||
```
|
||||
|
||||
After installing `entc` (the code generator for `ent`), you should have it in your `PATH`.
|
||||
If you don't find it your path, you can also run: `go run github.com/facebook/ent/cmd/entc <command>`
|
||||
After installing `ent` codegen tool, you should have it in your `PATH`.
|
||||
If you don't find it your path, you can also run: `go run github.com/facebook/ent/cmd/ent <command>`
|
||||
|
||||
## Setup A Go Environment
|
||||
|
||||
@@ -40,7 +40,7 @@ go mod init <project>
|
||||
Go to the root directory of your project, and run:
|
||||
|
||||
```console
|
||||
entc init User
|
||||
ent init User
|
||||
```
|
||||
The command above will generate the schema for `User` under `<project>/ent/schema/` directory:
|
||||
|
||||
@@ -169,7 +169,7 @@ func CreateUser(ctx context.Context, client *ent.Client) (*ent.User, error) {
|
||||
|
||||
## Query Your Entities
|
||||
|
||||
`entc` generates a package for each entity schema that contains its predicates, default values, validators
|
||||
`ent` generates a package for each entity schema that contains its predicates, default values, validators
|
||||
and additional information about storage elements (column names, primary keys, etc).
|
||||
|
||||
```go
|
||||
@@ -201,11 +201,11 @@ func QueryUser(ctx context.Context, client *ent.Client) (*ent.User, error) {
|
||||
|
||||
## Add Your First Edge (Relation)
|
||||
In this part of the tutorial, we want to declare an edge (relation) to another entity in the schema.
|
||||
Let's create 2 additional entities named `Car` and `Group` with a few fields. We use `entc`
|
||||
Let's create 2 additional entities named `Car` and `Group` with a few fields. We use `ent` CLI
|
||||
to generate the initial schemas:
|
||||
|
||||
```console
|
||||
entc init Car Group
|
||||
go run github.com/facebook/ent/cmd/ent init Car Group
|
||||
```
|
||||
|
||||
And then we add the rest of the fields manually:
|
||||
@@ -437,7 +437,7 @@ relationship named `groups`. Let's define this relationship in our schemas:
|
||||
}
|
||||
```
|
||||
|
||||
We run `entc` on the schema directory to re-generate the assets.
|
||||
We run `ent` on the schema directory to re-generate the assets.
|
||||
```console
|
||||
go generate ./ent
|
||||
```
|
||||
|
||||
@@ -68,7 +68,7 @@ In order to enable the privacy option in your code generation, enable the `priva
|
||||
```go
|
||||
package ent
|
||||
|
||||
//go:generate go run github.com/facebook/ent/cmd/entc generate --feature privacy ./schema
|
||||
//go:generate go run github.com/facebook/ent/cmd/ent generate --feature privacy ./schema
|
||||
```
|
||||
|
||||
2\. If you are using the configuration from the GraphQL documentation, add the feature flag as follows:
|
||||
|
||||
@@ -56,7 +56,7 @@ Entity schemas are usually stored inside `ent/schema` directory under
|
||||
the root directory of your project, and can be generated by `entc` as follows:
|
||||
|
||||
```console
|
||||
entc init User Group
|
||||
go run github.com/facebook/ent/cmd/ent init User Group
|
||||
```
|
||||
|
||||
## It's Just Another ORM
|
||||
|
||||
@@ -441,7 +441,7 @@ func (User) Fields() []ent.Field {
|
||||
|
||||
## Additional Struct Fields
|
||||
|
||||
By default, `entc` generates the entity model with fields that are configured in the `schema.Fields` method.
|
||||
By default, `ent` generates the entity model with fields that are configured in the `schema.Fields` method.
|
||||
For example, given this schema configuration:
|
||||
|
||||
```go
|
||||
|
||||
@@ -3,8 +3,8 @@ id: templates
|
||||
title: External Templates
|
||||
---
|
||||
|
||||
`entc` accepts external [Go templates](https://golang.org/pkg/text/template) to execute using the `--template` flag.
|
||||
If the template name is already defined by `entc`, it will override the existing one. Otherwise, it will write the
|
||||
`ent` accepts external [Go templates](https://golang.org/pkg/text/template) to execute using the `--template` flag.
|
||||
If the template name already defined by `ent`, it will override the existing one. Otherwise, it will write the
|
||||
execution output to a file with the same name as the template. For example:
|
||||
|
||||
`stringer.tmpl` - This template example will be written in a file named: `ent/stringer.go`.
|
||||
|
||||
@@ -11,7 +11,7 @@ For the purpose of the example, we'll generate the following graph:
|
||||
The first step is to generate the 3 schemas: `Pet`, `User`, `Group`.
|
||||
|
||||
```console
|
||||
entc init Pet User Group
|
||||
go run github.com/facebook/ent/cmd/ent init Pet User Group
|
||||
```
|
||||
|
||||
Add the necessary fields and edges for the schemas:
|
||||
|
||||
Reference in New Issue
Block a user