public
Description: A relational database using <table> tags and jQuery
Clone URL: git://github.com/nkallen/jquery-database.git
documentation
Nick Kallen (author)
Tue Apr 08 01:02:34 -0700 2008
commit  96ed31fe17663d385749aaa5394977e3093879e8
tree    4f18a49cfe782873f62d32e1f70fa9c91c2f8d3a
parent  4e30c5e560cff3c5309169856cb6c699d3fd124e
0
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -0,0 +1,54 @@
0
+Today I was thinking aloud about [Tree Regular Expressions](http://research.microsoft.com/Users/luca/Slides/2003-11-13%20Transitions%20in%20Programming%20Models%20\(Lisbon\).pdf) and how they might make a nice query language for document databases like CouchDB. Someone pointed out that CSS3 selectors might make a great concrete syntax for this. One thing lead to another and I thought, why not build a relational database in HTML? So I did. I even got **inner joins** working.
0
+
0
+Let's start with a few tables:
0
+
0
+ <table class="users">
0
+ <tr>
0
+ <td class="id">1</td>
0
+ <td class="first_name">amy</td>
0
+ <td class="last_name">bobamy</td>
0
+ </tr>
0
+ ...
0
+ </table>
0
+ <table class="photos">
0
+ <tr>
0
+ <td class="id">1</td>
0
+ <td class="user_id">1</td>
0
+ <td class="url">http://www.example.com/foo.png</td>
0
+ </tr>
0
+ </table>
0
+
0
+Now we can express some queries:
0
+
0
+ $('.users')
0
+ .where('.id:eq(1)')
0
+ .select('*')
0
+
0
+This is equivalent to `SELECT * FROM users WHERE id = 1`
0
+
0
+ $('.users')
0
+ .where('.id:eq(1)')
0
+ .select('.id, .name')
0
+
0
+This is equivalent to `SELECT id, name FROM users WHERE id = 1`. Here is something slightly more complicated:
0
+
0
+ $('.users')
0
+ .where('.name:contains(a)')
0
+ .and('.name:contains(c)')
0
+ .select('*')
0
+
0
+But here is **the crowning glory**, the inner join:
0
+
0
+ $('.users')
0
+ .join('.photos')
0
+ .where('.photos.user_id:eq(.users.id)')
0
+ .and('.users.id:eq(1)')
0
+ .select('.photos.url')
0
+
0
+This is equivalent to:
0
+
0
+ SELECT photos.url FROM users, photos
0
+ WHERE photos.user_id = users.id
0
+ AND users.id = 1
0
+
0
+[Download the fun](http://github.com/nkallen/jquery-database/tree/master) at Github.
0
\ No newline at end of file

Comments

    No one has commented yet.