Regal: An SQL relational algebra builder
Dylan Knutson via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Thu May 15 17:29:42 PDT 2014
Hi all,
I'd like to announce the initial version of Regal, an SQL
relational algebra builder for D. It's intended as a backbone for
a relational database ORM, in line with how Arel works with
Rails' ActiveRecord, but nearly any project that generates SQL
dynamically can benefit from it. The goal of the library is to
make programmatically generating queries simple (and more robust
than simple string concatenation), and to be database agnostic
(it's very easy to write database specific printers for a Regal
AST).
There are extensive examples available in the Readme about how to
use the library, from generating very simple queries (SELECT *
FROM users) to multiple chained joins and nested constraints.
Here's an example from the documentation: finding a user with ID
1:
```
auto users = new Table(
"users", // table name
"id", // the rest are columns
"name",
"created_at",
"updated_at");
// SELECT * FROM users WHERE users.id = 1 LIMIT 1
users
.where(users.id.eq(1))
.limit(1)
.project(new Sql("*"))
.to_sql
```
The library can be found at: https://github.com/dymk/regal
And the dub package: http://code.dlang.org/packages/regal
Please let me know if you find any bugs via the Github tracker!
Regards,
Dylan
More information about the Digitalmars-d-announce
mailing list