-
Notifications
You must be signed in to change notification settings - Fork 777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PART 2] pgx v5 support (#1823) #1874
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing unreasonable ! Good job :)
return "pgtype.Tsrange" | ||
case SQLDriverPGXV5: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can confirm this is the right thing to do. pgtype.Range[pgtype.Timestamp]
is the correct Go type.
@@ -122,6 +151,8 @@ func postgresType(req *plugin.CodeGenRequest, col *plugin.Column) string { | |||
|
|||
case "jsonb": | |||
switch driver { | |||
case SQLDriverPGXV5: | |||
return "[]byte" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that []byte
seems to be the right type here. Jackc said here that []byte and string can directly be used for json and jsonb. No need to a pgtype wrapper.
but my experience has been that []byte better handles NULL values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, user can override default []byte type with some struct type.
For example:
type SomeDTOStruct struct {
Value1 int. `json:"value_1"`
Value2 string `json:"value_2"`
}
"overrides": [
{
"column": "some_table.jsonb_field",
"go_type": "*example.com/db/dto.SomeDTOStruct"
}
]
Then pgx v5 will marshals struct to JSON and vice versa automatically.
I can add this example to the docs, if it's not obvious behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like above mentioned syntax for absolute path ("go_type": "*example.com/db/dto.SomeDTOStruct") not working . Throwing error path not recognised in latest go version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f1forhelp if you are sure that there is a bug in the sqlc you can create an issue with reproducible example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcdoker18 its working.
I used these json values.
"overrides": [
{
"column": "events.event_price",
"go_type": {
"import":"test_proj/models/sqlc_json_model",
"package": "sqlcjsonmodel",
"type":"EventPrice"
}
}
],
return "pgtype.CIDR" | ||
case SQLDriverLibPQ: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this cases the build to break. Can we add it back in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
I am interesting in this PR too. Anything I could do to help ? |
77a2d3e
to
cd5d070
Compare
* 'pgx/v5' option requires '--experimental' cli flag. * array, ranges, multiranges uses generic version for 'pgx/v5'. It supports multidemensional arrays. * 'pgx/v5' implementation prefers use pgtype types. For example, pgtype.Bool instead of sql.NullBool. * added support for new pg types: * datemultirange * tsmultirange * tstzmultirange * nummultirange * int4multirange * int8multirange * bit * varbit * cid * oid * tid * circle * line * lseg * path * point * polygon
cd5d070
to
4f0731b
Compare
Hi @kyleconroy Can you please take a look again? I fixed all merge conflicts |
Added support for v5 of the pgx Go drives
* datemultirange
* tsmultirange
* tstzmultirange
* nummultirange
* int4multirange
* int8multirange
* bit
* varbit
* cid
* oid
* tid
* circle
* line
* lseg
* path
* point
* polygon