entc/gen: add debug option to client

Summary:
It's possible to execute:
```
client.Debug().T.Query().AllX(ctx)
``

Reviewed By: alexsn

Differential Revision: D17092159

fbshipit-source-id: 6d1c56e8e45cfd8e36b2700c9d450f2bd5f66a71
This commit is contained in:
Ariel Mashraki
2019-08-28 07:22:25 -07:00
committed by Facebook Github Bot
parent e7fec6f8f9
commit dc542e46ae
17 changed files with 284 additions and 20 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/facebookincubator/ent/examples/o2o2types/ent/card"
"github.com/facebookincubator/ent/examples/o2o2types/ent/user"
"github.com/facebookincubator/ent/dialect"
"github.com/facebookincubator/ent/dialect/sql"
)
@@ -55,6 +56,26 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
}, nil
}
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// Card.
// Query().
// Count(ctx)
//
func (c *Client) Debug() *Client {
if c.debug {
return c
}
cfg := config{driver: dialect.Debug(c.driver, c.log), log: c.log, debug: true}
return &Client{
config: cfg,
Schema: migrate.NewSchema(cfg.driver),
Card: NewCardClient(cfg),
User: NewUserClient(cfg),
}
}
// CardClient is a client for the Card schema.
type CardClient struct {
config