mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
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:
committed by
Facebook Github Bot
parent
e7fec6f8f9
commit
dc542e46ae
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user