From 1f0f39df388cb79db332798cedc575086becf880 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Mon, 16 Sep 2019 06:05:27 -0700 Subject: [PATCH] ent/doc: add docs for storage-key option Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/36 Reviewed By: dlvhdr Differential Revision: D17395353 fbshipit-source-id: b06de30a66ee4bb79f68a585a981a52ee3f341be --- doc/.dockerignore | 2 -- doc/Dockerfile | 10 ---------- doc/docker-compose.yml | 18 ------------------ doc/md/code-gen.md | 14 ++++++++++++++ doc/md/schema-fields.md | 17 ++++++++++++++++- 5 files changed, 30 insertions(+), 31 deletions(-) delete mode 100755 doc/.dockerignore delete mode 100644 doc/Dockerfile delete mode 100644 doc/docker-compose.yml diff --git a/doc/.dockerignore b/doc/.dockerignore deleted file mode 100755 index 27d2dae2b..000000000 --- a/doc/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -*/node_modules -*.log diff --git a/doc/Dockerfile b/doc/Dockerfile deleted file mode 100644 index d369844d5..000000000 --- a/doc/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM node:8.11.4 - -WORKDIR /app/website - -EXPOSE 3000 35729 -COPY ./docs /app/docs -COPY ./website /app/website -RUN yarn install - -CMD ["yarn", "start"] diff --git a/doc/docker-compose.yml b/doc/docker-compose.yml deleted file mode 100644 index 6711192ae..000000000 --- a/doc/docker-compose.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3" - -services: - docusaurus: - build: . - ports: - - 3000:3000 - - 35729:35729 - volumes: - - ./docs:/app/docs - - ./website/blog:/app/website/blog - - ./website/core:/app/website/core - - ./website/i18n:/app/website/i18n - - ./website/pages:/app/website/pages - - ./website/static:/app/website/static - - ./website/sidebars.json:/app/website/sidebars.json - - ./website/siteConfig.js:/app/website/siteConfig.js - working_dir: /app/website diff --git a/doc/md/code-gen.md b/doc/md/code-gen.md index 05f9ecf07..3c7ead3ef 100755 --- a/doc/md/code-gen.md +++ b/doc/md/code-gen.md @@ -67,8 +67,22 @@ Flags: --idtype [int string] type of the id field (default int) --storage strings list of storage drivers to support (default [sql]) --target string target directory for codegen + --template strings external templates to execute ``` +## Storage Options + +`entc` 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 +a file with the same name as the template. + +Example of a custom template provides a `Node` API for GraphQL - +[Github](https://github.com/facebookincubator/ent/blob/master/entc/integration/template/ent/template/node.tmpl). + ## Schema Description In order to get a description of your graph schema, run: diff --git a/doc/md/schema-fields.md b/doc/md/schema-fields.md index 75b76c071..3b6ba2fa2 100755 --- a/doc/md/schema-fields.md +++ b/doc/md/schema-fields.md @@ -251,6 +251,21 @@ func (User) Fields() []ent.Field { } ``` +## Storage Key + +Custom storage name can be configured using the `StorageKey` method. +It's mapped to a column name in SQL dialects and to property name in Gremlin. + +```go +// Fields of the user. +func (User) Fields() []ent.Field { + return []ent.Field{ + field.String("name"). + StorageKey(`old_name"`), + } +} +``` + ## Indexes Indexes can be defined on multi fields and some types of edges as well. However, you should note, that this is currently an SQL-only feature. @@ -335,4 +350,4 @@ type User struct { Tenant string Logger *log.Logger } -``` \ No newline at end of file +```