Commit 50b3df83 authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

save

parent f6f60155
Pipeline #38 canceled with stages
package zdb
func (d *Pool) QExec(q *conn, sql string, args ...any) error {
_, err := q.Exec(d.ctx, sql, args...)
return err
func (d *Pool) WExec(sql string, args ...any) error {
return d.qExec(d.srvMaster, sql, args...)
}
func (d *Pool) WExecNamed(sql string, args map[string]any) error {
return d.qExec(d.srvMaster, d.prepare(sql, args))
}
func (d *Pool) WExecOpts(opts Opts) error {
sql, args := opts.Opts()
func (d *Pool) WExec(sql string, args ...any) error {
return d.QExec(d.srvMaster, sql, args...)
return d.qExec(d.srvMaster, d.prepare(sql, args))
}
func (d *Pool) WExecNamed(sql string, args map[string]any) error {
return d.QExec(d.srvMaster, d.prepare(sql, args))
func (d *Pool) qExec(q *conn, sql string, args ...any) error {
_, err := q.Exec(d.ctx, sql, args...)
return err
}
......@@ -2,46 +2,54 @@ package zdb
import "github.com/georgysavva/scany/v2/pgxscan"
func (d *Pool) QGet(q pgxscan.Querier, dst any, sql string, args ...any) error {
return pgxscan.Get(d.ctx, q, dst, sql, args...)
func (d *Pool) WGet(dst any, sql string, args ...any) error {
return d.qGet(d.srvMaster, dst, sql, args...)
}
func (d *Pool) WGetNamed(dst any, sql string, args map[string]any) error {
return d.qGet(d.srvMaster, dst, d.prepare(sql, args))
}
func (d *Pool) WGetOpts(dst any, opts Opts) error {
sql, args := opts.Opts()
return d.qGet(d.srvMaster, dst, d.prepare(sql, args))
}
func (d *Pool) Get(dst any, sql string, args ...any) error {
return d.execWrapper(ConnModeSync, dst, func(conn *conn, dst1 any) error {
return d.QGet(conn, dst1, sql, args...)
return d.execWrapper(ConnModeSync, dst, func(q *conn, dst1 any) error {
return d.qGet(q, dst1, sql, args...)
})
}
func (d *Pool) GetNamed(dst any, sql string, args map[string]any) error {
return d.execWrapper(ConnModeSync, dst, func(conn *conn, dst1 any) error {
return d.QGet(conn, dst1, d.prepare(sql, args))
return d.execWrapper(ConnModeSync, dst, func(q *conn, dst1 any) error {
return d.qGet(q, dst1, d.prepare(sql, args))
})
}
func (d *Pool) GetOpts(dst any, opts Opts) error {
sql, args := opts.Opts()
return d.execWrapper(ConnModeSync, dst, func(conn *conn, dst1 any) error {
return d.QGet(conn, dst1, d.prepare(sql, args))
return d.execWrapper(ConnModeSync, dst, func(q *conn, dst1 any) error {
return d.qGet(q, dst1, d.prepare(sql, args))
})
}
func (d *Pool) GetAsync(dst any, sql string, args ...any) error {
return d.execWrapper(ConnModeAsync, dst, func(conn *conn, dst1 any) error {
return d.QGet(conn, dst1, sql, args...)
return d.execWrapper(ConnModeAsync, dst, func(q *conn, dst1 any) error {
return d.qGet(q, dst1, sql, args...)
})
}
func (d *Pool) GetAsyncNamed(dst any, sql string, args map[string]any) error {
return d.execWrapper(ConnModeAsync, dst, func(conn *conn, dst1 any) error {
return d.QGet(conn, dst1, d.prepare(sql, args))
return d.execWrapper(ConnModeAsync, dst, func(q *conn, dst1 any) error {
return d.qGet(q, dst1, d.prepare(sql, args))
})
}
func (d *Pool) GetAsyncOpts(dst any, opts Opts) error {
sql, args := opts.Opts()
func (d *Pool) WGet(dst any, sql string, args ...any) error {
return d.QGet(d.srvMaster, dst, sql, args...)
return d.execWrapper(ConnModeAsync, dst, func(q *conn, dst1 any) error {
return d.qGet(q, dst1, d.prepare(sql, args))
})
}
func (d *Pool) WGetNamed(dst any, sql string, args map[string]any) error {
return d.QGet(d.srvMaster, dst, d.prepare(sql, args))
func (d *Pool) qGet(q pgxscan.Querier, dst any, sql string, args ...any) error {
return pgxscan.Get(d.ctx, q, dst, sql, args...)
}
......@@ -139,7 +139,7 @@ func (d *Pool) execWrapper(pool connMode, dst any, f func(conn *conn, dst1 any)
func (d *Pool) testConn(q *conn) (err error) {
var n any
if err = d.QGet(q, &n, "SELECT 1"); err != nil {
if err = d.qGet(q, &n, "SELECT 1"); err != nil {
d.logger.Printf("DB_TEST_CONN_ERR: MODE: %v, HOST: %s, PORT: %d, ERR: %v",
q.Mode.String(),
q.Config().ConnConfig.Host,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment