Fork me on GitHub

Lately its getting more and more obvious that web development is indeed a basic human right. And it should be accessible to every developer in the industry. jQuery played its part by making web development easier for designers, CoffeeScript for Rubyists and Pythonistas, Dart for Java devs, ClojureScript for Lispers etc.

But what about DBAs? aren't they equally human? Should they be doomed to suffer learning all about JS and the DOM?

DOMQL is here to make web development familiar to DBAs looking for a change of career (or suffering brain-damage). With a goal of making them Feel Right At Home™.

DOMQL is not a fully-fledged programming language but a small DSL inspired by SQL aimed at easing DOM manipulation for DBAs. Quick examples to make you feel warm and fuzzy (Feel Right At Home™):

SELECT DIV FROM BODY WHERE ID='container'
UPDATE (SELECT H1 FROM (SELECT DIV FROM BODY).ALL) SET CLASS='active' WHERE CLASS='disabled'
DELETE A FROM BODY.ALL WHERE HREF LIKE "google.com" AND ROWNUM BETWEEN 5 AND 10
You had me at SELECT where is the freakin' download link? Download

Speed

Just as in transactional DBMS you can write queries that are insanely slow.

DOMQL Injection

I tried my best to bring the stuff you most adore from SQL and I thought that Injections are a must have to make you Feel Right At Home™.
Features added/removed to make injections possible:

  1. Insert `--` anywhere in the code to comment out the rest of the query.
  2. Stacking queries. You can terminate any query with `;` and start a new one.
  3. Nothing is sanitized.
DOMQL("SELECT * FROM BODY WHERE CLASS='%s' AND ROWNUM > 2", "';DROP ELEMENT BODY;-- pwned! \o/")

Embedded queries.

Just like the TODO app example above you can embed your queries inside a script element with type="text/domql" and these queries would be run as soon as the page loads. The following would add 2 divs to the body element with ids header and container respectively:

<script type="text/domql">
  INSERT INTO BODY VALUES (
    CREATE ELEMENT DIV (
      id 'header'
    ),
    CREATE ELEMENT DIV (
      id 'container'
    )
  )
</script>

Alternatively you could embed queries as templates using text/domql-tmpl script type. You could think of them as stored procedures. Templates would then be accessible from anywhere in your app using DOMQL.tmpl('tmpl-id'). The function could also be passed multiple arguments in a printf()-ish way.

<script type="text/domql-tmpl" id="hello-user">
  CREATE ELEMENT SPAN (
    class 'greetings',
    innerText 'Hello %s'
  )
</script>

DOMQL from JavaScript

DOMQL.tmpl()

Executes an embedded query template. DOMQL.tmpl('hello-user', 'Amjad')

DOMQL()

To use DOMQL in JavaScript you could you just call the DOMQL() function passing it your query and any number of arguments (just like DOMQL.tmpl).

DOMQL("UPDATE BODY SET style ='background:%s'", "red");

DOMQL.ready()

Takes a JS function and executes it when the DOM is ready for manipulation.

Queries

SELECT

SELECT [Optional function ex: COUNT(][html tags separated by a comma] FROM [a single html tag or a Query between parentheses] followed by optional where clause:
WHERE [Expression: HTML Attribute or ROWNUM [Operator: =/>/</<>/IN/BETWEEN Value(s)]] AND/OR [Other expression]...

UPDATE

UPDATE [a single html tag or a Query between parentheses] SET [single or multiple key = value separated by a comma] followed by an optional where clause.

DELETE

DELETE [html tags separated by commas] FROM [a single html tag or a Query between parentheses] followed by an optional where clause.

INSERT

INSERT INTO [a single html tag or a Query between parentheses] VALUES ( [A single Query or multiple queries separated by commas] )

CREATE

CREATE ELEMENT [a single html tag] ( [zero, one or multiple key value separated by commas] )

DROP

DROP ELEMENT [a single html tag or a Query between parentheses]

UNIONS COMING SOON...

Twitter
Email