config.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "github.com/facebookincubator/ent"
  5. "github.com/facebookincubator/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. Car []ent.Hook
  23. Group []ent.Hook
  24. User []ent.Hook
  25. }
  26. // Options applies the options on the config object.
  27. func (c *config) options(opts ...Option) {
  28. for _, opt := range opts {
  29. opt(c)
  30. }
  31. if c.debug {
  32. c.driver = dialect.Debug(c.driver, c.log)
  33. }
  34. }
  35. // Debug enables debug logging on the ent.Driver.
  36. func Debug() Option {
  37. return func(c *config) {
  38. c.debug = true
  39. }
  40. }
  41. // Log sets the logging function for debug mode.
  42. func Log(fn func(...interface{})) Option {
  43. return func(c *config) {
  44. c.log = fn
  45. }
  46. }
  47. // Driver configures the client driver.
  48. func Driver(driver dialect.Driver) Option {
  49. return func(c *config) {
  50. c.driver = driver
  51. }
  52. }