config.go 1.1 KB

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