On Friday, 5 January 2018 at 07:40:14 UTC, Brian wrote:
auto db = new ORM;
auto users = db.select(User).where(email.like("*@hotmail.com")).limit(10);

Expression templates are a dead-end for any non-trivial queries.
You have to embrace SQL to properly use RDMS, at the cost of beginners having to learn it. There is no free lunch and the inefficient queries ppl. are running with Rails examplify what happens, when you pretend it's possible to use technology without understanding it.

I'm actively working towards a design that allows full compile-time typing with plain SQL commands. This will still take a while, but I hope we can see an alpha in 2018H1.
http://dconf.org/2016/talks/nowak.html

alias schema = AliasSeq!(User, MailAddress, Book, Lending);
DB!schema db = DB!schema(SQLite("local.db")); // connecting checks for missing/additional migrations db = DB!schema(MySQL("localhost", 3306)); // DB wrapper is driver agnostic
// Full ANSI SQL
// driver-specific functions when picking the driver at compile time
// You can always exec dynamic queries on the underlying driver

foreach (r; db.exec!(q"SQL
    SELECT u.name, m.addr, CONCAT(b.title, ';') books
    FROM users u
JOIN mail_addresses m ON m.user_id = u.id AND NOT u.can_overdraw JOIN lendings l ON l.user_id = u.id AND DATEDIFF(NOW(), l.end_date) >= 7
    JOIN books b ON b.lending_id = l.id
    WHERE b.amount < 20
    GROUP BY u.id
SQL
)
    sendMail(r.name, r.addr, r.books.splitter(';'));

More concise stuff is possible with heavy compile-time trickery (https://dpaste.dzfl.pl/cd375ac594cf) without incurring dreaded 1+N queries or even any unnecessary SELECT fields.

foreach (u; db.select!User.where!"NOT can_overdraw")
{
    sendMail(u.name, u.mail.addr, u.lendings // no 1+N here
.where!"DATEDIFF(NOW(), end_date) >= 7 AND book.amount < 20")
        .map!(l => l.book.Reminder)); // client side range API
}

This has become even more of a challenge since we plan to make it a @safe @nogc poster child.

If anyone wants to help with this project please contact me.

At the moment reworked @safe @nogc database drivers would be most helpful.
I'll soon publish a small RC, Uniq, Weak library.
Unbuffered IO foundations are already here https://github.com/MartinNowak/io, but not yet practically proven, and still lacking vibe-core scheduler/eventcore integration.

Reply via email to