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,74 @@
package sqlite
import (
"fmt"
"github.com/fnproject/fn/api/datastore/sql/dbhelper"
"github.com/jmoiron/sqlx"
"github.com/mattn/go-sqlite3"
"net/url"
"os"
"path/filepath"
"strings"
)
type sqliteHelper int
func (sqliteHelper) Supports(scheme string) bool {
switch scheme {
case "sqlite3", "sqlite":
return true
}
return false
}
func (sqliteHelper) PreConnect(url *url.URL) (string, error) {
// make all the dirs so we can make the file..
dir := filepath.Dir(url.Path)
err := os.MkdirAll(dir, 0755)
if err != nil {
return "", err
}
return strings.TrimPrefix(url.String(), url.Scheme+"://"), nil
}
func (sqliteHelper) PostCreate(db *sqlx.DB) (*sqlx.DB, error) {
db.SetMaxOpenConns(1)
return db, nil
}
func (sqliteHelper) CheckTableExists(tx *sqlx.Tx, table string) (bool, error) {
query := tx.Rebind(fmt.Sprintf(`SELECT count(*)
FROM sqlite_master
WHERE 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 (sqliteHelper) String() string {
return "sqlite"
}
func (sqliteHelper) IsDuplicateKeyError(err error) bool {
sqliteErr, ok := err.(sqlite3.Error)
if ok {
if sqliteErr.ExtendedCode == sqlite3.ErrConstraintUnique || sqliteErr.ExtendedCode == sqlite3.ErrConstraintPrimaryKey {
return true
}
}
return false
}
func init() {
dbhelper.Add(sqliteHelper(0))
}