Skip to content

Instantly share code, notes, and snippets.

@4ydx
Created April 26, 2015 02:05
Show Gist options
  • Select an option

  • Save 4ydx/70b732c15d83c294c7dd to your computer and use it in GitHub Desktop.

Select an option

Save 4ydx/70b732c15d83c294c7dd to your computer and use it in GitHub Desktop.
Wrapping multiple similar calls so that error handling code is reduced.
type WriteDB struct {
Conn *sql.DB
Err error
}
func (db *WriteDB) Do(
update,
title,
updated_at,
updated_by,
titleString,
) {
if db.Err != nil {
return
}
_, db.Err = db.Conn.Exec(update, title, updated_at, updated_by, titleString)
}
func main() {
var db WriteDB
db.Conn, db.Err = readDB.Begin()
db.Do(stmtUpdateSettings, title, updated_at, updated_by, "title")
db.Do(stmtUpdateSettings, logo, updated_at, updated_by, "logo")
if db.Err != nil {
db.Conn.Rollback()
}
return db.Conn.Commit()
}
@4ydx
Copy link
Author

4ydx commented Apr 26, 2015

This is pseudo-code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment