Skip to content

Conversation

@nobokoba
Copy link

@nobokoba nobokoba commented Mar 4, 2016

If primarykey is an integer , will be removed also have been included in the structure , I want to directly INSERT an integer value . Use for example, INSERT to a dependent table .

usage:

CREATE TABLE `user` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(64) NOT NULL,
)
CREATE TABLE `user_setting` (
  `user_id` int(11) NOT NULL,
  `some_setting_value` int(11) NOT NULL,
)
type User struct {
    Id         int    `db:"pk" column:"user_id"`
    Username string
}
type UserSetting struct {
    UserId int `db:"pk,not_ai"`
    SomeSettingValue int `db:"pk"`
}

user := &User {
    Username : "USER_NAME",
}
db.Insert(user)
setting := &UserSetting {
    UserId : user.Id,
    SomeSettingValue: 1
}
db.Insert(setting)

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.

2 participants