Relational database using jQuery and HTML tables
Here's a novel use for the HTML <TABLE> tag: storing client side database tables. Nick Kallen came up with a slick hack that uses the jQuery syntax to perform simple selects and joins on HTML tables. By using CSS3 selectors, you can easily target fields which match or contain your search terms, and Nick's jQuery-based API provides a simple query language, similar to a rudimentary SQL:
Today I was thinking aloud about Tree Regular Expressions 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.Let's start with a few tables:
<table class="users"> <tr> <td class="id">1</td> <td class="first_name">amy</td> <td class="last_name">bobamy</td> </tr> ... </table> <table class="photos"> <tr> <td class="id">1</td> <td class="user_id">1</td> <td class="url">http://www.example.com/foo.png</td> </tr> </table>Now we can express some queries:
$('.users') .where('.id:eq(1)') .select('*')This is equivalent to
SELECT * FROM users WHERE id = 1$('.users') .where('.id:eq(1)') .select('.id, .name')This is equivalent to
SELECT id, name FROM users WHERE id = 1
How cool is that? Check out Nick's blog post for an example of text search and an inner join. The API in his jquery.db.js is quite straightforward and only about 50 lines of code. Adding a sort function shouldn't be too difficult.
I'm pretty much convinced now that jQuery is black magic.
Building a relational database using jQuery and <TABLE> tags
Download the jquery.db.js library
Posted by Jason Striegel |
Apr 8, 2008 10:02 PM
Ajax, SQL, Software Engineering, Web |
Permalink
| Comments (1)
Recent Entries
- Air on the EeePC
- Relational database using jQuery and HTML tables
- Javascript marker clustering for Google Maps
- Windows Mobile del.icio.us plugin
- HOWTO - Encode any string into a trigonometric function
- Add keystroke user verification to Gnome
- Practical fluid mechanics
- Poromenos' hello world curve
- USB CapsLocker and Sun keyboard simulation
- Robosapien has a coil gun
Comments
Newest comments listed first.
| Posted by: How to display the 3 query results in the web page itself? on April 10, 2008 at 1:42 PM |
Very nice, using the output to Firebug Console.
But...from a practical angle,
what's the code to display the 3 query results
in the web page itself,
not in the Firebug Console?
(3 results displayed in the page
containing the 2 tables, "users" and "photos"...).
Thanks!
SFdude
Leave a comment
Bloggers
Welcome to the Hacks Blog!
Categories
- Ajax
- Amazon
- AppleTV
- Astronomy
- BlackBerry
- Blogging
- Body
- Cars
- Cryptography
- Data
- Education
- Electronics
- Energy
- Events
- Excel
- Excerpts
- Firefox
- Flash
- Flickr
- Flying Things
- Food
- Gaming
- Gmail
- Google Earth
- Google Maps
- Government
- Greasemonkey
- Hacks Series
- Hackszine Podcast
- Halo
- Hardware
- Home
- Home Theater
- iPhone
- iPod
- IRC
- iTunes
- Java
- Kindle
- Knoppix
- Language
- LEGO
- Life
- Lifehacker
- Linux
- Linux Desktop
- Linux Multimedia
- Linux Server
- Mac
- Mapping
- Math
- Microsoft Office
- Mind
- Mind Performance
- Mobile Phones
- Music
- MySpace
- MySQL
- NetFlix
- Network Security
- olpc
- OpenOffice
- Outdoor
- Parenting
- PDAs
- Perl
- Philosophy
- Photography
- PHP
- Pleo
- Podcast
- Podcasting
- Productivity
- PSP
- Retro Computing
- Retro Gaming
- Science
- Screencasts
- Shopping
- Skype
- Smart Home
- Software Engineering
- Sports
- SQL
- Statistics
- Survival
- TiVo
- Transportation
- Travel
- Ubuntu
- Video
- Virtualization
- Visual Studio
- VoIP
- Web
- Web Site Measurement
- Windows
- Windows Server
- Wireless
- Word
- World
- Xbox
- Yahoo!
- YouTube
Archives
Recent Posts
- Air on the EeePC
- Relational database using jQuery and HTML tables
- Javascript marker clustering for Google Maps
- Windows Mobile del.icio.us plugin
- HOWTO - Encode any string into a trigonometric function
- Add keystroke user verification to Gnome
- Practical fluid mechanics
- Poromenos' hello world curve
- USB CapsLocker and Sun keyboard simulation
- Robosapien has a coil gun
www.flickr.com
|




