-
Notifications
You must be signed in to change notification settings - Fork 369
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
Field tags now allow you to declare a primary key or autoincrement field #26
Conversation
…field declaration
Apologies I haven't commented. I like the idea, but I wonder if we should use the same "db" tag for all of these attributes, rather than introducing another tag. For example:
That would follow the convention used in the Thoughts? |
I should clarify: the first item in the comma separated list would always be the column name, similar to the way the json tag works. |
+1 to using the same tag name, following the convention of |
I would personally prefer "name,autoincrement" and "name,primary" over "name,pk,autoincrement" and "name,pk". In the case of "autoincrement", "primary" would naturally be assumed. |
@lukescott auto-increment columns are not always primary keys. |
@meetmauro Can you see if the requested changes can be made to this PR? I'd be happy to add this feature to the codebase.
|
OK. Rebased and made suggested changes in a new PR. |
New PR: #233 |
With this patch you can declaratively say:
type Product struct {
Id int64
db:"product_id" flags:"pk, autoincrement"
Price int64
db:"unit_price"
IgnoreMe string
db:"-"
}
so that your AddTableWithName will be simpler like:
t1 := dbmap.AddTableWithName(Invoice{}, "invoice_test")
instead of using SetKeys to specify keys on fields.