# HG changeset patch # User Christophe de Vienne <christophe@cdevienne.info> # Date 1618003756 -7200 # Fri Apr 09 23:29:16 2021 +0200 # Node ID 547b573df49e906a16805dd94468ea5db5084c84 # Parent fa4e7de857924acebccd3fa32dbd4c08328b2984 SQLHelper: add 'raw' versions of the main functions diff --git a/database/sql_helper.go b/database/sql_helper.go --- a/database/sql_helper.go +++ b/database/sql_helper.go @@ -26,6 +26,11 @@ return GetContext(h.ctx, h.sqle, obj, query, &h.log) } +func (h *SQLHelper) GetRaw(obj interface{}, sql string, args ...interface{}) error { + SQLTrace(&h.log, sql, args) + return h.sqle.GetContext(h.ctx, obj, sql, args...) +} + // GetByPKey loads a mapped structure func (h *SQLHelper) GetByPKey(obj Mapped, value interface{}) error { return h.GetBy(obj, obj.PKeyColumn(), value) @@ -51,16 +56,32 @@ return SelectContext(h.ctx, h.sqle, obj, query, &h.log) } +func (h *SQLHelper) SelectRaw(obj interface{}, sql string, args ...interface{}) error { + SQLTrace(&h.log, sql, args) + return h.sqle.SelectContext(h.ctx, obj, sql, args...) +} + // Exec executes a query func (h *SQLHelper) Exec(query sq.Sqlizer) (sql.Result, error) { return ExecContext(h.ctx, h.sqle, query, &h.log) } +func (h *SQLHelper) ExecRaw(sql string, args ...interface{}) (sql.Result, error) { + SQLTrace(&h.log, sql, args) + return h.sqle.ExecContext(h.ctx, sql, args...) +} + // Query executes a query func (h *SQLHelper) Query(query sq.Sqlizer) (*sqlx.Rows, error) { return QueryContext(h.ctx, h.sqle, query, &h.log) } +// QueryRaw executes a raw SQL query +func (h *SQLHelper) QueryRaw(sql string, args ...interface{}) (*sqlx.Rows, error) { + SQLTrace(&h.log, sql, args) + return h.sqle.QueryxContext(h.ctx, sql, args...) +} + // Insert inserts a Mapped into the db func (h *SQLHelper) Insert(instances ...Mapped) (sql.Result, error) { query := SQLInsert(instances...)