Den 09-08-2011 21:15, Robert Clipsham skrev:
On 09/08/2011 08:30, Jonas Drewsen wrote:
Just stumbled upon this db orm for c++ that uses the gcc frontend to
rewrite c++ code to make classes suitable for database access.
http://www.codesynthesis.com/products/odb/
They are using pragmas to accomplish this. I guess an equally good
implementation in D would use custom attributes for this once (if) they
are supported.
/Jonas
How ugly! My (far from complete, but good enough to demonstrate what D
can do) ORM is far simpler than that:
https://github.com/mrmonday/serenity (actually a web framework, includes
an incomplete ORM)
----
struct Post
{
ulong id;
DateTime dt;
string title;
string content;
}
Persister!Post posts;
// Append a post
posts ~= Post(0, someDateTime, "A title", "Some content");
foreach (post; posts[0..5])
{
// Iterate over the first 5 posts
}
post[3] = posts[2];
----
All SQL is generated at compile time, and the backend database is called
directly - that's less overhead than you'd get from a typical scripting
language accessing a database directly (no need to convert between types
first).
Very nice. I have to give that a look for sure.
/Jonas