storage/sql: initial MySQL storage implementation

It will be shared by both Postgres and MySQL configs.

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
This commit is contained in:
Pavel Borzenkov
2017-04-21 18:51:55 +03:00
committed by Nandor Kracser
parent 92920c86ea
commit e53bdfabb9
6 changed files with 292 additions and 97 deletions

View File

@@ -83,6 +83,28 @@ var (
{regexp.MustCompile(`\bnow\(\)`), "date('now')"},
},
}
flavorMySQL = flavor{
queryReplacers: []replacer{
{bindRegexp, "?"},
// Translate types.
{matchLiteral("bytea"), "blob"},
{matchLiteral("timestamptz"), "datetime(3)"},
// MySQL doesn't support indicies on text fields w/o
// specifying key length. Use varchar instead (768 is
// the max key length for InnoDB with 4k pages).
{matchLiteral("text"), "varchar(768)"},
// Quote keywords and reserved words used as identifiers.
{regexp.MustCompile(`\b(keys)\b`), "`$1`"},
// Change default timestamp to fit datetime.
{regexp.MustCompile(`0001-01-01 00:00:00 UTC`), "1000-01-01 00:00:00"},
},
}
// Not tested.
flavorCockroach = flavor{
executeTx: crdb.ExecuteTx,
}
)
func (f flavor) translate(query string) string {