DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How to LINQ Between Java and SQL With JPAStreamer
  • 9 Best Free and Open Source Tools for Reporting
  • Apache Cassandra Horizontal Scalability for Java Applications [Book]
  • 5 Key Postgres Advantages Over MySQL

Trending

  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • Proactive Security in Distributed Systems: A Developer’s Approach
  • Tired of Spring Overhead? Try Dropwizard for Your Next Java Microservice
  • How to Use AWS Aurora Database for a Retail Point of Sale (POS) Transaction System
  1. DZone
  2. Data Engineering
  3. Databases
  4. AlaSQL in Action: The JavaScript SQL Database

AlaSQL in Action: The JavaScript SQL Database

Overview on AlaSQL, the popular lightweight client-side in memory SQL database, including a real life example of AlaSQL in action.

By 
Margo McCabe user avatar
Margo McCabe
·
Aug. 10, 20 · Review
Likes (4)
Comment
Save
Tweet
Share
6.9K Views

Join the DZone community and get the full member experience.

Join For Free

What’s AlaSQL?

For starters, this open-source project garners 11k weekly downloads off npm and has over 5K stars on GitHub.

I was surprised to see that there aren’t more posts about this popular lightweight client-side in-memory SQL database online apart from this awesome article I found. However, AlaSQL’s website gets straight to the point:

  • JavaScript SQL database for browser and Node.js.
  • Handles both traditional relational tables and nested JSON data (NoSQL).
  • Export, store, and import data from localStorage, IndexedDB, or Excel.

What’s not to love? AlaSQL was designed to work in browser and Node.js, is fast, and super easy to use. Some say that when you need to find data fast and want a better alternative to a full database or Redis, check out AlaSQL.

We Love AlaSQL, too!

HarperDB has had the pleasure of using AlaSQL for its backend SQL functionality. We chose to use AlaSQL because it has extensive language support, is well supported and extensible, can execute SQL against data sets (JSON or Arrays), and the ability to generate reusable functions. AlaSQL enables us to convert SQL language into an Abstract Syntax Tree (AST) that we can programmatically interpret into our data model. We can feed data into a processor that can perform the calculations native to SQL, using the functions defined in the library throughout our project as APIs and not just in the context of a SQL call.

AlaSQL is extensible and allows us to create custom functions. For example, we created a custom function called SEARCH_JSON that allows HarperDB users to search and transform nested documents. This function wraps a popular npm package called JSONata. With AlaSQL we were able to embed another open-source package as a simple function call. Our implementation was as easy as defining the function (Note this is sample code):

Java
 




x
27


 
1
const jsonata = require('jsonata');
2
/**
3
 * wrapper function that implements the JSONata library, which performs searches, transforms, etc... on JSON
4
 * @param {String} jsonata_expression - the JSONata expression to execute
5
 * @param {any} data - data which will be evaluated
6
 * @returns {any}
7
 */
8
function searchJSON(jsonata_expression, data){
9
    if(typeof jsonata_expression !== 'string' || jsonata_expression.length === 0){
10
        throw new Error('search json expression must be a non-empty string');
11
    }
12

          
13
    let alias = '__' + jsonata_expression + '__';
14

          
15
    if(hdb_utils.isEmpty(this.__ala__.res)){
16
        this.__ala__.res = {};
17
    }
18

          
19
    if(hdb_utils.isEmpty(this.__ala__.res[alias])) {
20
        let expression = jsonata(jsonata_expression);
21
        this.__ala__.res[alias] = expression;
22
    }
23
    return this.__ala__.res[alias].evaluate(data);
24
}
25
//Then define a custom function in AlaSQL:
26
const alasql = require('alasql');
27
alasql.fn.search_json = alasql.fn.SEARCH_JSON = searchJSON;



We are happy with our decision to use AlaSQL to interpret SQL into our data model and run performant queries against as much SQL as possible. That’s why we hosted the creators of AlaSQL on June 16th for a showcase to get an inside look at how AlaSQL was created, how it grew in popularity, and real-world use cases and products. It was awesome to hear from AlaSQL creators Mathias Rangel Wulff and Andrey Gershun. After Q&A on AlaSQL, our CTO Kyle Bernhardy shared more about using AlaSQL as HarperDB’s engine to interpret and parse complex SQL into our data model and perform simple to complex SQL CRUD operations, as well as exposing other libraries like Turf.js, JSONata and more.

Looking for more resources on this innovative client-side in-memory SQL database? Check out this JavaScript library designed for:

  • Fast in-memory SQL data processing for BI and ERP applications on fat clients
  • Easy ETL and options for persistence by data import/manipulation/export of several formats
  • All major browsers, Node.js, and mobile applications
sql Relational database JavaScript library Data processing Open source

Opinions expressed by DZone contributors are their own.

Related

  • How to LINQ Between Java and SQL With JPAStreamer
  • 9 Best Free and Open Source Tools for Reporting
  • Apache Cassandra Horizontal Scalability for Java Applications [Book]
  • 5 Key Postgres Advantages Over MySQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!