Skip to content

Commit

Permalink
refactor(builder): extract exec method (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen authored Dec 2, 2020
1 parent a46052e commit 22b80ca
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions generator/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,27 @@ func (q Query) buildFields(list bool, wrapList bool, fields []Field) string {
return builder.String()
}

func (q Query) Exec(ctx context.Context, v interface{}) error {
func (q Query) Exec(ctx context.Context, into interface{}) error {
payload := engine.GQLRequest{
Query: q.Build(),
Variables: map[string]interface{}{},
}
return q.exec(ctx, payload, into)
}

func (q Query) exec(ctx context.Context, payload interface{}, into interface{}) error {
if q.Engine == nil {
panic("client.Connect() needs to be called before sending queries")
}

query := q.Build()

// TODO use specific log level
if logger.Enabled {
logger.Debug.Printf("prisma query: `%q`", query)
logger.Debug.Printf("prisma engine payload: `%+v`", payload)
}

logger.Debug.Printf("[timing] building %q", time.Since(q.Start))

payload := engine.GQLRequest{
Query: query,
Variables: map[string]interface{}{},
}
err := q.Engine.Do(ctx, payload, v)
err := q.Engine.Do(ctx, payload, into)
now := time.Now()
totalDuration := now.Sub(q.Start)
logger.Debug.Printf("[timing] TOTAL %q", totalDuration)
Expand Down

0 comments on commit 22b80ca

Please sign in to comment.