Inverting deps on SQL, Log and MQ plugins to make them optional dependencies of extended servers, Removing some dead code that brought in unused dependencies Filtering out some non-linux transitive deps. (#1057)

* initial Db helper split - make SQL and datastore packages optional

* abstracting log store

* break out DB, MQ and log drivers as extensions

* cleanup

* fewer deps

* fixing docker test

* hmm dbness

* updating db startup

* Consolidate all your extensions into one convenient package

* cleanup

* clean up dep constraints
This commit is contained in:
Owen Cliffe
2018-06-11 18:23:28 +01:00
committed by Reed Allman
parent 5b2691037e
commit 1ad27f4f0d
519 changed files with 907 additions and 91042 deletions

View File

@@ -0,0 +1,61 @@
package mysql
import (
"fmt"
"github.com/fnproject/fn/api/datastore/sql/dbhelper"
"github.com/go-sql-driver/mysql"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"net/url"
"strings"
)
type mysqlHelper int
func (mysqlHelper) Supports(scheme string) bool {
return scheme == "mysql"
}
func (mysqlHelper) PreConnect(url *url.URL) (string, error) {
return strings.TrimPrefix(url.String(), url.Scheme+"://"), nil
}
func (mysqlHelper) PostCreate(db *sqlx.DB) (*sqlx.DB, error) {
return db, nil
}
func (mysqlHelper) CheckTableExists(tx *sqlx.Tx, table string) (bool, error) {
query := tx.Rebind(fmt.Sprintf(`SELECT count(*)
FROM information_schema.TABLES
WHERE TABLE_NAME = '%s'
`, table))
row := tx.QueryRow(query)
var count int
err := row.Scan(&count)
if err != nil {
return false, err
}
exists := count > 0
return exists, nil
}
func (mysqlHelper) String() string {
return "mysql"
}
func (mysqlHelper) IsDuplicateKeyError(err error) bool {
switch mErr := err.(type) {
case *mysql.MySQLError:
if mErr.Number == 1062 {
return true
}
}
return false
}
func init() {
dbhelper.Add(mysqlHelper(0))
}