StructFromCreateTable

Given some SQL, it finds the CREATE TABLE instruction for the given tableName. (this is so it can find one entry from a file with several SQL commands. But it may break on a complex file, so try to only feed it simple sql files.)

From that, it pulls out the members to create a simple struct based on it.

It's not terribly smart, so it will probably break on complex tables.

Data types handled: INTEGER, SMALLINT, MEDIUMINT -> D's int TINYINT -> D's bool BIGINT -> D's long TEXT, VARCHAR -> D's string FLOAT, DOUBLE -> D's double

It also reads DEFAULT values to pass to D, except for NULL. It ignores any length restrictions.

struct StructFromCreateTable (
string sql
string tableName
)

Bugs

Skips all constraints Doesn't handle nullable fields, except with strings It only handles SQL keywords if they are all caps

This, when combined with SimpleDataObject!(), can automatically create usable D classes from SQL input.

Meta