Last active
September 8, 2020 23:19
-
-
Save jamesgarfield/48304aab09499f66b423132347a49099 to your computer and use it in GitHub Desktop.
Example of InlineSQLArgs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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