daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Aug 21st, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //OpenConnection opens a connection to a MySQL database by `connStr`
  2. // or returns error. If `connStr` is empty, error is returned.
  3. //
  4. // Parameters:
  5. // - `connStr`: the URL of the database to connect to
  6. // - `interpolateParams` : should we interpolate parameters?
  7. //
  8. // Returns:
  9. // - pointer to the database connection
  10. // - any errors that happened during this process
  11. func OpenConnection(connStr string, interpolateParams bool) (*sql.DB, *errors.ErrorSt) {
  12.     if connStr == "" {
  13.         return nil, errors.Database().ReplaceMessage("No database connection string.")
  14.     }
  15.     connStr = connStr + "?parseTime=true&multiStatements=true"
  16.     if interpolateParams {
  17.         connStr += "&interpolateParams=true"
  18.     }
  19.  
  20.     db, err := sql.Open("mysql", connStr)
  21.     if err != nil {
  22.         return nil, errors.Database().AddDetails(err.Error(), connStr)
  23.     }
  24.     return db, nil
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top