get.go 1.72 KB
Newer Older
Vladimir Barsukov's avatar
Vladimir Barsukov committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package zdb

import "github.com/georgysavva/scany/v2/pgxscan"

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(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(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(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(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(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()

	return d.execWrapper(ConnModeAsync, dst, func(q *Conn, dst1 any) error {
		return d.qGet(q, dst1, 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...)
}