Client-side SQL in JavaScript

Posted on
  • I've been working on a framework, SquareDB, that brings relational data storage and queries to the client. It's open-source and 100% JavaScript with no dependencies on a server. I'm not familiar with everything you can do with Espruino, but I'm guessing this technology would be useful. If you agree, please let me know how it would be useful to you. SquareDB is pre-alpha and is on GitHub

    I am also preparing to launch a Kickstarter and would be insterested in any feedback about the campaign before it launches. Preview at [dead link removed, Kickstarter launched]

  • Is there any sort of readme or documentation, or example of how to use it?

    We can't view the kickstarter page - All we can do is click a button to be notified on launch. So it's also not clear what you're planning to kickstart.

  • LokiJS uses collections and is a noSQL database. SquareDB uses a true relational structure which is 60% faster. More info and supporting tests are on the Kickstarter page. NeDB is based on a subset of Mongo, so again it works on the idea of noSQL and collections of objects - same for taffydb. alasql on the other hand is very interesting, I had not seen this one before. It does follow a very similar stategy with the biggest difference being the architecture. alasql uses string parsing and internal caching to initialize every query. SquareDB uses functional programming to allow caching of any portion of the query for reuse and there is very little string parsing to reduce overhead. I also noticed jQuery, lodash, etc being used which will hurt performance. SquareDB does not use convenience libraries to substitute for faster, native implementations. datavor seems a little less complete, albeit very fast. SQL is abstracted away so much by datavor that it doesn't let people who already know the syntax to reuse that skill. I try to write APIs that play off of what devlopers are already accustomed to.

    Documentation is pretty sparse, but the tests file shows some good implementation https://github.com/blujagu/square/blob/m­aster/test/squareDBTests.js

    I went ahead and launched the Kickstarter, so the perm link is https://www.kickstarter.com/projects/blu­jagu/squaredb

  • Looks interesting - but my first thought is: The Espruino Pico has maybe 80kB of available RAM, which has to store program code as well. Even if SquareDB fits on to it, how much space would be available for actual data storage?

    I think this is probably something that you'd want to use on the server or maybe a web browser that's connecting to an Espruino.

    If you wanted to write a tutorial on using Espruino and SquareDB, I'd be happy to have it on the site. It'd be nice to have a JS-only example of a system that could easily store and use data from remote sensors.

    Good luck with the KickStarter!

  • Thanks Gordon! Right now, SquareDB is ~35kb unpacked, but I just minified it and the size is only 9kb! I'll do my homework on the espruino and see what I can do about writing that tutorial. Can you point me in the direction of more information regarding what data from remote sensors would look like and how it can be useful? Thanks again for the direction.

    Oh, I forgot to mention in my comparison that none of those other libraries support data binding between the view and the model, but SquareDB + the SquareJS EventHub = 1 & 2 way databinding.

  • Wow, ok - so it looks like it would fit in Espruino itself! It's definitely be worth a try.

    What I was thinking was more that you might have multiple sensors with an Espruino on each, maybe reporting data back via WiFi as JSON. Probably the most simple one would be { id: "SENSOR1", temperature : 12.5 }, but you could imagine there could be humidity, co2, all kinds of stuff in there.

    So then on the server you'd want to timestamp that and store it in a database (SquareDB?) and then maybe have a web interface that searched via date range and dumped it out as a graph.

    The other thing - which would be amazingly useful for Espruino users - is to have the database running on Espruino, but able work from data on External memory. Either on SD card using the filesystem library, or via EEPROM or Flash memory. There are libraries that can access each, but flash memory is more tricky because it's paged.

    I imagine that's a lot more work, but it's something that would make SquareDB really appealing - at the moment everyone has to come up with their own solution for storing and retrieving data on Espruino.

  • Gordon, you have been the most thought provoking, forward-thinking person I've talked to about this db project, so thanks again for that! As I stated in the latest campaign update, Sensor I/O and general IoT enhancements will be my focus all weekend and throughout next week, so look for improvements in those areas soon. (Although documentation will have to wait until the campaign ends)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Client-side SQL in JavaScript

Posted by Avatar for SquareDB @SquareDB

Actions