sqlc-dev / pqtype Goto Github PK
View Code? Open in Web Editor NEWGo types for PostgreSQL types when using lib/pq
Home Page: https://pkg.go.dev/github.com/sqlc-dev/pqtype
License: MIT License
Go types for PostgreSQL types when using lib/pq
Home Page: https://pkg.go.dev/github.com/sqlc-dev/pqtype
License: MIT License
We have a SQL table like this:
CREATE TABLE foobar (
id uuid NOT NULL,
data jsonb,
CONSTRAINT foobar_pk PRIMARY KEY (id)
);
and a query like this:
-- name: CreateFoobar :one
INSERT INTO foobar (id, data) VALUES ($1, $2)
RETURNING *;
with sqlc
(current master, compiled from source which includes sqlc-dev/sqlc@2143e46) the following arg is generated for CreateFoobar
:
type CreateFoobarParams struct {
ID uuid.UUID
Data pqtype.NullRawMessage
}
When I try to use CreateFoobar
with this argument, I get the following error:
sql: converting argument $2 type: non-Value type json.RawMessage returned from Value
To me, it looks like the database/sql
package does not like the json.RawMessage
which is returned as driver.Value
from Value()
. If I return a []byte
instead, then it works for me.
// Value implements the driver Valuer interface.
func (n NullRawMessage) Value() (driver.Value, error) {
if !n.Valid {
return nil, nil
}
return []byte(n.RawMessage), nil
}
@kyleconroy What do you think, is returning []byte
, which is accepted as driver.Value
the right thing to do here? Should I file a PR for this?
The go.mod is not adapted to the new org, so when requiring this in go you get the following error:
❯ go mod tidy
go: finding module for package github.com/tabbed/pqtype
go: found github.com/tabbed/pqtype in github.com/tabbed/pqtype v0.2.0
go: jus.tw.cx/steering-api/internal/adminpanel/cyclestatus/internal/db imports
github.com/tabbed/pqtype: github.com/tabbed/[email protected]: parsing go.mod:
module declares its path as: github.com/sqlc-dev/pqtype
but was required as: github.com/tabbed/pqtype
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.