From 770bb0f1a26d958ae4eb982177108bb268c8a9c5 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Date: Thu, 16 Feb 2023 12:08:41 +0200 Subject: [PATCH] entc/gen: merge generate config.go file with client.go (#3319) --- entc/gen/graph.go | 8 +- entc/gen/graph_test.go | 2 +- entc/gen/template.go | 9 +- entc/gen/template/client.tmpl | 107 +++++++++++++++- entc/gen/template/config.tmpl | 126 ------------------ entc/integration/cascadelete/ent/client.go | 71 +++++++++- entc/integration/cascadelete/ent/config.go | 74 ----------- entc/integration/config/ent/client.go | 63 ++++++++- entc/integration/config/ent/config.go | 70 ---------- entc/integration/customid/ent/client.go | 99 +++++++++++++- entc/integration/customid/ent/config.go | 102 --------------- entc/integration/edgefield/ent/client.go | 83 +++++++++++- entc/integration/edgefield/ent/config.go | 86 ------------- entc/integration/edgeschema/ent/client.go | 99 +++++++++++++- entc/integration/edgeschema/ent/config.go | 102 --------------- entc/integration/ent/client.go | 121 +++++++++++++++++- entc/integration/ent/config.go | 128 ------------------- entc/integration/gremlin/ent/client.go | 99 +++++++++++++- entc/integration/gremlin/ent/config.go | 100 --------------- entc/integration/hooks/ent/client.go | 71 +++++++++- entc/integration/hooks/ent/config.go | 74 ----------- entc/integration/idtype/ent/client.go | 63 ++++++++- entc/integration/idtype/ent/config.go | 70 ---------- entc/integration/json/ent/client.go | 63 ++++++++- entc/integration/json/ent/config.go | 70 ---------- entc/integration/migrate/entv1/client.go | 75 ++++++++++- entc/integration/migrate/entv1/config.go | 76 ----------- entc/integration/migrate/entv2/client.go | 83 +++++++++++- entc/integration/migrate/entv2/config.go | 86 ------------- entc/integration/migrate/versioned/client.go | 67 +++++++++- entc/integration/migrate/versioned/config.go | 72 ----------- entc/integration/multischema/ent/client.go | 93 +++++++++++++- entc/integration/multischema/ent/config.go | 99 -------------- entc/integration/privacy/ent/client.go | 79 +++++++++++- entc/integration/privacy/ent/config.go | 84 ------------ entc/integration/template/ent/client.go | 81 +++++++++++- entc/integration/template/ent/config.go | 85 ------------ examples/edgeindex/ent/client.go | 67 +++++++++- examples/edgeindex/ent/config.go | 72 ----------- examples/encryptfield/ent/client.go | 72 ++++++++++- examples/encryptfield/ent/config.go | 79 ------------ examples/entcpkg/ent/client.go | 80 +++++++++++- examples/entcpkg/ent/config.go | 89 ------------- examples/fs/ent/client.go | 63 ++++++++- examples/fs/ent/config.go | 70 ---------- examples/jsonencode/ent/client.go | 71 +++++++++- examples/jsonencode/ent/config.go | 74 ----------- examples/m2m2types/ent/client.go | 67 +++++++++- examples/m2m2types/ent/config.go | 72 ----------- examples/m2mbidi/ent/client.go | 63 ++++++++- examples/m2mbidi/ent/config.go | 70 ---------- examples/m2mrecur/ent/client.go | 63 ++++++++- examples/m2mrecur/ent/config.go | 70 ---------- examples/migration/ent/client.go | 71 +++++++++- examples/migration/ent/config.go | 74 ----------- examples/o2m2types/ent/client.go | 67 +++++++++- examples/o2m2types/ent/config.go | 72 ----------- examples/o2mrecur/ent/client.go | 63 ++++++++- examples/o2mrecur/ent/config.go | 70 ---------- examples/o2o2types/ent/client.go | 67 +++++++++- examples/o2o2types/ent/config.go | 72 ----------- examples/o2obidi/ent/client.go | 63 ++++++++- examples/o2obidi/ent/config.go | 70 ---------- examples/o2orecur/ent/client.go | 63 ++++++++- examples/o2orecur/ent/config.go | 70 ---------- examples/privacyadmin/ent/client.go | 63 ++++++++- examples/privacyadmin/ent/config.go | 70 ---------- examples/privacytenant/ent/client.go | 71 +++++++++- examples/privacytenant/ent/config.go | 74 ----------- examples/start/ent/client.go | 71 +++++++++- examples/start/ent/config.go | 74 ----------- examples/traversal/ent/client.go | 71 +++++++++- examples/traversal/ent/config.go | 74 ----------- examples/version/ent/client.go | 63 ++++++++- examples/version/ent/config.go | 70 ---------- 75 files changed, 2598 insertions(+), 3007 deletions(-) delete mode 100644 entc/gen/template/config.tmpl delete mode 100644 entc/integration/cascadelete/ent/config.go delete mode 100644 entc/integration/config/ent/config.go delete mode 100644 entc/integration/customid/ent/config.go delete mode 100644 entc/integration/edgefield/ent/config.go delete mode 100644 entc/integration/edgeschema/ent/config.go delete mode 100644 entc/integration/ent/config.go delete mode 100644 entc/integration/gremlin/ent/config.go delete mode 100644 entc/integration/hooks/ent/config.go delete mode 100644 entc/integration/idtype/ent/config.go delete mode 100644 entc/integration/json/ent/config.go delete mode 100644 entc/integration/migrate/entv1/config.go delete mode 100644 entc/integration/migrate/entv2/config.go delete mode 100644 entc/integration/migrate/versioned/config.go delete mode 100644 entc/integration/multischema/ent/config.go delete mode 100644 entc/integration/privacy/ent/config.go delete mode 100644 entc/integration/template/ent/config.go delete mode 100644 examples/edgeindex/ent/config.go delete mode 100644 examples/encryptfield/ent/config.go delete mode 100644 examples/entcpkg/ent/config.go delete mode 100644 examples/fs/ent/config.go delete mode 100644 examples/jsonencode/ent/config.go delete mode 100644 examples/m2m2types/ent/config.go delete mode 100644 examples/m2mbidi/ent/config.go delete mode 100644 examples/m2mrecur/ent/config.go delete mode 100644 examples/migration/ent/config.go delete mode 100644 examples/o2m2types/ent/config.go delete mode 100644 examples/o2mrecur/ent/config.go delete mode 100644 examples/o2o2types/ent/config.go delete mode 100644 examples/o2obidi/ent/config.go delete mode 100644 examples/o2orecur/ent/config.go delete mode 100644 examples/privacyadmin/ent/config.go delete mode 100644 examples/privacytenant/ent/config.go delete mode 100644 examples/start/ent/config.go delete mode 100644 examples/traversal/ent/config.go delete mode 100644 examples/version/ent/config.go diff --git a/entc/gen/graph.go b/entc/gen/graph.go index 73f0eaf4c..5b2b05803 100644 --- a/entc/gen/graph.go +++ b/entc/gen/graph.go @@ -259,8 +259,14 @@ func generate(g *Graph) error { if err := assets.write(); err != nil { return err } - // cleanup assets that are not needed anymore. + // Cleanup nodes' assets and old template + // files that are not needed anymore. cleanOldNodes(assets, g.Config.Target) + for _, n := range deletedTemplates { + if err := os.Remove(filepath.Join(g.Target, n)); err != nil && !os.IsNotExist(err) { + log.Printf("remove old file %s: %s\n", filepath.Join(g.Target, n), err) + } + } // We can't run "imports" on files when the state is not completed. // Because, "goimports" will drop undefined package. Therefore, it // is suspended to the end of the writing. diff --git a/entc/gen/graph_test.go b/entc/gen/graph_test.go index 9ecc94c2b..171a1c852 100644 --- a/entc/gen/graph_test.go +++ b/entc/gen/graph_test.go @@ -440,7 +440,7 @@ func TestGraph_Gen(t *testing.T) { require.NotNil(graph) require.NoError(graph.Gen()) // Ensure graph files were generated. - for _, name := range []string{"ent", "client", "config"} { + for _, name := range []string{"ent", "client"} { _, err := os.Stat(fmt.Sprintf("%s/%s.go", target, name)) require.NoError(err) } diff --git a/entc/gen/template.go b/entc/gen/template.go index dbe3d3e5b..d1c8d8c79 100644 --- a/entc/gen/template.go +++ b/entc/gen/template.go @@ -111,13 +111,6 @@ var ( Name: "tx", Format: "tx.go", }, - { - Name: "config", - Format: "config.go", - ExtendPatterns: []string{ - "dialect/*/config/*/*", - }, - }, { Name: "mutation", Format: "mutation.go", @@ -174,6 +167,8 @@ var ( Format: "runtime/runtime.go", }, } + // template files that were deleted and should be removed by the codegen. + deletedTemplates = []string{"config.go"} // patterns for extending partial-templates (included by other templates). partialPatterns = [...]string{ "client/additional/*", diff --git a/entc/gen/template/client.tmpl b/entc/gen/template/client.tmpl index 03647675e..f9ced97de 100644 --- a/entc/gen/template/client.tmpl +++ b/entc/gen/template/client.tmpl @@ -50,6 +50,9 @@ func (c *Client) init() { {{ $pkg := base $.Config.Package }} {{ template "header" $ }} +{{/* Additional dependencies injected to config. */}} +{{ $deps := list }}{{ with $.Config.Annotations }}{{ $deps = $.Config.Annotations.Dependencies }}{{ end }} + import ( "log" @@ -57,15 +60,89 @@ import ( {{ range $n := $.Nodes }} {{ $n.PackageAlias }} "{{ $n.Config.Package }}/{{ $n.PackageDir }}" {{- end }} - + {{- range $dep := $deps }} + {{ $dep.Type.PkgName }} "{{ $dep.Type.PkgPath }}" + {{- end }} "entgo.io/ent/dialect" {{ range $import := $.Storage.Imports -}} "{{ $import }}" {{ end -}} + {{- template "import/additional" $ }} ) {{ template "client/init" $ }} +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + {{- /* Additional dependency fields. */}} + {{- range $dep := $deps }} + {{ $dep.Field }} {{ $dep.Type }} + {{- end }} + {{- /* Support adding config fields from both global or dialect-specific templates. */}} + {{- range $prefix := list "" (printf "dialect/%s/" $.Storage) }} + {{- with $tmpls := matchTemplate (print $prefix "config/fields/*") }} + {{- range $tmpl := $tmpls }} + {{ xtemplate $tmpl $ }} + {{- end }} + {{- end }} + {{- end }} + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + +{{- /* Additional dependency options reside on the config object. */}} +{{- range $dep := $deps }} + // {{ $dep.Option }} configures the {{ $dep.Field }}. + func {{ $dep.Option }}(v {{ $dep.Type }}) Option { + return func(c *config) { + c.{{ $dep.Field }} = v + } + } +{{- end }} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -339,6 +416,34 @@ func (c *{{ $client }}) mutate(ctx context.Context, m *{{ $n.MutationName }}) (V } } {{ end }} +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + {{- range $n := $.Nodes }} + {{ $n.Name }} []ent.Hook + {{- end }} + } + inters struct { + {{- range $n := $.Nodes }} + {{ $n.Name }} []ent.Interceptor + {{- end }} + } +) + +{{- /* Support adding config options from both global or dialect-specific templates. */}} +{{- range $prefix := list "" (printf "dialect/%s/" $.Storage) }} + {{- with $tmpls := matchTemplate (print $prefix "config/options/*") }} + {{- range $tmpl := $tmpls }} + {{ xtemplate $tmpl $ }} + {{- end }} + {{- end }} +{{- end }} + +{{- with $tmpls := matchTemplate "config/additional/*" "config/additional/*/*" }} + {{- range $tmpl := $tmpls }} + {{- xtemplate $tmpl $ }} + {{- end }} +{{- end }} {{ end }} {{/* A template that can be overridden in order to add additional fields to the client.*/}} diff --git a/entc/gen/template/config.tmpl b/entc/gen/template/config.tmpl deleted file mode 100644 index 8d6271d74..000000000 --- a/entc/gen/template/config.tmpl +++ /dev/null @@ -1,126 +0,0 @@ -{{/* -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. -*/}} - -{{/* gotype: entgo.io/ent/entc/gen.Graph */}} - -{{ define "config" }} - -{{ $pkg := base $.Config.Package }} -{{/* Additional dependencies. */}} -{{ $deps := list }}{{ with $.Config.Annotations }}{{ $deps = $.Config.Annotations.Dependencies }}{{ end }} - -{{ template "header" $ }} - -{{ template "import" $ }} - -{{ with $deps }} - import ( - {{- range $dep := $deps }} - {{ $dep.Type.PkgName }} "{{ $dep.Type.PkgPath }}" - {{- end }} - ) -{{ end }} - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - {{- /* Additional dependency fields. */}} - {{- range $dep := $deps }} - {{ $dep.Field }} {{ $dep.Type }} - {{- end }} - {{- /* Support adding config fields from both global or dialect-specific templates. */}} - {{- range $prefix := list "" (printf "dialect/%s/" $.Storage) }} - {{- with $tmpls := matchTemplate (print $prefix "config/fields/*") }} - {{- range $tmpl := $tmpls }} - {{ xtemplate $tmpl $ }} - {{- end }} - {{- end }} - {{- end }} -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - {{- range $n := $.Nodes }} - {{ $n.Name }} []ent.Hook - {{- end }} - } - inters struct { - {{- range $n := $.Nodes }} - {{ $n.Name }} []ent.Interceptor - {{- end }} - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -{{- /* Additional dependency options. */}} -{{- range $dep := $deps }} - // {{ $dep.Option }} configures the {{ $dep.Field }}. - func {{ $dep.Option }}(v {{ $dep.Type }}) Option { - return func(c *config) { - c.{{ $dep.Field }} = v - } - } -{{- end }} - -{{- /* Support adding config options from both global or dialect-specific templates. */}} -{{- range $prefix := list "" (printf "dialect/%s/" $.Storage) }} - {{- with $tmpls := matchTemplate (print $prefix "config/options/*") }} - {{- range $tmpl := $tmpls }} - {{ xtemplate $tmpl $ }} - {{- end }} - {{- end }} -{{- end }} - -{{- with $tmpls := matchTemplate "config/additional/*" "config/additional/*/*" }} - {{- range $tmpl := $tmpls }} - {{- xtemplate $tmpl $ }} - {{- end }} -{{- end }} - -{{ end }} diff --git a/entc/integration/cascadelete/ent/client.go b/entc/integration/cascadelete/ent/client.go index 7f2c3a6d6..200cfd0e8 100644 --- a/entc/integration/cascadelete/ent/client.go +++ b/entc/integration/cascadelete/ent/client.go @@ -12,15 +12,15 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/cascadelete/ent/migrate" - "entgo.io/ent/entc/integration/cascadelete/ent/comment" - "entgo.io/ent/entc/integration/cascadelete/ent/post" - "entgo.io/ent/entc/integration/cascadelete/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entc/integration/cascadelete/ent/comment" + "entgo.io/ent/entc/integration/cascadelete/ent/post" + "entgo.io/ent/entc/integration/cascadelete/ent/user" ) // Client is the client that holds all ent builders. @@ -52,6 +52,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -580,3 +629,17 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Comment []ent.Hook + Post []ent.Hook + User []ent.Hook + } + inters struct { + Comment []ent.Interceptor + Post []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/entc/integration/cascadelete/ent/config.go b/entc/integration/cascadelete/ent/config.go deleted file mode 100644 index d695a2be7..000000000 --- a/entc/integration/cascadelete/ent/config.go +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Comment []ent.Hook - Post []ent.Hook - User []ent.Hook - } - inters struct { - Comment []ent.Interceptor - Post []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/config/ent/client.go b/entc/integration/config/ent/client.go index d40d6441a..b75ddddc3 100644 --- a/entc/integration/config/ent/client.go +++ b/entc/integration/config/ent/client.go @@ -12,12 +12,12 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/config/ent/migrate" - "entgo.io/ent/entc/integration/config/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/entc/integration/config/ent/user" ) // Client is the client that holds all ent builders. @@ -43,6 +43,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -259,3 +308,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/entc/integration/config/ent/config.go b/entc/integration/config/ent/config.go deleted file mode 100644 index daad44de4..000000000 --- a/entc/integration/config/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/customid/ent/client.go b/entc/integration/customid/ent/client.go index c1954c601..78654fbc9 100644 --- a/entc/integration/customid/ent/client.go +++ b/entc/integration/customid/ent/client.go @@ -12,12 +12,16 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/customid/ent/migrate" "entgo.io/ent/entc/integration/customid/ent/schema" "entgo.io/ent/entc/integration/customid/sid" uuidc "entgo.io/ent/entc/integration/customid/uuidcompatible" "github.com/google/uuid" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/entc/integration/customid/ent/account" "entgo.io/ent/entc/integration/customid/ent/blob" "entgo.io/ent/entc/integration/customid/ent/bloblink" @@ -35,10 +39,6 @@ import ( "entgo.io/ent/entc/integration/customid/ent/session" "entgo.io/ent/entc/integration/customid/ent/token" "entgo.io/ent/entc/integration/customid/ent/user" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" ) // Client is the client that holds all ent builders. @@ -112,6 +112,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -2695,3 +2744,45 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Account []ent.Hook + Blob []ent.Hook + BlobLink []ent.Hook + Car []ent.Hook + Device []ent.Hook + Doc []ent.Hook + Group []ent.Hook + IntSID []ent.Hook + Link []ent.Hook + MixinID []ent.Hook + Note []ent.Hook + Other []ent.Hook + Pet []ent.Hook + Revision []ent.Hook + Session []ent.Hook + Token []ent.Hook + User []ent.Hook + } + inters struct { + Account []ent.Interceptor + Blob []ent.Interceptor + BlobLink []ent.Interceptor + Car []ent.Interceptor + Device []ent.Interceptor + Doc []ent.Interceptor + Group []ent.Interceptor + IntSID []ent.Interceptor + Link []ent.Interceptor + MixinID []ent.Interceptor + Note []ent.Interceptor + Other []ent.Interceptor + Pet []ent.Interceptor + Revision []ent.Interceptor + Session []ent.Interceptor + Token []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/entc/integration/customid/ent/config.go b/entc/integration/customid/ent/config.go deleted file mode 100644 index 4069050f4..000000000 --- a/entc/integration/customid/ent/config.go +++ /dev/null @@ -1,102 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Account []ent.Hook - Blob []ent.Hook - BlobLink []ent.Hook - Car []ent.Hook - Device []ent.Hook - Doc []ent.Hook - Group []ent.Hook - IntSID []ent.Hook - Link []ent.Hook - MixinID []ent.Hook - Note []ent.Hook - Other []ent.Hook - Pet []ent.Hook - Revision []ent.Hook - Session []ent.Hook - Token []ent.Hook - User []ent.Hook - } - inters struct { - Account []ent.Interceptor - Blob []ent.Interceptor - BlobLink []ent.Interceptor - Car []ent.Interceptor - Device []ent.Interceptor - Doc []ent.Interceptor - Group []ent.Interceptor - IntSID []ent.Interceptor - Link []ent.Interceptor - MixinID []ent.Interceptor - Note []ent.Interceptor - Other []ent.Interceptor - Pet []ent.Interceptor - Revision []ent.Interceptor - Session []ent.Interceptor - Token []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/edgefield/ent/client.go b/entc/integration/edgefield/ent/client.go index 5d3241a7c..be9bd3c93 100644 --- a/entc/integration/edgefield/ent/client.go +++ b/entc/integration/edgefield/ent/client.go @@ -12,9 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/edgefield/ent/migrate" "github.com/google/uuid" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/entc/integration/edgefield/ent/car" "entgo.io/ent/entc/integration/edgefield/ent/card" "entgo.io/ent/entc/integration/edgefield/ent/info" @@ -24,10 +28,6 @@ import ( "entgo.io/ent/entc/integration/edgefield/ent/post" "entgo.io/ent/entc/integration/edgefield/ent/rental" "entgo.io/ent/entc/integration/edgefield/ent/user" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" ) // Client is the client that holds all ent builders. @@ -77,6 +77,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -1605,3 +1654,29 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Car []ent.Hook + Card []ent.Hook + Info []ent.Hook + Metadata []ent.Hook + Node []ent.Hook + Pet []ent.Hook + Post []ent.Hook + Rental []ent.Hook + User []ent.Hook + } + inters struct { + Car []ent.Interceptor + Card []ent.Interceptor + Info []ent.Interceptor + Metadata []ent.Interceptor + Node []ent.Interceptor + Pet []ent.Interceptor + Post []ent.Interceptor + Rental []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/entc/integration/edgefield/ent/config.go b/entc/integration/edgefield/ent/config.go deleted file mode 100644 index 2cd04ac06..000000000 --- a/entc/integration/edgefield/ent/config.go +++ /dev/null @@ -1,86 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Car []ent.Hook - Card []ent.Hook - Info []ent.Hook - Metadata []ent.Hook - Node []ent.Hook - Pet []ent.Hook - Post []ent.Hook - Rental []ent.Hook - User []ent.Hook - } - inters struct { - Car []ent.Interceptor - Card []ent.Interceptor - Info []ent.Interceptor - Metadata []ent.Interceptor - Node []ent.Interceptor - Pet []ent.Interceptor - Post []ent.Interceptor - Rental []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/edgeschema/ent/client.go b/entc/integration/edgeschema/ent/client.go index aeb292c7a..4059fd268 100644 --- a/entc/integration/edgeschema/ent/client.go +++ b/entc/integration/edgeschema/ent/client.go @@ -12,9 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/edgeschema/ent/migrate" "github.com/google/uuid" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/entc/integration/edgeschema/ent/attachedfile" "entgo.io/ent/entc/integration/edgeschema/ent/file" "entgo.io/ent/entc/integration/edgeschema/ent/friendship" @@ -32,10 +36,6 @@ import ( "entgo.io/ent/entc/integration/edgeschema/ent/user" "entgo.io/ent/entc/integration/edgeschema/ent/usergroup" "entgo.io/ent/entc/integration/edgeschema/ent/usertweet" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" ) // Client is the client that holds all ent builders. @@ -109,6 +109,55 @@ func (c *Client) init() { c.UserTweet = NewUserTweetClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -2956,3 +3005,45 @@ func (c *UserTweetClient) mutate(ctx context.Context, m *UserTweetMutation) (Val return nil, fmt.Errorf("ent: unknown UserTweet mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + AttachedFile []ent.Hook + File []ent.Hook + Friendship []ent.Hook + Group []ent.Hook + GroupTag []ent.Hook + Process []ent.Hook + Relationship []ent.Hook + RelationshipInfo []ent.Hook + Role []ent.Hook + RoleUser []ent.Hook + Tag []ent.Hook + Tweet []ent.Hook + TweetLike []ent.Hook + TweetTag []ent.Hook + User []ent.Hook + UserGroup []ent.Hook + UserTweet []ent.Hook + } + inters struct { + AttachedFile []ent.Interceptor + File []ent.Interceptor + Friendship []ent.Interceptor + Group []ent.Interceptor + GroupTag []ent.Interceptor + Process []ent.Interceptor + Relationship []ent.Interceptor + RelationshipInfo []ent.Interceptor + Role []ent.Interceptor + RoleUser []ent.Interceptor + Tag []ent.Interceptor + Tweet []ent.Interceptor + TweetLike []ent.Interceptor + TweetTag []ent.Interceptor + User []ent.Interceptor + UserGroup []ent.Interceptor + UserTweet []ent.Interceptor + } +) diff --git a/entc/integration/edgeschema/ent/config.go b/entc/integration/edgeschema/ent/config.go deleted file mode 100644 index 1bc8e37f3..000000000 --- a/entc/integration/edgeschema/ent/config.go +++ /dev/null @@ -1,102 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - AttachedFile []ent.Hook - File []ent.Hook - Friendship []ent.Hook - Group []ent.Hook - GroupTag []ent.Hook - Process []ent.Hook - Relationship []ent.Hook - RelationshipInfo []ent.Hook - Role []ent.Hook - RoleUser []ent.Hook - Tag []ent.Hook - Tweet []ent.Hook - TweetLike []ent.Hook - TweetTag []ent.Hook - User []ent.Hook - UserGroup []ent.Hook - UserTweet []ent.Hook - } - inters struct { - AttachedFile []ent.Interceptor - File []ent.Interceptor - Friendship []ent.Interceptor - Group []ent.Interceptor - GroupTag []ent.Interceptor - Process []ent.Interceptor - Relationship []ent.Interceptor - RelationshipInfo []ent.Interceptor - Role []ent.Interceptor - RoleUser []ent.Interceptor - Tag []ent.Interceptor - Tweet []ent.Interceptor - TweetLike []ent.Interceptor - TweetTag []ent.Interceptor - User []ent.Interceptor - UserGroup []ent.Interceptor - UserTweet []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/ent/client.go b/entc/integration/ent/client.go index 2fbd9eca4..8e64d37ca 100644 --- a/entc/integration/ent/client.go +++ b/entc/integration/ent/client.go @@ -12,8 +12,12 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/ent/migrate" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/entc/integration/ent/api" "entgo.io/ent/entc/integration/ent/card" "entgo.io/ent/entc/integration/ent/comment" @@ -31,9 +35,7 @@ import ( enttask "entgo.io/ent/entc/integration/ent/task" "entgo.io/ent/entc/integration/ent/user" - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" + stdsql "database/sql" ) // Client is the client that holds all ent builders. @@ -105,6 +107,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -2623,3 +2674,67 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Api []ent.Hook + Card []ent.Hook + Comment []ent.Hook + FieldType []ent.Hook + File []ent.Hook + FileType []ent.Hook + Goods []ent.Hook + Group []ent.Hook + GroupInfo []ent.Hook + Item []ent.Hook + License []ent.Hook + Node []ent.Hook + Pet []ent.Hook + Spec []ent.Hook + Task []ent.Hook + User []ent.Hook + } + inters struct { + Api []ent.Interceptor + Card []ent.Interceptor + Comment []ent.Interceptor + FieldType []ent.Interceptor + File []ent.Interceptor + FileType []ent.Interceptor + Goods []ent.Interceptor + Group []ent.Interceptor + GroupInfo []ent.Interceptor + Item []ent.Interceptor + License []ent.Interceptor + Node []ent.Interceptor + Pet []ent.Interceptor + Spec []ent.Interceptor + Task []ent.Interceptor + User []ent.Interceptor + } +) + +// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it. +// See, database/sql#DB.ExecContext for more information. +func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { + ex, ok := c.driver.(interface { + ExecContext(context.Context, string, ...any) (stdsql.Result, error) + }) + if !ok { + return nil, fmt.Errorf("Driver.ExecContext is not supported") + } + return ex.ExecContext(ctx, query, args...) +} + +// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it. +// See, database/sql#DB.QueryContext for more information. +func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { + q, ok := c.driver.(interface { + QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) + }) + if !ok { + return nil, fmt.Errorf("Driver.QueryContext is not supported") + } + return q.QueryContext(ctx, query, args...) +} diff --git a/entc/integration/ent/config.go b/entc/integration/ent/config.go deleted file mode 100644 index 42ffaf82e..000000000 --- a/entc/integration/ent/config.go +++ /dev/null @@ -1,128 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - stdsql "database/sql" - "fmt" - - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Api []ent.Hook - Card []ent.Hook - Comment []ent.Hook - FieldType []ent.Hook - File []ent.Hook - FileType []ent.Hook - Goods []ent.Hook - Group []ent.Hook - GroupInfo []ent.Hook - Item []ent.Hook - License []ent.Hook - Node []ent.Hook - Pet []ent.Hook - Spec []ent.Hook - Task []ent.Hook - User []ent.Hook - } - inters struct { - Api []ent.Interceptor - Card []ent.Interceptor - Comment []ent.Interceptor - FieldType []ent.Interceptor - File []ent.Interceptor - FileType []ent.Interceptor - Goods []ent.Interceptor - Group []ent.Interceptor - GroupInfo []ent.Interceptor - Item []ent.Interceptor - License []ent.Interceptor - Node []ent.Interceptor - Pet []ent.Interceptor - Spec []ent.Interceptor - Task []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it. -// See, database/sql#DB.ExecContext for more information. -func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { - ex, ok := c.driver.(interface { - ExecContext(context.Context, string, ...any) (stdsql.Result, error) - }) - if !ok { - return nil, fmt.Errorf("Driver.ExecContext is not supported") - } - return ex.ExecContext(ctx, query, args...) -} - -// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it. -// See, database/sql#DB.QueryContext for more information. -func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { - q, ok := c.driver.(interface { - QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) - }) - if !ok { - return nil, fmt.Errorf("Driver.QueryContext is not supported") - } - return q.QueryContext(ctx, query, args...) -} diff --git a/entc/integration/gremlin/ent/client.go b/entc/integration/gremlin/ent/client.go index bc6098c09..33cf1a7e4 100644 --- a/entc/integration/gremlin/ent/client.go +++ b/entc/integration/gremlin/ent/client.go @@ -13,6 +13,11 @@ import ( "log" "net/url" + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/gremlin" + "entgo.io/ent/dialect/gremlin/graph/dsl" + "entgo.io/ent/dialect/gremlin/graph/dsl/g" "entgo.io/ent/entc/integration/gremlin/ent/api" "entgo.io/ent/entc/integration/gremlin/ent/card" "entgo.io/ent/entc/integration/gremlin/ent/comment" @@ -29,11 +34,6 @@ import ( "entgo.io/ent/entc/integration/gremlin/ent/spec" enttask "entgo.io/ent/entc/integration/gremlin/ent/task" "entgo.io/ent/entc/integration/gremlin/ent/user" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/gremlin" - "entgo.io/ent/dialect/gremlin/graph/dsl" - "entgo.io/ent/dialect/gremlin/graph/dsl/g" ) // Client is the client that holds all ent builders. @@ -102,6 +102,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -2459,3 +2508,43 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Api []ent.Hook + Card []ent.Hook + Comment []ent.Hook + FieldType []ent.Hook + File []ent.Hook + FileType []ent.Hook + Goods []ent.Hook + Group []ent.Hook + GroupInfo []ent.Hook + Item []ent.Hook + License []ent.Hook + Node []ent.Hook + Pet []ent.Hook + Spec []ent.Hook + Task []ent.Hook + User []ent.Hook + } + inters struct { + Api []ent.Interceptor + Card []ent.Interceptor + Comment []ent.Interceptor + FieldType []ent.Interceptor + File []ent.Interceptor + FileType []ent.Interceptor + Goods []ent.Interceptor + Group []ent.Interceptor + GroupInfo []ent.Interceptor + Item []ent.Interceptor + License []ent.Interceptor + Node []ent.Interceptor + Pet []ent.Interceptor + Spec []ent.Interceptor + Task []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/entc/integration/gremlin/ent/config.go b/entc/integration/gremlin/ent/config.go deleted file mode 100644 index 8c724437d..000000000 --- a/entc/integration/gremlin/ent/config.go +++ /dev/null @@ -1,100 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Api []ent.Hook - Card []ent.Hook - Comment []ent.Hook - FieldType []ent.Hook - File []ent.Hook - FileType []ent.Hook - Goods []ent.Hook - Group []ent.Hook - GroupInfo []ent.Hook - Item []ent.Hook - License []ent.Hook - Node []ent.Hook - Pet []ent.Hook - Spec []ent.Hook - Task []ent.Hook - User []ent.Hook - } - inters struct { - Api []ent.Interceptor - Card []ent.Interceptor - Comment []ent.Interceptor - FieldType []ent.Interceptor - File []ent.Interceptor - FileType []ent.Interceptor - Goods []ent.Interceptor - Group []ent.Interceptor - GroupInfo []ent.Interceptor - Item []ent.Interceptor - License []ent.Interceptor - Node []ent.Interceptor - Pet []ent.Interceptor - Spec []ent.Interceptor - Task []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/hooks/ent/client.go b/entc/integration/hooks/ent/client.go index ca0cbfd3a..507cbe34b 100644 --- a/entc/integration/hooks/ent/client.go +++ b/entc/integration/hooks/ent/client.go @@ -12,15 +12,15 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/hooks/ent/migrate" - "entgo.io/ent/entc/integration/hooks/ent/card" - "entgo.io/ent/entc/integration/hooks/ent/pet" - "entgo.io/ent/entc/integration/hooks/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entc/integration/hooks/ent/card" + "entgo.io/ent/entc/integration/hooks/ent/pet" + "entgo.io/ent/entc/integration/hooks/ent/user" ) // Client is the client that holds all ent builders. @@ -52,6 +52,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -617,3 +666,17 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Card []ent.Hook + Pet []ent.Hook + User []ent.Hook + } + inters struct { + Card []ent.Interceptor + Pet []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/entc/integration/hooks/ent/config.go b/entc/integration/hooks/ent/config.go deleted file mode 100644 index e47670013..000000000 --- a/entc/integration/hooks/ent/config.go +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Card []ent.Hook - Pet []ent.Hook - User []ent.Hook - } - inters struct { - Card []ent.Interceptor - Pet []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/idtype/ent/client.go b/entc/integration/idtype/ent/client.go index b22a3a16f..a05071a54 100644 --- a/entc/integration/idtype/ent/client.go +++ b/entc/integration/idtype/ent/client.go @@ -12,13 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/idtype/ent/migrate" - "entgo.io/ent/entc/integration/idtype/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entc/integration/idtype/ent/user" ) // Client is the client that holds all ent builders. @@ -44,6 +44,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -308,3 +357,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/entc/integration/idtype/ent/config.go b/entc/integration/idtype/ent/config.go deleted file mode 100644 index daad44de4..000000000 --- a/entc/integration/idtype/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/json/ent/client.go b/entc/integration/json/ent/client.go index 303fe3564..f42a7df93 100644 --- a/entc/integration/json/ent/client.go +++ b/entc/integration/json/ent/client.go @@ -12,12 +12,12 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/json/ent/migrate" - "entgo.io/ent/entc/integration/json/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/entc/integration/json/ent/user" ) // Client is the client that holds all ent builders. @@ -43,6 +43,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -259,3 +308,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/entc/integration/json/ent/config.go b/entc/integration/json/ent/config.go deleted file mode 100644 index daad44de4..000000000 --- a/entc/integration/json/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/migrate/entv1/client.go b/entc/integration/migrate/entv1/client.go index 16bd538d6..de71f1f19 100644 --- a/entc/integration/migrate/entv1/client.go +++ b/entc/integration/migrate/entv1/client.go @@ -12,16 +12,16 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/migrate/entv1/migrate" - "entgo.io/ent/entc/integration/migrate/entv1/car" - "entgo.io/ent/entc/integration/migrate/entv1/conversion" - "entgo.io/ent/entc/integration/migrate/entv1/customtype" - "entgo.io/ent/entc/integration/migrate/entv1/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entc/integration/migrate/entv1/car" + "entgo.io/ent/entc/integration/migrate/entv1/conversion" + "entgo.io/ent/entc/integration/migrate/entv1/customtype" + "entgo.io/ent/entc/integration/migrate/entv1/user" ) // Client is the client that holds all ent builders. @@ -56,6 +56,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -724,3 +773,19 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("entv1: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Car []ent.Hook + Conversion []ent.Hook + CustomType []ent.Hook + User []ent.Hook + } + inters struct { + Car []ent.Interceptor + Conversion []ent.Interceptor + CustomType []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/entc/integration/migrate/entv1/config.go b/entc/integration/migrate/entv1/config.go deleted file mode 100644 index 71a310baa..000000000 --- a/entc/integration/migrate/entv1/config.go +++ /dev/null @@ -1,76 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package entv1 - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Car []ent.Hook - Conversion []ent.Hook - CustomType []ent.Hook - User []ent.Hook - } - inters struct { - Car []ent.Interceptor - Conversion []ent.Interceptor - CustomType []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/migrate/entv2/client.go b/entc/integration/migrate/entv2/client.go index df8ddbc70..47316be19 100644 --- a/entc/integration/migrate/entv2/client.go +++ b/entc/integration/migrate/entv2/client.go @@ -12,8 +12,12 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/migrate/entv2/migrate" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/entc/integration/migrate/entv2/blog" "entgo.io/ent/entc/integration/migrate/entv2/car" "entgo.io/ent/entc/integration/migrate/entv2/conversion" @@ -23,10 +27,6 @@ import ( "entgo.io/ent/entc/integration/migrate/entv2/pet" "entgo.io/ent/entc/integration/migrate/entv2/user" "entgo.io/ent/entc/integration/migrate/entv2/zoo" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" ) // Client is the client that holds all ent builders. @@ -76,6 +76,55 @@ func (c *Client) init() { c.Zoo = NewZooClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -1380,3 +1429,29 @@ func (c *ZooClient) mutate(ctx context.Context, m *ZooMutation) (Value, error) { return nil, fmt.Errorf("entv2: unknown Zoo mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Blog []ent.Hook + Car []ent.Hook + Conversion []ent.Hook + CustomType []ent.Hook + Group []ent.Hook + Media []ent.Hook + Pet []ent.Hook + User []ent.Hook + Zoo []ent.Hook + } + inters struct { + Blog []ent.Interceptor + Car []ent.Interceptor + Conversion []ent.Interceptor + CustomType []ent.Interceptor + Group []ent.Interceptor + Media []ent.Interceptor + Pet []ent.Interceptor + User []ent.Interceptor + Zoo []ent.Interceptor + } +) diff --git a/entc/integration/migrate/entv2/config.go b/entc/integration/migrate/entv2/config.go deleted file mode 100644 index 6f09b3541..000000000 --- a/entc/integration/migrate/entv2/config.go +++ /dev/null @@ -1,86 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package entv2 - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Blog []ent.Hook - Car []ent.Hook - Conversion []ent.Hook - CustomType []ent.Hook - Group []ent.Hook - Media []ent.Hook - Pet []ent.Hook - User []ent.Hook - Zoo []ent.Hook - } - inters struct { - Blog []ent.Interceptor - Car []ent.Interceptor - Conversion []ent.Interceptor - CustomType []ent.Interceptor - Group []ent.Interceptor - Media []ent.Interceptor - Pet []ent.Interceptor - User []ent.Interceptor - Zoo []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/migrate/versioned/client.go b/entc/integration/migrate/versioned/client.go index 2208abba5..751572e9b 100644 --- a/entc/integration/migrate/versioned/client.go +++ b/entc/integration/migrate/versioned/client.go @@ -12,13 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/migrate/versioned/migrate" - "entgo.io/ent/entc/integration/migrate/versioned/group" - "entgo.io/ent/entc/integration/migrate/versioned/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/entc/integration/migrate/versioned/group" + "entgo.io/ent/entc/integration/migrate/versioned/user" ) // Client is the client that holds all ent builders. @@ -47,6 +47,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -387,3 +436,15 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("versioned: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Group []ent.Hook + User []ent.Hook + } + inters struct { + Group []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/entc/integration/migrate/versioned/config.go b/entc/integration/migrate/versioned/config.go deleted file mode 100644 index 763e05f87..000000000 --- a/entc/integration/migrate/versioned/config.go +++ /dev/null @@ -1,72 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package versioned - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Group []ent.Hook - User []ent.Hook - } - inters struct { - Group []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/entc/integration/multischema/ent/client.go b/entc/integration/multischema/ent/client.go index e309624d2..2072ba737 100644 --- a/entc/integration/multischema/ent/client.go +++ b/entc/integration/multischema/ent/client.go @@ -12,16 +12,18 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/multischema/ent/migrate" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/entc/integration/multischema/ent/friendship" "entgo.io/ent/entc/integration/multischema/ent/group" "entgo.io/ent/entc/integration/multischema/ent/pet" "entgo.io/ent/entc/integration/multischema/ent/user" - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entc/integration/multischema/ent/internal" ) // Client is the client that holds all ent builders. @@ -56,6 +58,57 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + // schemaConfig contains alternative names for all tables. + schemaConfig SchemaConfig + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -796,3 +849,37 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Friendship []ent.Hook + Group []ent.Hook + Pet []ent.Hook + User []ent.Hook + } + inters struct { + Friendship []ent.Interceptor + Group []ent.Interceptor + Pet []ent.Interceptor + User []ent.Interceptor + } +) + +// SchemaConfigFromContext exports the internal.SchemaConfigFromContext +// for external usage (inside custom predicates or modifiers). +func SchemaConfigFromContext(ctx context.Context) SchemaConfig { + return internal.SchemaConfigFromContext(ctx) +} + +// SchemaConfig represents alternative schema names for all tables +// that can be passed at runtime. +type SchemaConfig = internal.SchemaConfig + +// AlternateSchemas allows alternate schema names to be +// passed into ent operations. +func AlternateSchema(schemaConfig SchemaConfig) Option { + return func(c *config) { + c.schemaConfig = schemaConfig + } +} diff --git a/entc/integration/multischema/ent/config.go b/entc/integration/multischema/ent/config.go deleted file mode 100644 index 4b319ea6a..000000000 --- a/entc/integration/multischema/ent/config.go +++ /dev/null @@ -1,99 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent" - "entgo.io/ent/dialect" - "entgo.io/ent/entc/integration/multischema/ent/internal" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - // schemaConfig contains alternative names for all tables. - schemaConfig SchemaConfig -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Friendship []ent.Hook - Group []ent.Hook - Pet []ent.Hook - User []ent.Hook - } - inters struct { - Friendship []ent.Interceptor - Group []ent.Interceptor - Pet []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// SchemaConfigFromContext exports the internal.SchemaConfigFromContext -// for external usage (inside custom predicates or modifiers). -func SchemaConfigFromContext(ctx context.Context) SchemaConfig { - return internal.SchemaConfigFromContext(ctx) -} - -// SchemaConfig represents alternative schema names for all tables -// that can be passed at runtime. -type SchemaConfig = internal.SchemaConfig - -// AlternateSchemas allows alternate schema names to be -// passed into ent operations. -func AlternateSchema(schemaConfig SchemaConfig) Option { - return func(c *config) { - c.schemaConfig = schemaConfig - } -} diff --git a/entc/integration/privacy/ent/client.go b/entc/integration/privacy/ent/client.go index 40d637cc6..f230b2b41 100644 --- a/entc/integration/privacy/ent/client.go +++ b/entc/integration/privacy/ent/client.go @@ -12,15 +12,17 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/entc/integration/privacy/ent/migrate" - "entgo.io/ent/entc/integration/privacy/ent/task" - "entgo.io/ent/entc/integration/privacy/ent/team" - "entgo.io/ent/entc/integration/privacy/ent/user" + "net/http" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entc/integration/privacy/ent/task" + "entgo.io/ent/entc/integration/privacy/ent/team" + "entgo.io/ent/entc/integration/privacy/ent/user" ) // Client is the client that holds all ent builders. @@ -52,6 +54,63 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + HTTPClient *http.Client + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + +// HTTPClient configures the HTTPClient. +func HTTPClient(v *http.Client) Option { + return func(c *config) { + c.HTTPClient = v + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -615,3 +674,17 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Task []ent.Hook + Team []ent.Hook + User []ent.Hook + } + inters struct { + Task []ent.Interceptor + Team []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/entc/integration/privacy/ent/config.go b/entc/integration/privacy/ent/config.go deleted file mode 100644 index b6b3061fa..000000000 --- a/entc/integration/privacy/ent/config.go +++ /dev/null @@ -1,84 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "net/http" - - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - HTTPClient *http.Client -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Task []ent.Hook - Team []ent.Hook - User []ent.Hook - } - inters struct { - Task []ent.Interceptor - Team []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// HTTPClient configures the HTTPClient. -func HTTPClient(v *http.Client) Option { - return func(c *config) { - c.HTTPClient = v - } -} diff --git a/entc/integration/template/ent/client.go b/entc/integration/template/ent/client.go index 47aca182d..77f0e5aae 100644 --- a/entc/integration/template/ent/client.go +++ b/entc/integration/template/ent/client.go @@ -11,16 +11,17 @@ import ( "errors" "fmt" "log" + "net/http" + "entgo.io/ent" "entgo.io/ent/entc/integration/template/ent/migrate" - "entgo.io/ent/entc/integration/template/ent/group" - "entgo.io/ent/entc/integration/template/ent/pet" - "entgo.io/ent/entc/integration/template/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entc/integration/template/ent/group" + "entgo.io/ent/entc/integration/template/ent/pet" + "entgo.io/ent/entc/integration/template/ent/user" ) // Client is the client that holds all ent builders. @@ -61,6 +62,57 @@ func (c *Client) HiddenData() int { return c.extraHiddenField } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + // HTTPClient field added by a test template. + HTTPClient *http.Client + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -576,3 +628,24 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Group []ent.Hook + Pet []ent.Hook + User []ent.Hook + } + inters struct { + Group []ent.Interceptor + Pet []ent.Interceptor + User []ent.Interceptor + } +) + +// HTTPClient option added by a test template. +func HTTPClient(hc *http.Client) Option { + return func(c *config) { + c.HTTPClient = hc + } +} diff --git a/entc/integration/template/ent/config.go b/entc/integration/template/ent/config.go deleted file mode 100644 index aed1c1110..000000000 --- a/entc/integration/template/ent/config.go +++ /dev/null @@ -1,85 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "net/http" - - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - // HTTPClient field added by a test template. - HTTPClient *http.Client -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Group []ent.Hook - Pet []ent.Hook - User []ent.Hook - } - inters struct { - Group []ent.Interceptor - Pet []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// HTTPClient option added by a test template. -func HTTPClient(hc *http.Client) Option { - return func(c *config) { - c.HTTPClient = hc - } -} diff --git a/examples/edgeindex/ent/client.go b/examples/edgeindex/ent/client.go index b0a9f9e3e..456bc751f 100644 --- a/examples/edgeindex/ent/client.go +++ b/examples/edgeindex/ent/client.go @@ -12,14 +12,14 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/edgeindex/ent/migrate" - "entgo.io/ent/examples/edgeindex/ent/city" - "entgo.io/ent/examples/edgeindex/ent/street" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/edgeindex/ent/city" + "entgo.io/ent/examples/edgeindex/ent/street" ) // Client is the client that holds all ent builders. @@ -48,6 +48,55 @@ func (c *Client) init() { c.Street = NewStreetClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -420,3 +469,15 @@ func (c *StreetClient) mutate(ctx context.Context, m *StreetMutation) (Value, er return nil, fmt.Errorf("ent: unknown Street mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + City []ent.Hook + Street []ent.Hook + } + inters struct { + City []ent.Interceptor + Street []ent.Interceptor + } +) diff --git a/examples/edgeindex/ent/config.go b/examples/edgeindex/ent/config.go deleted file mode 100644 index b1c55f778..000000000 --- a/examples/edgeindex/ent/config.go +++ /dev/null @@ -1,72 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - City []ent.Hook - Street []ent.Hook - } - inters struct { - City []ent.Interceptor - Street []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/encryptfield/ent/client.go b/examples/encryptfield/ent/client.go index 148db9de9..e88b41468 100644 --- a/examples/encryptfield/ent/client.go +++ b/examples/encryptfield/ent/client.go @@ -12,12 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/encryptfield/ent/migrate" - "entgo.io/ent/examples/encryptfield/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/examples/encryptfield/ent/user" + "gocloud.dev/secrets" ) // Client is the client that holds all ent builders. @@ -43,6 +44,63 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + SecretsKeeper *secrets.Keeper + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + +// SecretsKeeper configures the SecretsKeeper. +func SecretsKeeper(v *secrets.Keeper) Option { + return func(c *config) { + c.SecretsKeeper = v + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -261,3 +319,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/examples/encryptfield/ent/config.go b/examples/encryptfield/ent/config.go deleted file mode 100644 index bf9edd6e7..000000000 --- a/examples/encryptfield/ent/config.go +++ /dev/null @@ -1,79 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" - "gocloud.dev/secrets" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - SecretsKeeper *secrets.Keeper -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// SecretsKeeper configures the SecretsKeeper. -func SecretsKeeper(v *secrets.Keeper) Option { - return func(c *config) { - c.SecretsKeeper = v - } -} diff --git a/examples/entcpkg/ent/client.go b/examples/entcpkg/ent/client.go index cb1d4b6f7..b5353a29b 100644 --- a/examples/entcpkg/ent/client.go +++ b/examples/entcpkg/ent/client.go @@ -12,12 +12,15 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/entcpkg/ent/migrate" - "entgo.io/ent/examples/entcpkg/ent/user" + "io" + "net/http" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/examples/entcpkg/ent/user" ) // Client is the client that holds all ent builders. @@ -43,6 +46,71 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + HTTPClient *http.Client + Writer io.Writer + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + +// HTTPClient configures the HTTPClient. +func HTTPClient(v *http.Client) Option { + return func(c *config) { + c.HTTPClient = v + } +} + +// Writer configures the Writer. +func Writer(v io.Writer) Option { + return func(c *config) { + c.Writer = v + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -259,3 +327,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/examples/entcpkg/ent/config.go b/examples/entcpkg/ent/config.go deleted file mode 100644 index 20f4ec298..000000000 --- a/examples/entcpkg/ent/config.go +++ /dev/null @@ -1,89 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "io" - "net/http" - - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - HTTPClient *http.Client - Writer io.Writer -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// HTTPClient configures the HTTPClient. -func HTTPClient(v *http.Client) Option { - return func(c *config) { - c.HTTPClient = v - } -} - -// Writer configures the Writer. -func Writer(v io.Writer) Option { - return func(c *config) { - c.Writer = v - } -} diff --git a/examples/fs/ent/client.go b/examples/fs/ent/client.go index 289048822..862df9ba4 100644 --- a/examples/fs/ent/client.go +++ b/examples/fs/ent/client.go @@ -12,13 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/fs/ent/migrate" - "entgo.io/ent/examples/fs/ent/file" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/fs/ent/file" ) // Client is the client that holds all ent builders. @@ -44,6 +44,55 @@ func (c *Client) init() { c.File = NewFileClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -292,3 +341,13 @@ func (c *FileClient) mutate(ctx context.Context, m *FileMutation) (Value, error) return nil, fmt.Errorf("ent: unknown File mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + File []ent.Hook + } + inters struct { + File []ent.Interceptor + } +) diff --git a/examples/fs/ent/config.go b/examples/fs/ent/config.go deleted file mode 100644 index f9084639c..000000000 --- a/examples/fs/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - File []ent.Hook - } - inters struct { - File []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/jsonencode/ent/client.go b/examples/jsonencode/ent/client.go index af20e1bd2..75f607a8a 100644 --- a/examples/jsonencode/ent/client.go +++ b/examples/jsonencode/ent/client.go @@ -12,15 +12,15 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/jsonencode/ent/migrate" - "entgo.io/ent/examples/jsonencode/ent/card" - "entgo.io/ent/examples/jsonencode/ent/pet" - "entgo.io/ent/examples/jsonencode/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/jsonencode/ent/card" + "entgo.io/ent/examples/jsonencode/ent/pet" + "entgo.io/ent/examples/jsonencode/ent/user" ) // Client is the client that holds all ent builders. @@ -52,6 +52,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -548,3 +597,17 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Card []ent.Hook + Pet []ent.Hook + User []ent.Hook + } + inters struct { + Card []ent.Interceptor + Pet []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/examples/jsonencode/ent/config.go b/examples/jsonencode/ent/config.go deleted file mode 100644 index e47670013..000000000 --- a/examples/jsonencode/ent/config.go +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Card []ent.Hook - Pet []ent.Hook - User []ent.Hook - } - inters struct { - Card []ent.Interceptor - Pet []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/m2m2types/ent/client.go b/examples/m2m2types/ent/client.go index 32b662601..a0e6ae1ed 100644 --- a/examples/m2m2types/ent/client.go +++ b/examples/m2m2types/ent/client.go @@ -12,14 +12,14 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/m2m2types/ent/migrate" - "entgo.io/ent/examples/m2m2types/ent/group" - "entgo.io/ent/examples/m2m2types/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/m2m2types/ent/group" + "entgo.io/ent/examples/m2m2types/ent/user" ) // Client is the client that holds all ent builders. @@ -48,6 +48,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -420,3 +469,15 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Group []ent.Hook + User []ent.Hook + } + inters struct { + Group []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/examples/m2m2types/ent/config.go b/examples/m2m2types/ent/config.go deleted file mode 100644 index 7f30b10c1..000000000 --- a/examples/m2m2types/ent/config.go +++ /dev/null @@ -1,72 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Group []ent.Hook - User []ent.Hook - } - inters struct { - Group []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/m2mbidi/ent/client.go b/examples/m2mbidi/ent/client.go index e437c38e1..9e509415f 100644 --- a/examples/m2mbidi/ent/client.go +++ b/examples/m2mbidi/ent/client.go @@ -12,13 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/m2mbidi/ent/migrate" - "entgo.io/ent/examples/m2mbidi/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/m2mbidi/ent/user" ) // Client is the client that holds all ent builders. @@ -44,6 +44,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -276,3 +325,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/examples/m2mbidi/ent/config.go b/examples/m2mbidi/ent/config.go deleted file mode 100644 index daad44de4..000000000 --- a/examples/m2mbidi/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/m2mrecur/ent/client.go b/examples/m2mrecur/ent/client.go index 186315bc4..eddc86158 100644 --- a/examples/m2mrecur/ent/client.go +++ b/examples/m2mrecur/ent/client.go @@ -12,13 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/m2mrecur/ent/migrate" - "entgo.io/ent/examples/m2mrecur/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/m2mrecur/ent/user" ) // Client is the client that holds all ent builders. @@ -44,6 +44,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -292,3 +341,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/examples/m2mrecur/ent/config.go b/examples/m2mrecur/ent/config.go deleted file mode 100644 index daad44de4..000000000 --- a/examples/m2mrecur/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/migration/ent/client.go b/examples/migration/ent/client.go index ebd0ee1a4..36b3da9a4 100644 --- a/examples/migration/ent/client.go +++ b/examples/migration/ent/client.go @@ -12,16 +12,16 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/migration/ent/migrate" "github.com/google/uuid" - "entgo.io/ent/examples/migration/ent/card" - "entgo.io/ent/examples/migration/ent/pet" - "entgo.io/ent/examples/migration/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/migration/ent/card" + "entgo.io/ent/examples/migration/ent/pet" + "entgo.io/ent/examples/migration/ent/user" ) // Client is the client that holds all ent builders. @@ -53,6 +53,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -581,3 +630,17 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Card []ent.Hook + Pet []ent.Hook + User []ent.Hook + } + inters struct { + Card []ent.Interceptor + Pet []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/examples/migration/ent/config.go b/examples/migration/ent/config.go deleted file mode 100644 index e47670013..000000000 --- a/examples/migration/ent/config.go +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Card []ent.Hook - Pet []ent.Hook - User []ent.Hook - } - inters struct { - Card []ent.Interceptor - Pet []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/o2m2types/ent/client.go b/examples/o2m2types/ent/client.go index 6a5814a74..3fbf555d3 100644 --- a/examples/o2m2types/ent/client.go +++ b/examples/o2m2types/ent/client.go @@ -12,14 +12,14 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/o2m2types/ent/migrate" - "entgo.io/ent/examples/o2m2types/ent/pet" - "entgo.io/ent/examples/o2m2types/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/o2m2types/ent/pet" + "entgo.io/ent/examples/o2m2types/ent/user" ) // Client is the client that holds all ent builders. @@ -48,6 +48,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -420,3 +469,15 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Pet []ent.Hook + User []ent.Hook + } + inters struct { + Pet []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/examples/o2m2types/ent/config.go b/examples/o2m2types/ent/config.go deleted file mode 100644 index aedf548be..000000000 --- a/examples/o2m2types/ent/config.go +++ /dev/null @@ -1,72 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Pet []ent.Hook - User []ent.Hook - } - inters struct { - Pet []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/o2mrecur/ent/client.go b/examples/o2mrecur/ent/client.go index dcc4398fe..224dc4d91 100644 --- a/examples/o2mrecur/ent/client.go +++ b/examples/o2mrecur/ent/client.go @@ -12,13 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/o2mrecur/ent/migrate" - "entgo.io/ent/examples/o2mrecur/ent/node" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/o2mrecur/ent/node" ) // Client is the client that holds all ent builders. @@ -44,6 +44,55 @@ func (c *Client) init() { c.Node = NewNodeClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -292,3 +341,13 @@ func (c *NodeClient) mutate(ctx context.Context, m *NodeMutation) (Value, error) return nil, fmt.Errorf("ent: unknown Node mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Node []ent.Hook + } + inters struct { + Node []ent.Interceptor + } +) diff --git a/examples/o2mrecur/ent/config.go b/examples/o2mrecur/ent/config.go deleted file mode 100644 index e9947206c..000000000 --- a/examples/o2mrecur/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Node []ent.Hook - } - inters struct { - Node []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/o2o2types/ent/client.go b/examples/o2o2types/ent/client.go index 4068ff7c7..3f33bf2d1 100644 --- a/examples/o2o2types/ent/client.go +++ b/examples/o2o2types/ent/client.go @@ -12,14 +12,14 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/o2o2types/ent/migrate" - "entgo.io/ent/examples/o2o2types/ent/card" - "entgo.io/ent/examples/o2o2types/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/o2o2types/ent/card" + "entgo.io/ent/examples/o2o2types/ent/user" ) // Client is the client that holds all ent builders. @@ -48,6 +48,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -420,3 +469,15 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Card []ent.Hook + User []ent.Hook + } + inters struct { + Card []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/examples/o2o2types/ent/config.go b/examples/o2o2types/ent/config.go deleted file mode 100644 index cf1e1cdc4..000000000 --- a/examples/o2o2types/ent/config.go +++ /dev/null @@ -1,72 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Card []ent.Hook - User []ent.Hook - } - inters struct { - Card []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/o2obidi/ent/client.go b/examples/o2obidi/ent/client.go index 3e94bea60..e40653a49 100644 --- a/examples/o2obidi/ent/client.go +++ b/examples/o2obidi/ent/client.go @@ -12,13 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/o2obidi/ent/migrate" - "entgo.io/ent/examples/o2obidi/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/o2obidi/ent/user" ) // Client is the client that holds all ent builders. @@ -44,6 +44,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -276,3 +325,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/examples/o2obidi/ent/config.go b/examples/o2obidi/ent/config.go deleted file mode 100644 index daad44de4..000000000 --- a/examples/o2obidi/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/o2orecur/ent/client.go b/examples/o2orecur/ent/client.go index c6fda58ee..69e63dc10 100644 --- a/examples/o2orecur/ent/client.go +++ b/examples/o2orecur/ent/client.go @@ -12,13 +12,13 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/o2orecur/ent/migrate" - "entgo.io/ent/examples/o2orecur/ent/node" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/o2orecur/ent/node" ) // Client is the client that holds all ent builders. @@ -44,6 +44,55 @@ func (c *Client) init() { c.Node = NewNodeClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -292,3 +341,13 @@ func (c *NodeClient) mutate(ctx context.Context, m *NodeMutation) (Value, error) return nil, fmt.Errorf("ent: unknown Node mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Node []ent.Hook + } + inters struct { + Node []ent.Interceptor + } +) diff --git a/examples/o2orecur/ent/config.go b/examples/o2orecur/ent/config.go deleted file mode 100644 index e9947206c..000000000 --- a/examples/o2orecur/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Node []ent.Hook - } - inters struct { - Node []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/privacyadmin/ent/client.go b/examples/privacyadmin/ent/client.go index 0e0462c72..34fdfda35 100644 --- a/examples/privacyadmin/ent/client.go +++ b/examples/privacyadmin/ent/client.go @@ -12,12 +12,12 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/privacyadmin/ent/migrate" - "entgo.io/ent/examples/privacyadmin/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/examples/privacyadmin/ent/user" ) // Client is the client that holds all ent builders. @@ -43,6 +43,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -260,3 +309,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/examples/privacyadmin/ent/config.go b/examples/privacyadmin/ent/config.go deleted file mode 100644 index daad44de4..000000000 --- a/examples/privacyadmin/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/privacytenant/ent/client.go b/examples/privacytenant/ent/client.go index fd684da94..36c59debf 100644 --- a/examples/privacytenant/ent/client.go +++ b/examples/privacytenant/ent/client.go @@ -12,15 +12,15 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/privacytenant/ent/migrate" - "entgo.io/ent/examples/privacytenant/ent/group" - "entgo.io/ent/examples/privacytenant/ent/tenant" - "entgo.io/ent/examples/privacytenant/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/privacytenant/ent/group" + "entgo.io/ent/examples/privacytenant/ent/tenant" + "entgo.io/ent/examples/privacytenant/ent/user" ) // Client is the client that holds all ent builders. @@ -52,6 +52,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -583,3 +632,17 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Group []ent.Hook + Tenant []ent.Hook + User []ent.Hook + } + inters struct { + Group []ent.Interceptor + Tenant []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/examples/privacytenant/ent/config.go b/examples/privacytenant/ent/config.go deleted file mode 100644 index 4e98a3da7..000000000 --- a/examples/privacytenant/ent/config.go +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Group []ent.Hook - Tenant []ent.Hook - User []ent.Hook - } - inters struct { - Group []ent.Interceptor - Tenant []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/start/ent/client.go b/examples/start/ent/client.go index 647757acb..2a986cb31 100644 --- a/examples/start/ent/client.go +++ b/examples/start/ent/client.go @@ -12,15 +12,15 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/start/ent/migrate" - "entgo.io/ent/examples/start/ent/car" - "entgo.io/ent/examples/start/ent/group" - "entgo.io/ent/examples/start/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/start/ent/car" + "entgo.io/ent/examples/start/ent/group" + "entgo.io/ent/examples/start/ent/user" ) // Client is the client that holds all ent builders. @@ -52,6 +52,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -580,3 +629,17 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Car []ent.Hook + Group []ent.Hook + User []ent.Hook + } + inters struct { + Car []ent.Interceptor + Group []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/examples/start/ent/config.go b/examples/start/ent/config.go deleted file mode 100644 index 570bc43d0..000000000 --- a/examples/start/ent/config.go +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Car []ent.Hook - Group []ent.Hook - User []ent.Hook - } - inters struct { - Car []ent.Interceptor - Group []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/traversal/ent/client.go b/examples/traversal/ent/client.go index 4a1b95ce9..6e4270bba 100644 --- a/examples/traversal/ent/client.go +++ b/examples/traversal/ent/client.go @@ -12,15 +12,15 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/traversal/ent/migrate" - "entgo.io/ent/examples/traversal/ent/group" - "entgo.io/ent/examples/traversal/ent/pet" - "entgo.io/ent/examples/traversal/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/examples/traversal/ent/group" + "entgo.io/ent/examples/traversal/ent/pet" + "entgo.io/ent/examples/traversal/ent/user" ) // Client is the client that holds all ent builders. @@ -52,6 +52,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -644,3 +693,17 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Group []ent.Hook + Pet []ent.Hook + User []ent.Hook + } + inters struct { + Group []ent.Interceptor + Pet []ent.Interceptor + User []ent.Interceptor + } +) diff --git a/examples/traversal/ent/config.go b/examples/traversal/ent/config.go deleted file mode 100644 index 5ef71b95c..000000000 --- a/examples/traversal/ent/config.go +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Group []ent.Hook - Pet []ent.Hook - User []ent.Hook - } - inters struct { - Group []ent.Interceptor - Pet []ent.Interceptor - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/version/ent/client.go b/examples/version/ent/client.go index 244aa0d61..6a5ad150f 100644 --- a/examples/version/ent/client.go +++ b/examples/version/ent/client.go @@ -12,12 +12,12 @@ import ( "fmt" "log" + "entgo.io/ent" "entgo.io/ent/examples/version/ent/migrate" - "entgo.io/ent/examples/version/ent/user" - "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/examples/version/ent/user" ) // Client is the client that holds all ent builders. @@ -43,6 +43,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -259,3 +308,13 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + User []ent.Hook + } + inters struct { + User []ent.Interceptor + } +) diff --git a/examples/version/ent/config.go b/examples/version/ent/config.go deleted file mode 100644 index daad44de4..000000000 --- a/examples/version/ent/config.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - User []ent.Hook - } - inters struct { - User []ent.Interceptor - } -) - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -}