Skip to content
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

Add basic support for RETURNING syntax #6

Merged
merged 3 commits into from Dec 23, 2014
Merged

Add basic support for RETURNING syntax #6

merged 3 commits into from Dec 23, 2014

Conversation

0x6e6562
Copy link
Member

As discussed in #5, this patch provides basic support for the RETURNING syntax on Postgres.

Take the following example auto-increment table definition:

CREATE TABLE key_value 
(
    id SERIAL PRIMARY KEY,
    value TEXT
);

You can use the Returning() API like so:

var id int
row, err := sqlc.InsertInto(KEY_VALUE).
                 SetString(KEY_VALUE.VALUE, "foo").
                 Returning(KEY_VALUE.ID).
                 Fetch(d, db)
err = row.Scan(&id)

Right now, no other database is supported, so if people require this, then let their requirements be known. Also, the API only accepts one column definition in the Returning() function - in the future we could expand this to be variadic. There are probably are few more things that could be made more flexible as well.

0x6e6562 added a commit that referenced this pull request Dec 23, 2014
Add basic support for RETURNING syntax
@0x6e6562 0x6e6562 merged commit 30e2761 into master Dec 23, 2014
@0x6e6562 0x6e6562 deleted the returning branch December 23, 2014 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant