code: func getDatabaseConnection(c context.Context) (*sql.DB, error) {
  	// Update the database pointer if the database settings have changed. This operation is costly, but should be rare.
  	// Done here to ensure that a connection established with an outdated connection string is closed as soon as possible.
  	settings, err := settings.Get(c)
  	if err != nil {
  		return nil, err
  	}
  	connectionString := fmt.Sprintf("%s:%s@cloudsql(%s)/%s", settings.Username, settings.Password, settings.Server, settings.Database)
  
  	// If the connection string matches what we expect, the current pointer is correct so just return it.
  	dbLock.RLock()
  	if connectionString == dbConnectionString {
  		defer dbLock.RUnlock()
  		return db, nil
  	}
  	dbLock.RUnlock()
  
  	// The connection string doesn't match so the db pointer needs to be created or updated.
  	dbLock.Lock()
  	defer dbLock.Unlock()
  
  	// Releasing the read lock may have allowed another concurrent request to grab the write lock first so it's
  	// possible we no longer need to do anything. Check again while holding the write lock.
  	if connectionString == dbConnectionString {
  		return db, nil
  	}
  
  	if db != nil {
  		if err := db.Close(); err != nil {
  			logging.Warningf(c, "Failed to close the previous database connection: %s", err.Error())
  		}
  	}
  	db, err = sql.Open("mysql", connectionString)
  	if err != nil {
  		return nil, fmt.Errorf("failed to open a new database connection: %s", err.Error())
  	}
  
  	// AppEngine limit.
  	db.SetMaxOpenConns(12)
  	dbConnectionString = connectionString
  	return db, nil
  }
docs: // getDatabaseConnection returns a pointer to the open database connection, creating it if necessary.