mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-12 16:10:03 +01:00
Add cgo build constraint for sqlite support (#25)
Required to upgrade https://github.com/mattn/go-sqlite3 which does not compile correctly with missing cgo.
This commit is contained in:
parent
cc769e9605
commit
fbddb76b84
6 changed files with 30 additions and 10 deletions
|
|
@ -19,6 +19,13 @@ type Driver interface {
|
|||
DeleteMigration(Transaction, string) error
|
||||
}
|
||||
|
||||
var drivers = map[string]Driver{}
|
||||
|
||||
// RegisterDriver registers a driver for a URL scheme
|
||||
func RegisterDriver(drv Driver, scheme string) {
|
||||
drivers[scheme] = drv
|
||||
}
|
||||
|
||||
// Transaction can represent a database or open transaction
|
||||
type Transaction interface {
|
||||
Exec(query string, args ...interface{}) (sql.Result, error)
|
||||
|
|
@ -26,16 +33,11 @@ type Transaction interface {
|
|||
|
||||
// GetDriver loads a database driver by name
|
||||
func GetDriver(name string) (Driver, error) {
|
||||
switch name {
|
||||
case "mysql":
|
||||
return MySQLDriver{}, nil
|
||||
case "postgres", "postgresql":
|
||||
return PostgresDriver{}, nil
|
||||
case "sqlite", "sqlite3":
|
||||
return SQLiteDriver{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown driver: %s", name)
|
||||
if val, ok := drivers[name]; ok {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unsupported driver: %s", name)
|
||||
}
|
||||
|
||||
// GetDriverOpen is a shortcut for GetDriver(u.Scheme).Open(u)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@ func TestGetDriver_MySQL(t *testing.T) {
|
|||
|
||||
func TestGetDriver_Error(t *testing.T) {
|
||||
drv, err := GetDriver("foo")
|
||||
require.Equal(t, "unknown driver: foo", err.Error())
|
||||
require.Equal(t, "unsupported driver: foo", err.Error())
|
||||
require.Nil(t, drv)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ import (
|
|||
_ "github.com/go-sql-driver/mysql" // mysql driver for database/sql
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterDriver(MySQLDriver{}, "mysql")
|
||||
}
|
||||
|
||||
// MySQLDriver provides top level database functions
|
||||
type MySQLDriver struct {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ import (
|
|||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterDriver(PostgresDriver{}, "postgres")
|
||||
RegisterDriver(PostgresDriver{}, "postgresql")
|
||||
}
|
||||
|
||||
// PostgresDriver provides top level database functions
|
||||
type PostgresDriver struct {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
// +build cgo
|
||||
|
||||
package dbmate
|
||||
|
||||
import (
|
||||
|
|
@ -12,6 +14,11 @@ import (
|
|||
_ "github.com/mattn/go-sqlite3" // sqlite driver for database/sql
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterDriver(SQLiteDriver{}, "sqlite")
|
||||
RegisterDriver(SQLiteDriver{}, "sqlite3")
|
||||
}
|
||||
|
||||
// SQLiteDriver provides top level database functions
|
||||
type SQLiteDriver struct {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
// +build cgo
|
||||
|
||||
package dbmate
|
||||
|
||||
import (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue