Most query-languages for databases are not as elegant or expressive as CSS.
Has anyone attempted to use CSS selectors as the query language for databases?
This idea lends itself naturally to document databases - let's say you have the following document:
<blogpost title="This Week's Crazy Idea">
<user name="Rasmus" class="author"/>
<body>
...
</body>
</blogpost>
In a relational database, "blogpost" and "user" would be tables, and "title" and "name" would be columns in those tables.
As for the class-attribute, in a relational database, this might be represented as a bitmask or boolean columns according to some given rule, for example, the "author" class might be represented as a "class_author" column on the "user" table.
To select blog posts, one might do something along the lines of this:
$posts = select('blogpost:has(user.author[name="Rasmus"])');
In the relational database example, this might translate to something along the lines of:
SELECT
blogpost.*, author.*
FROM
blogpost
INNER JOIN
user AS author ON author.id = blogpost.author_id
WHERE
author.name = 'Rasmus'
Of course, there are numerous problems in terms of object-relational impedance mismatch, so this idea probably lends itself best to graph and/or document databases.
Furthermore, this of course only addresses querying - I haven't yet given too much thought to whether this would somehow work for updates and projection queries.
Just throwing this idea out there... :-)
I have a much better idea: Make CSS selectors more like SQL!
...Nah just kidding. Interesting idea... :)