github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/config.go (about)

     1  // Code generated by ent, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"context"
     7  	stdsql "database/sql"
     8  	"fmt"
     9  
    10  	"entgo.io/ent"
    11  	"entgo.io/ent/dialect"
    12  )
    13  
    14  // Option function to configure the client.
    15  type Option func(*config)
    16  
    17  // Config is the configuration for the client and its builder.
    18  type config struct {
    19  	// driver used for executing database requests.
    20  	driver dialect.Driver
    21  	// debug enable a debug logging.
    22  	debug bool
    23  	// log used for logging on debug mode.
    24  	log func(...interface{})
    25  	// hooks to execute on mutations.
    26  	hooks *hooks
    27  }
    28  
    29  // hooks per client, for fast access.
    30  type hooks struct {
    31  	AppCoin                 []ent.Hook
    32  	ChainBase               []ent.Hook
    33  	CoinBase                []ent.Hook
    34  	CoinDescription         []ent.Hook
    35  	CoinExtra               []ent.Hook
    36  	CoinFiat                []ent.Hook
    37  	CoinFiatCurrency        []ent.Hook
    38  	CoinFiatCurrencyHistory []ent.Hook
    39  	CoinUsedFor             []ent.Hook
    40  	Currency                []ent.Hook
    41  	CurrencyFeed            []ent.Hook
    42  	CurrencyHistory         []ent.Hook
    43  	ExchangeRate            []ent.Hook
    44  	Fiat                    []ent.Hook
    45  	FiatCurrency            []ent.Hook
    46  	FiatCurrencyFeed        []ent.Hook
    47  	FiatCurrencyHistory     []ent.Hook
    48  	Setting                 []ent.Hook
    49  	Tran                    []ent.Hook
    50  }
    51  
    52  // Options applies the options on the config object.
    53  func (c *config) options(opts ...Option) {
    54  	for _, opt := range opts {
    55  		opt(c)
    56  	}
    57  	if c.debug {
    58  		c.driver = dialect.Debug(c.driver, c.log)
    59  	}
    60  }
    61  
    62  // Debug enables debug logging on the ent.Driver.
    63  func Debug() Option {
    64  	return func(c *config) {
    65  		c.debug = true
    66  	}
    67  }
    68  
    69  // Log sets the logging function for debug mode.
    70  func Log(fn func(...interface{})) Option {
    71  	return func(c *config) {
    72  		c.log = fn
    73  	}
    74  }
    75  
    76  // Driver configures the client driver.
    77  func Driver(driver dialect.Driver) Option {
    78  	return func(c *config) {
    79  		c.driver = driver
    80  	}
    81  }
    82  
    83  // ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
    84  // See, database/sql#DB.ExecContext for more information.
    85  func (c *config) ExecContext(ctx context.Context, query string, args ...interface{}) (stdsql.Result, error) {
    86  	ex, ok := c.driver.(interface {
    87  		ExecContext(context.Context, string, ...interface{}) (stdsql.Result, error)
    88  	})
    89  	if !ok {
    90  		return nil, fmt.Errorf("Driver.ExecContext is not supported")
    91  	}
    92  	return ex.ExecContext(ctx, query, args...)
    93  }
    94  
    95  // QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
    96  // See, database/sql#DB.QueryContext for more information.
    97  func (c *config) QueryContext(ctx context.Context, query string, args ...interface{}) (*stdsql.Rows, error) {
    98  	q, ok := c.driver.(interface {
    99  		QueryContext(context.Context, string, ...interface{}) (*stdsql.Rows, error)
   100  	})
   101  	if !ok {
   102  		return nil, fmt.Errorf("Driver.QueryContext is not supported")
   103  	}
   104  	return q.QueryContext(ctx, query, args...)
   105  }