Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //OpenConnection opens a connection to a MySQL database by `connStr`
- // or returns error. If `connStr` is empty, error is returned.
- //
- // Parameters:
- // - `connStr`: the URL of the database to connect to
- // - `interpolateParams` : should we interpolate parameters?
- //
- // Returns:
- // - pointer to the database connection
- // - any errors that happened during this process
- func OpenConnection(connStr string, interpolateParams bool) (*sql.DB, *errors.ErrorSt) {
- if connStr == "" {
- return nil, errors.Database().ReplaceMessage("No database connection string.")
- }
- connStr = connStr + "?parseTime=true&multiStatements=true"
- if interpolateParams {
- connStr += "&interpolateParams=true"
- }
- db, err := sql.Open("mysql", connStr)
- if err != nil {
- return nil, errors.Database().AddDetails(err.Error(), connStr)
- }
- return db, nil
- }
Add Comment
Please, Sign In to add comment