[std.database]
Steve Teale
steve.teale at britseyeview.com
Mon Oct 10 22:14:05 PDT 2011
Another dumb idea.
I was thinking about Johathan's idea about std.sql. What if we did
something like the following - let the compiler do the work.
enum Disposition { ... }
Disposition Insert(string database, S)(out ulong ra, S s, string table)
if (is(S == struct))
{ ... }
Disposition Insert(string database)
(out ulong ra, Variant[string] vaa, string table) { ... }
Disposition PrepareInsert(string database, S)(S s) if (is(S == struct))
{ ... }
Disposition PrepareInsert(string database)(Variant[string] vaa)
{ ... }
Disposition ExecInsert(string database, S)
(out ulong ra, S s) if (is(S == struct))
Disposition ExecInsert(string database)
(out ulong ra, Variant[string] vaa)
{ ... }
Disposition Update(string database, string whereClause, S, T...)
(out ulong ra, S s, string table, T args) if (is(S == struct)) { ... }
Disposition Update(string database, string whereClause, T...)
(out ulong ra, Variant[string] vaa, string table, T args)
{ ... }
...
Disposition Delete(string database, string whereClause, S)
(out ulong ra, S s) if (is(S == struct)) { ... }
Disposition Delete(string database, string whereClause)
(Variant[string] vaa) { ... }
...
Disposition SelectSequence(string database, SIN, SOUT)
(SIN sin, SOUT sout, string table)
if (is(SIN == struct) && is(SOUT == struct)) { ... }
Disposition SelectSequence(string database)
(Variant[string] vaain, Variant[string] vaaout, string table)
{ ... }
Disposition SelectResultSet(string database, SIN, SOUT)
(out ulong rc, SIN sin, SOUT sout, string table)
if (is(SIN == struct) && is(SOUT == struct))
{ ... }
Disposition SelectResultSet(string database)
(out ulong rc, Variant[string] vaain, Variant[string] vaaout,
string table)
{ ... }
...
...
This would sidestep the need for a lowest common denominator approach.
The compiler would generate code for a specified database, and could
generate SQL with appropriate parameter markers and escaping. and the
code to execute it.
If some operation wasn't supported it could do a static assert.
This would be on top of a set of modules that provided nitty-gritty
operations for each database - database oriented modules as opposed to
SQL oriented. If the compile time SQL option didn't work for your app,
you'd fall back for specifics on these.
Could it be done?
Steve
More information about the Digitalmars-d
mailing list