On Sunday, 7 October 2012 at 17:06:31 UTC, Joseph Rushton Wakeling wrote:
Am I right that there's something in Adam Ruppe's web modules
that's heading in this direction?

Yeah, though I'm a little biased toward mysql since that's what I use every day, so some of the stuff that should be in generic database.d are instead in mysql.d.

But my stuff indeed does sql strings which can then be passed to a Database class with pretty uniform interface, at least for basic queries, for some major dbs.

https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff


Among the string manipulation stuff is class DataObject, which builds an UPDATE or INSERT query:

auto obj = new DataObject(db, "table_name");
obj.id = 10;
obj.name = "cool";
obj.commitChanges(); /* runs:
  if(db.query("select id from table_name where id = 10").empty)
db.query("insert into table_name (id, name) values (10, 'cool')");
   else
db.query("UPDATE table_name set name = 'cool' where id = 10");
*/

and also a build data object subclass from sql create table which kinda works, ugly mixin stuff.


And there's also a SelectBuilder which does basic concat stuff:

auto query = new SelectBuilder();
query.table = "something";
query.fields ~= "something.*";
query.wheres ~= "id > ?0";

db.query(query.toString(), 10);


expands into

select something.* from something where (id > 10);



Nothing super fancy but it works for me.

Reply via email to