Files
fn-serverless/api/datastore/datastore.go
Martin Pinto-Bazurco Mendieta e4b3105d92 Fix #418 Added MySQL as DB storage layer. (#575)
* Fix #418 Added MySQL as DB storage layer.

* Make the mysql stuff work

* Make the mysql stuff work

* Make the mysql stuff work

* Make the mysql stuff work

* small fixes

* Switch to Go 1.8 installation inside CI (#589)

* Switch to Go 1.8 installation inside CI

Partially Addresses: #588

* Use url.Hostname() instead of custom method

* Added PR review changes.

* Added missing check for error.

* Changed * with name, config

* Removed unused import.

* Added check for NoRows

* Merged changes with HEAD

* Added documentation to mysql.go

* update mysql to be on par with postgres
2017-03-21 20:01:17 +01:00

34 lines
847 B
Go

package datastore
import (
"fmt"
"net/url"
"github.com/Sirupsen/logrus"
"github.com/iron-io/functions/api/datastore/bolt"
"github.com/iron-io/functions/api/datastore/mysql"
"github.com/iron-io/functions/api/datastore/postgres"
"github.com/iron-io/functions/api/datastore/redis"
"github.com/iron-io/functions/api/models"
)
func New(dbURL string) (models.Datastore, error) {
u, err := url.Parse(dbURL)
if err != nil {
logrus.WithError(err).WithFields(logrus.Fields{"url": dbURL}).Fatal("bad DB URL")
}
logrus.WithFields(logrus.Fields{"db": u.Scheme}).Debug("creating new datastore")
switch u.Scheme {
case "bolt":
return bolt.New(u)
case "postgres":
return postgres.New(u)
case "mysql":
return mysql.New(u)
case "redis":
return redis.New(u)
default:
return nil, fmt.Errorf("db type not supported %v", u.Scheme)
}
}