Skip to content

Instantly share code, notes, and snippets.

@jamesgarfield
Last active September 8, 2020 23:19
Show Gist options
  • Save jamesgarfield/48304aab09499f66b423132347a49099 to your computer and use it in GitHub Desktop.
Save jamesgarfield/48304aab09499f66b423132347a49099 to your computer and use it in GitHub Desktop.
Example of InlineSQLArgs
func (dqb *QueryBox) ExecAndSelect(ctx context.Context, output interface{}, ds DS, params interface{}, tmplName ...string) error {
if dqb.ReadTmplBox == nil {
return errors.WithStack(errNoBoxFound)
}
panicWhenNotSlice(output)
query, vals, err := execDefaultTemplates(dqb.ReadTmplBox, params, tmplName...)
if err != nil {
return err
}
if sql, err := DebugInlineSQLArgs(query, vals); err == nil {
if f, err := ioutil.TempFile("", tmplName[0]); err == nil {
log.Infof(ctx, "inlinesql: Writing SQL to: %s", f.Name())
_, _ = f.WriteString(sql)
} else {
log.Warningf(ctx, "inlinesql: could not open temp file: %v", err)
}
} else {
log.Warningf(ctx, "inlinesql: could not inline sql: %+v", err)
}
return selectAll(WithQueryTimingFilesInfo(ctx, dqb.DB, tmplName...), output, ds, query, vals...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment