MCPcopy Create free account
hub / github.com/go-pg/pg / ExampleDB_Model_updateSomeColumns

Function ExampleDB_Model_updateSomeColumns

example_model_test.go:843–858  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

841}
842
843func ExampleDB_Model_updateSomeColumns() {
844 db := modelDB()
845
846 book := Book{
847 ID: 1,
848 Title: "updated book 1", // only this column is going to be updated
849 AuthorID: 2,
850 }
851 _, err := db.Model(&book).Column("title").WherePK().Returning("*").Update()
852 if err != nil {
853 panic(err)
854 }
855
856 fmt.Println(book, book.AuthorID)
857 // Output: Book<Id=1 Title="updated book 1"> 1
858}
859
860func ExampleDB_Model_updateSomeColumns2() {
861 db := modelDB()

Callers

nothing calls this directly

Calls 6

modelDBFunction · 0.85
UpdateMethod · 0.80
ReturningMethod · 0.80
WherePKMethod · 0.80
ColumnMethod · 0.80
ModelMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…