arsd.database



string escapedVariants(Database db, in string sql, VariantN!(maxSize)[] t);
Note:
?n params are zero based!

string DataObjectField(T, string table, string column, string aliasAs = null)();
You can subclass DataObject if you want to get some compile time checks or better types.

You'll want to disable opDispatch, then forward your properties to the super opDispatch.

class SimpleDataObject(string tableToUse,fieldsToUse): DataObject;
This creates an editable data object out of a simple struct.

struct MyFields { int id; string name; }

alias SimpleDataObject!("my_table", MyFields) User;



User a = new User(db);

a.id = 30; a.name = "hello"; a.commitChanges(); // tries an update or insert on the my_table table



Unlike the base DataObject class, this template provides compile time checking for types and names, based on the struct you pass in:

a.id = "aa"; // compile error

a.notAField; // compile error

struct StructFromCreateTable(string sql,string tableName);
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.

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.

template DataObjectFromSqlCreateTable(string sql,string tableName)
Combines StructFromCreateTable and SimpleDataObject into a one-stop template. alias DataObjectFromSqlCreateTable(import("file.sql"), "my_table") MyTable;


Page generated by Ddoc.