Tuesday, October 25th, 2005

JavaScript Database: In Browser

Category: Library

<p>Cory Rauch has combined the browser storage story of AMASS with the TrimPath SQL Query Engine.

What does this mean?

Cory now allows you to have storage of data in the form of JSON, in a local system, and query that storage on the client via SQL.

Say you have a datastructure such as:

Invoice  : [ { id: 1, total: 100, custId: 10 }, 
                   { id: 2, total: 200, custId: 10 }, 
                   { id: 3, total: 300, custId: 10 }, 
                   { id: 4, total: 400, custId: 20 } ],
Customer : [ { id: 10, acctBalance: 1000 }, 
                   { id: 20, acctBalance: 2000 }, 
                   { id: 30, acctBalance: 3000 } ]

you can hunt for data via:

SELECT Customer.id, Customer.acctBalance, Invoice.total
FROM Customer, Invoice
WHERE Customer.id = Invoice.custId
ORDER BY Customer.id

There is a full example on this

Where does Cory want to take this?

If these projects mature we eventually could have an even more reliable and fault tolerant generation of AJAX applications. I’m thinking one case for use would be if you are saving data on a form filled and the connection fails to the server a client side database query to store the data could take place and re-sync when the connection comes online again. The user interface could even technically still go on working as long as the UI is completely client side javascript. The details though would have to be sorted out, like syncing db keys, other issues regarding the UI being coded in Javascript (some what of a nightmare).

Another use could be cache for server side database queries, this could be used to cache the database queries happenign at the client side between the server and client lowering the amount of server requests. Or a variation on this idea of caching XML web service calls.

Related Content:

Posted by Dion Almaer at 8:20 am
17 Comments

+++--
3.9 rating from 23 votes

17 Comments »

Comments feed

Interesting bit of synergy. Local SQL access to data structures is also part of Microsoft’s MSH (nee Monad) shell. MSH isn’t destined for browsers, though (JScript is too entrenched even for them to upset the applecart), but it’s interesting to see this kind of access becoming mainstream, seeing as most people still can’t handle the boolean algebra of searches.

Comment by joelfinkle — October 25, 2005

I have been also thinking that this also could lower the cost of hosting an web application. For example lets say you host a web based RSS reader, instead of storing the rss feeds to the server you could store them to the client. This would lower the storage requirements for that application and in return make it faster too.

Comment by Cory Rauch — October 25, 2005

Intressting but I can’t see the use for it. This is a bit to much emphasis on the Javascript part of AJAX, and not enough on the XML part.

Because same thing can be achieved using XPath on XML, which can be considered as a distributed database. Create and alter XML data and sync with the “real” database when online. And this approach is not new at all.

Comment by Hakan Bilgin — October 25, 2005

Hakan, what makes this unique is that because it uses AMASS, the data is permanently stored on the client side, up to megabytes of information. You can’t do that with simple XPath + XML. Keep in mind that you could decide to not use the Trimpath SQL layer and just store XML natively into AMASS, and then use XPath as your query API.

Cory, in a few weeks I will be working on making AMASS far more reliable and simpler, and we can move along with this even more. One issue is that Trimpath is under the GPL, which makes it impossible for web pages to use.

Comment by Brad Neuberg — October 25, 2005

Hi Brad, AMASS sounds also intressting but I’m skeptical to even that. Is it really necessary? Don’t get me wrong, it sounds great with both solutions but where can they be used?

I can’t imagine regular users needing a feature like working up or edit megabyte files and synchronize these with a server. Also, I have exceeded the 64K limit with XML many times…

Brad, your blog contains much candy, I will consume them tomorrow ;-)

Cheers,
hbi

Comment by Hakan Bilgin — October 25, 2005

I have used TrimPath’s stuff in some experiments and really like it, both the sql engine and their template engine. I can see a lot of potential where we can almost go back to a stateless environment on the server by caching data on the client, either completely in javascript or in combo with AMASS approach.

Think of the resources that could be saved by not having server side state management and thus easier scalability with some environments. This would also allow applications to not timeout on the server, which could be a big plus. For example, say you have a receptionist at some office (lets say a medical office) and her appt application is web based. Well, more than likely she/he is going to keep that up and running all day long, and it would never have to timeout on th e server and she/he would never have to reopen/restart the application. Yes you could do this with DB stored sessions and such, but that isn’t the point :-)

You could also cache things such as the expected clients for the whole day on the client, along with some other data, say appt data, and the app would only have to go back to the server for updates, and searches could take place on the client.

Just food for thought.

Comment by Robert McIntosh — October 26, 2005

This seems to me a great idea! I’m looking for a way to develop an application that would run mostly off line with possible access to a server. I need a simple database (text and images) that can be accessed locally by sql.

Years ago I used Delphi and Paradox, but the application grew to several megabytes and was only usable with Windows.

What I would like to develop is an MS independant application using standard browsers and as much Open source software as possible. The combination of JS and Trimpath seems great for what I want to do. Any other suggestion? Thanks.

Comment by Boris — November 11, 2005

[...] We’ve seen in-browser SQL, a database administrator, and even a database designer. Now there’s a database monitor. AjaxMyTop presents current MySQL connections. You get a data grid showing connections, each showing ID, user, duration, and so on. Periodic Refresh ensures the connections are kept fresh, and you can easily set the refresh period in an input field. Being a true data grid, the connection list can be sorted and filtered on one or more fields. In a nice touch, the column heading morphs to include a text input when you want to type in a filter for that column. It’s nice to see keyboard shortcuts here, certainly a feature every DBA will welcome. [...]

Pingback by Ajaxian » — January 25, 2006

Wow, Hakan seems incredibly short sighted.

Comment by pwb — February 1, 2006

Thank you for that post, I agree with you. Take Care,

Fernando Ambuero

Comment by discount office furniture — February 8, 2006

Nice format on this blog if I must say myself. Can I add that the value of good content on the web has diminished but not on your pages. Great stuff–David :-)

Comment by car insurance online quotes uk — April 4, 2006

ghnmjdghmjdghmjdghnms

Comment by thrthrthrt — April 18, 2006

[...] We’ve seen in-browser SQL, a database administrator, and even a database designer. Now there’s a database monitor… [...]

Pingback by All About Web Technologies » AjaxMyTop: MySQL Monitor — June 22, 2006

Ajax is alltogether seperate from php? I’m not sure how the two could work together is Ajax is based on JAVA. I’m not real technical, so forgive me if that is a stupid question..

Comment by attorney blogs — December 21, 2006

Nice post :)

Comment by Jacob — March 16, 2007

Why not use xml + xpath?

Comment by non-named — June 6, 2007

Try http://www.jsdb.org/tutorial.html , it looks great!

Comment by KKFC — January 10, 2009

Leave a comment

You must be logged in to post a comment.