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

Primary keys in PostgreSQL tables #6

Closed
pzduniak opened this issue Mar 9, 2014 · 1 comment
Closed

Primary keys in PostgreSQL tables #6

pzduniak opened this issue Mar 9, 2014 · 1 comment

Comments

@pzduniak
Copy link
Contributor

pzduniak commented Mar 9, 2014

First of all, thank you for developing such great library - it really simplified development of my software, because now I don't have to care about weird ORM magic.

The only issue is that whenever I create a new struct with the SERIAL column (ie. primary key) not set, it tries to create a new row with id 0 (because uninitialized int64 is 0). How can I use the nextval feature in PostgreSQL appends? If it's not possible, could you add such feature / shortly explain how can I add it on my own?

It currently freezed my development, as I can't finish the CRUD functionality of my API, so it'd be great if you could sort it out quickly.

@xiam
Copy link
Member

xiam commented Mar 10, 2014

Hello Piotr,

Glad to hear upper/db is useful for you! Thanks for trying, even with our docs are not so good.

If you're using a serial field with name id, try to omit the id value from being sent using the omitempty tag, like this:

type User struct {
  Id int `field:"id" omitempty:"true"`
  Name string `field:"name"`
}

The omitempty tag skips fields with zero value from being used in a query. That should work with PostgreSQL and serial, let me know how it went.

(I should put that in our docs too).

Regards,

@xiam xiam closed this as completed Apr 13, 2014
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

No branches or pull requests

2 participants