Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladimir Barsukov
zGo
Commits
5b2da0e8
Commit
5b2da0e8
authored
Nov 19, 2023
by
Vladimir Barsukov
Browse files
fix
parent
f8faa7da
Changes
2
Hide whitespace changes
Inline
Side-by-side
zdb/any.go
View file @
5b2da0e8
...
...
@@ -6,7 +6,6 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"reflect"
"time"
)
func
(
d
*
Pool
)
WAny
(
dst
any
,
sql
string
,
args
...
any
)
error
{
...
...
@@ -55,8 +54,6 @@ func (d *Pool) qAny(q *Conn, dst any, sql string, args ...any) error {
}
else
if
f
.
DataTypeOID
==
pgtype
.
NumericOID
{
ff
,
_
:=
v
[
i
]
.
(
pgtype
.
Numeric
)
.
Float64Value
()
r
[
f
.
Name
]
=
ff
.
Float64
}
else
if
f
.
DataTypeOID
==
pgtype
.
TimestampOID
&&
!
d
.
UseGoTime
{
r
[
f
.
Name
]
=
v
[
i
]
.
(
time
.
Time
)
.
Format
(
d
.
PgTsFormat
)
}
else
if
f
.
DataTypeOID
==
pgtype
.
UUIDOID
{
bb
:=
v
[
i
]
.
([
16
]
byte
)
u
,
_
:=
uuid
.
FromBytes
(
bb
[
:
])
...
...
zdb/pool.go
View file @
5b2da0e8
...
...
@@ -31,8 +31,6 @@ type Pool struct {
slavesIter
*
atomic
.
Int64
slavesAsyncIter
*
atomic
.
Int64
stop
bool
PgTsFormat
string
UseGoTime
bool
Continues
[]
string
ContinuesTry
[]
string
TryOnError
int
...
...
@@ -48,7 +46,6 @@ func New(ctx context.Context) *Pool {
mu
:
&
sync
.
RWMutex
{},
slavesIter
:
&
atomic
.
Int64
{},
slavesAsyncIter
:
&
atomic
.
Int64
{},
PgTsFormat
:
"2006-01-02 15:04:05"
,
Continues
:
[]
string
{
"connect"
,
"EOF"
,
"conflict with recovery"
,
"context deadline exceeded"
},
ContinuesTry
:
[]
string
{
"conflict with recovery"
},
TryOnError
:
1
,
...
...
@@ -78,8 +75,6 @@ func (d *Pool) WithContext(ctx context.Context) *Pool {
slavesIter
:
d
.
slavesIter
,
slavesAsyncIter
:
d
.
slavesAsyncIter
,
stop
:
d
.
stop
,
UseGoTime
:
d
.
UseGoTime
,
PgTsFormat
:
d
.
PgTsFormat
,
Continues
:
d
.
Continues
,
ContinuesTry
:
d
.
ContinuesTry
,
TryOnError
:
d
.
TryOnError
,
...
...
@@ -356,12 +351,12 @@ func (d *Pool) prepare(sql string, param map[string]any) string {
for
n
,
t1
:=
range
param
{
switch
tv
:=
t1
.
(
type
)
{
case
time
.
Time
:
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%s'
"
,
tv
.
UTC
()
.
Format
(
time
.
DateTime
)))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%s'
::timestamptz"
,
tv
.
Format
(
time
.
RFC3339Nano
)))
case
*
time
.
Time
:
if
tv
==
nil
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
}
else
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%s'
"
,
tv
.
UTC
()
.
Format
(
time
.
DateTime
)))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%s'
::timestamptz"
,
tv
.
Format
(
time
.
RFC3339Nano
)))
}
case
nil
:
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
...
...
@@ -415,7 +410,7 @@ func (d *Pool) prepare(sql string, param map[string]any) string {
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"%v"
,
tv
))
default
:
switch
reflect
.
TypeOf
(
tv
)
.
Kind
()
{
case
reflect
.
Slice
:
case
reflect
.
Slice
,
reflect
.
Array
:
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"'{"
+
strings
.
Trim
(
strings
.
Join
(
strings
.
Split
(
fmt
.
Sprint
(
tv
),
" "
),
","
),
"[]"
)
+
"}'"
)
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment