mirror of https://github.com/VinGarcia/ksql.git
Add support to the mysql driver
parent
3a90b03a37
commit
bbad31ce4d
|
@ -13,7 +13,7 @@ const (
|
||||||
var supportedDialects = map[string]dialect{
|
var supportedDialects = map[string]dialect{
|
||||||
"postgres": &postgresDialect{},
|
"postgres": &postgresDialect{},
|
||||||
"sqlite3": &sqlite3Dialect{},
|
"sqlite3": &sqlite3Dialect{},
|
||||||
// "mysql": &mysqlDialect{},
|
"mysql": &mysqlDialect{},
|
||||||
}
|
}
|
||||||
|
|
||||||
type dialect interface {
|
type dialect interface {
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -4,6 +4,7 @@ go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ditointernet/go-assert v0.0.0-20200120164340-9e13125a7018
|
github.com/ditointernet/go-assert v0.0.0-20200120164340-9e13125a7018
|
||||||
|
github.com/go-sql-driver/mysql v1.4.0 // indirect
|
||||||
github.com/golang/mock v1.5.0
|
github.com/golang/mock v1.5.0
|
||||||
github.com/jmoiron/sqlx v1.2.0
|
github.com/jmoiron/sqlx v1.2.0
|
||||||
github.com/lib/pq v1.1.1
|
github.com/lib/pq v1.1.1
|
||||||
|
|
12
ksql_test.go
12
ksql_test.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ditointernet/go-assert"
|
"github.com/ditointernet/go-assert"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/vingarcia/ksql/nullable"
|
"github.com/vingarcia/ksql/nullable"
|
||||||
|
@ -353,7 +354,7 @@ func TestInsert(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should insert ignoring the ID for sqlite and multiple ids", func(t *testing.T) {
|
t.Run("should insert ignoring the ID for sqlite and multiple ids", func(t *testing.T) {
|
||||||
if driver != "sqlite3" {
|
if supportedDialects[driver].InsertMethod() != insertWithLastInsertID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1345,6 +1346,7 @@ func TestScanRows(t *testing.T) {
|
||||||
var connectionString = map[string]string{
|
var connectionString = map[string]string{
|
||||||
"postgres": "host=localhost port=5432 user=postgres password=postgres dbname=ksql sslmode=disable",
|
"postgres": "host=localhost port=5432 user=postgres password=postgres dbname=ksql sslmode=disable",
|
||||||
"sqlite3": "/tmp/ksql.db",
|
"sqlite3": "/tmp/ksql.db",
|
||||||
|
"mysql": "root:mysql@(127.0.0.1:3306)/ksql?timeout=30s",
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTable(driver string) error {
|
func createTable(driver string) error {
|
||||||
|
@ -1376,6 +1378,13 @@ func createTable(driver string) error {
|
||||||
name VARCHAR(50),
|
name VARCHAR(50),
|
||||||
address jsonb
|
address jsonb
|
||||||
)`)
|
)`)
|
||||||
|
case "mysql":
|
||||||
|
_, err = db.Exec(`CREATE TABLE users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
age INT,
|
||||||
|
name VARCHAR(50),
|
||||||
|
address JSON
|
||||||
|
)`)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create new users table: %s", err.Error())
|
return fmt.Errorf("failed to create new users table: %s", err.Error())
|
||||||
|
@ -1399,6 +1408,7 @@ func newTestDB(db *sql.DB, driver string, tableName string, ids ...string) DB {
|
||||||
insertMethod: map[string]insertMethod{
|
insertMethod: map[string]insertMethod{
|
||||||
"sqlite3": insertWithLastInsertID,
|
"sqlite3": insertWithLastInsertID,
|
||||||
"postgres": insertWithReturning,
|
"postgres": insertWithReturning,
|
||||||
|
"mysql": insertWithLastInsertID,
|
||||||
}[driver],
|
}[driver],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue