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
zdb
Commits
1c1eb92b
Commit
1c1eb92b
authored
May 22, 2023
by
Vladimir Barsukov
Browse files
fix
parent
4a21e5bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
pool.go
View file @
1c1eb92b
...
...
@@ -4,9 +4,6 @@ import (
"context"
"errors"
"fmt"
"git.barsukov.pro/barsukov/zdb/ztype"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
"log"
"reflect"
...
...
@@ -117,17 +114,17 @@ func (d *Pool) newConn(mode connMode, pgConnString string) (q *conn, err error)
return
nil
,
err
}
pgxConfig
.
AfterConnect
=
func
(
ctx
context
.
Context
,
p
*
pgx
.
Conn
)
error
{
j
:=
&
pgtype
.
Type
{
Name
:
"jsonb"
,
OID
:
pgtype
.
JSONBOID
,
Codec
:
ztype
.
JSONBCodec
{}}
jb
:=
&
pgtype
.
Type
{
Name
:
"json"
,
OID
:
pgtype
.
JSONOID
,
Codec
:
ztype
.
JSONCodec
{}}
p
.
TypeMap
()
.
RegisterType
(
j
)
p
.
TypeMap
()
.
RegisterType
(
jb
)
p
.
TypeMap
()
.
RegisterType
(
&
pgtype
.
Type
{
Name
:
"_json"
,
OID
:
pgtype
.
JSONArrayOID
,
Codec
:
&
pgtype
.
ArrayCodec
{
ElementType
:
j
}})
p
.
TypeMap
()
.
RegisterType
(
&
pgtype
.
Type
{
Name
:
"_jsonb"
,
OID
:
pgtype
.
JSONBArrayOID
,
Codec
:
&
pgtype
.
ArrayCodec
{
ElementType
:
jb
}})
return
nil
}
//
pgxConfig.AfterConnect = func(ctx context.Context, p *pgx.Conn) error {
//
j := &pgtype.Type{Name: "jsonb", OID: pgtype.JSONBOID, Codec: ztype.JSONBCodec{}}
//
jb := &pgtype.Type{Name: "json", OID: pgtype.JSONOID, Codec: ztype.JSONCodec{}}
//
//
p.TypeMap().RegisterType(j)
//
p.TypeMap().RegisterType(jb)
//
p.TypeMap().RegisterType(&pgtype.Type{Name: "_json", OID: pgtype.JSONArrayOID, Codec: &pgtype.ArrayCodec{ElementType: j}})
//
p.TypeMap().RegisterType(&pgtype.Type{Name: "_jsonb", OID: pgtype.JSONBArrayOID, Codec: &pgtype.ArrayCodec{ElementType: jb}})
//
//
return nil
//
}
if
pgxPool
,
err
=
pgxpool
.
NewWithConfig
(
d
.
ctx
,
pgxConfig
);
err
!=
nil
{
return
&
conn
{
Pool
:
pgxPool
,
Alive
:
false
,
Mode
:
mode
},
err
...
...
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