GithubHelp home page GithubHelp logo

sqlc-dev / pqtype Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 3.0 33 KB

Go types for PostgreSQL types when using lib/pq

Home Page: https://pkg.go.dev/github.com/sqlc-dev/pqtype

License: MIT License

Go 100.00%
golang postgresql

pqtype's People

Contributors

jille avatar kyleconroy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

pqtype's Issues

Error when using NullRawMessage in SQL query (e.g. INSERT)

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?

Wrong module name

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.