mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: add support for adding client fields using template
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/155 Reviewed By: alexsn Differential Revision: D18421223 fbshipit-source-id: 112d4d26d53a64e2c78640c6d508ba2d1d3a7791
This commit is contained in:
committed by
Facebook Github Bot
parent
6ed99b93e5
commit
514c0ff6d3
File diff suppressed because one or more lines are too long
@@ -34,6 +34,7 @@ type Client struct {
|
||||
// {{ $n.Name }} is the client for interacting with the {{ $n.Name }} builders.
|
||||
{{ $n.Name }} *{{ $n.Name }}Client
|
||||
{{ end }}
|
||||
{{ template "client/fields/additional" $ }}
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
@@ -204,3 +205,6 @@ func (c *{{ $client }}) Query{{ pascal $e.Name }}({{ $rec }} *{{ $n.Name }}) *{{
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{/* A template that can be overrided in order to add additional fields to the client.*/}}
|
||||
{{ define "client/fields/additional" }}{{end}}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/facebookincubator/ent/entc/integration/template/ent/migrate"
|
||||
|
||||
@@ -32,6 +33,10 @@ type Client struct {
|
||||
Pet *PetClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
|
||||
// additional fields.
|
||||
sync.Mutex
|
||||
tables []string
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
|
||||
11
entc/integration/template/ent/template/client.tmpl
Normal file
11
entc/integration/template/ent/template/client.tmpl
Normal file
@@ -0,0 +1,11 @@
|
||||
{{/*
|
||||
Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
This source code is licensed under the Apache 2.0 license found
|
||||
in the LICENSE file in the root directory of this source tree.
|
||||
*/}}
|
||||
|
||||
{{ define "client/fields/additional" }}
|
||||
// additional fields.
|
||||
sync.Mutex
|
||||
tables []string
|
||||
{{ end }}
|
||||
@@ -42,4 +42,7 @@ func TestCustomTemplate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, g.ID, node.ID)
|
||||
require.Equal(t, &ent.Field{Type: "int", Name: "MaxUsers", Value: "10"}, node.Fields[0])
|
||||
|
||||
// compile time check for client fields.
|
||||
_ = &client.Mutex
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user