Skip to content

Instantly share code, notes, and snippets.

@jaybill
Created November 28, 2013 18:52
Show Gist options
  • Select an option

  • Save jaybill/7696642 to your computer and use it in GitHub Desktop.

Select an option

Save jaybill/7696642 to your computer and use it in GitHub Desktop.
/* See http://godoc.org/bitbucket.org/jaybill/sawsij/framework/model#DbSetup for how to set up a DbSetup object */
db := &model.DbSetup{}
....
post := &Post{Name: "Jimmy", Title: "First Post", Slug: "firstpost"}
t := &model.Table{Db: db}
err := t.Insert(post)
// assuming no error, post.Id will now contain the auto-inserted Id.
/* Here's how you do it if you want to set your own id */
post := &Post{Id: 4, Name: "Jimmy", Title: "First Post", Slug: "firstpost"}
t := &model.Table{Db: db}
err := t.InsertWithoutAutoId(post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment