diff --git a/dialect.go b/dialect.go index 6640c34..c46869d 100644 --- a/dialect.go +++ b/dialect.go @@ -13,7 +13,7 @@ const ( var supportedDialects = map[string]dialect{ "postgres": &postgresDialect{}, "sqlite3": &sqlite3Dialect{}, - // "mysql": &mysqlDialect{}, + "mysql": &mysqlDialect{}, } type dialect interface { diff --git a/go.mod b/go.mod index b218375..2b82c83 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.14 require ( 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/jmoiron/sqlx v1.2.0 github.com/lib/pq v1.1.1 diff --git a/ksql_test.go b/ksql_test.go index f0514b9..85a4691 100644 --- a/ksql_test.go +++ b/ksql_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/ditointernet/go-assert" + _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" "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) { - if driver != "sqlite3" { + if supportedDialects[driver].InsertMethod() != insertWithLastInsertID { return } @@ -1345,6 +1346,7 @@ func TestScanRows(t *testing.T) { var connectionString = map[string]string{ "postgres": "host=localhost port=5432 user=postgres password=postgres dbname=ksql sslmode=disable", "sqlite3": "/tmp/ksql.db", + "mysql": "root:mysql@(127.0.0.1:3306)/ksql?timeout=30s", } func createTable(driver string) error { @@ -1376,6 +1378,13 @@ func createTable(driver string) error { name VARCHAR(50), 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 { 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{ "sqlite3": insertWithLastInsertID, "postgres": insertWithReturning, + "mysql": insertWithLastInsertID, }[driver], } }