github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/config.go (about)

     1  // Code generated by entc, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"entgo.io/ent"
     7  	"entgo.io/ent/dialect"
     8  )
     9  
    10  // Option function to configure the client.
    11  type Option func(*config)
    12  
    13  // Config is the configuration for the client and its builder.
    14  type config struct {
    15  	// driver used for executing database requests.
    16  	driver dialect.Driver
    17  	// debug enable a debug logging.
    18  	debug bool
    19  	// log used for logging on debug mode.
    20  	log func(...interface{})
    21  	// hooks to execute on mutations.
    22  	hooks *hooks
    23  }
    24  
    25  // hooks per client, for fast access.
    26  type hooks struct {
    27  	Comment    []ent.Hook
    28  	File       []ent.Hook
    29  	Page       []ent.Hook
    30  	Permission []ent.Hook
    31  	Post       []ent.Hook
    32  	Role       []ent.Hook
    33  	Setting    []ent.Hook
    34  	Topic      []ent.Hook
    35  	User       []ent.Hook
    36  }
    37  
    38  // Options applies the options on the config object.
    39  func (c *config) options(opts ...Option) {
    40  	for _, opt := range opts {
    41  		opt(c)
    42  	}
    43  	if c.debug {
    44  		c.driver = dialect.Debug(c.driver, c.log)
    45  	}
    46  }
    47  
    48  // Debug enables debug logging on the ent.Driver.
    49  func Debug() Option {
    50  	return func(c *config) {
    51  		c.debug = true
    52  	}
    53  }
    54  
    55  // Log sets the logging function for debug mode.
    56  func Log(fn func(...interface{})) Option {
    57  	return func(c *config) {
    58  		c.log = fn
    59  	}
    60  }
    61  
    62  // Driver configures the client driver.
    63  func Driver(driver dialect.Driver) Option {
    64  	return func(c *config) {
    65  		c.driver = driver
    66  	}
    67  }