-
-
Notifications
You must be signed in to change notification settings - Fork 234
Description
Looking through the examples I found the memory database helpful and am able to get an instance of go-mysql-server up and running. I am able to populate databases and table names from my custom source but am running into an issue with the table schema.
In the examples I see the follow which works:
table := NewTable(tableName, sql.Schema{
{Name: "name", Type: sql.Text, Nullable: false, Source: tableName},
{Name: "email", Type: sql.Text, Nullable: false, Source: tableName},
{Name: "phone_numbers", Type: sql.JSON, Nullable: false, Source: tableName},
{Name: "created_at", Type: sql.Timestamp, Nullable: false, Source: tableName},
})
But for my custom backend I actually have the table definitions already in SQL create table format:
CREATE TABLE fancy_table1
(
param_num
smallint(6) NOT NULL DEFAULT '0',
name
varchar(255) NOT NULL DEFAULT '',
units
varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (param_num
)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I can create the tables from the cli via:
mysql --host 127.0.0.1 -u root mydb < createtables.sql
However I am wondering if there is a way using the parser already build into go-mysql-server to convert the SQL query into something I can easily feed into NewTable?