SQL Alternatives in 2022

19 augustus 2022 om 10:00 by ParTech Media - Post a comment

In the last couple of decades, the world of programming has evolved considerably. Many changes can be seen in programming languages such as C#, C++, Java, etc. 

But if there is one thing that has never changed in all these years, it has to be the importance of effective data storage and data retrieval in programming.

Whenever we talk about data storage or data retrieval, the first thing that comes to our mind is SQL. After all, it is one of the most popular querying languages currently available.

But did you know that SQL is not the only powerful querying language currently available? There are plenty more alternatives to SQL in 2022. Let’s cover a few of them in this post.

Table of contents

  1. GraphQL
  2. PRQL
  3. Gremlin
  4. N10L
  5. Conclusion

GraphQL

GraphQL was the internal querying language of Facebook that was later released as an open-source project. It is a querying language for API codes. In other words, it deals with codes that interact with different applications. 

GraphQL allows users to query what they want at runtime. It is the responsibility of the backend application to filter out what the user needs and return only the requested fields as the response. The query is just a formatted JSON of what the client wants as Output. 

GraphQL is available to integrate with .NET. When we integrate it with the .NET APIs, there will be individual endpoints to access data from the database using the code. But, while using GraphQL, a single endpoint is sufficient. Based on the request sent, appropriate response data will be sent back to the requesting client. 

For .Net API, GraphQL provides a developer tools screen (similar to Swagger) to execute the request (with or without conditions) and examine the output before it is consumed by the client.

Sample Query:

{

 me {

   name

 }

}

Output:

{

 "me":

{

   "name": "Luke Skywalker"

 }

}

PRQL

PRQL stands for Pipelined Relational Query Language. It is also pronounced as Prequel. It is considered to be a simple, open-source, pipelined, extensible, and analytical language. In this, queries are structured as a small chain of commands and compiled together to produce the desired result. This language has a friendly syntax and a flat learning curve.

Each line in this language is a meaningful command. It is also possible to comment out certain lines and generate output and uncomment them to see the difference. The software allows backward compatibility.

A simple PRQL query looks like this - 

from employees

select [id, first_name, age]

sort age

take 10

It is the equivalent of:

SELECT id, first_name, age

FROM employees

ORDER BY age

LIMIT 10

And to use joins,

from employees

join benefits [employee_id]

join side:left p=positions [id==employee_id]

select [employee_id, role, vision_coverage]

It is the equivalent of:

SELECT

  employee_id,

  role,

  vision_coverage

FROM

  employees

  JOIN benefits USING(employee_id)

  LEFT JOIN positions AS p ON id = employee_id

It is possible to incorporate functions, null handling, f-strings, and so on in this language. 

Gremlin

Gremlin is a graph traversal language developed by Apache Tinkerpop. It primarily consists of a sequence of steps.  Each step can be :

  • Map step - transforming objects into the stream
  • Filter step - removing data from the stream 
  • Side effect step - statistics computation from the stream

Unlike SQL, it does not require a separate language to query data. Instead, it takes the in-built programming language option that comes in the form of a package.

A sample gremlin query looks like this - 

g.V().match(

  as("a").out("knows").as("b"),

  as("a").out("created").as("c"),

  as("b").out("created").as("c"),

  as("c").in("created").count().is(2)).

  select("c").by("name")

N10L

N10L is also a querying language that is quite similar to SQL. N10L queries are formed with the keywords SELECT, FROM, and WHERE. This makes it very easy for SQL native users to immediately adopt this language. 

You can also use GROUP BY, and ORDER BY functions to transform the results even further. N10L also supports nested sub-queries to retrieve data.

But the difference between SQL and N10L is mainly in how the response is sent back. In SQL, the data is sent back as Dataset and Datatables, whereas in N10L, the data is sent back to the requester as JSON document.

Sample query:

SELECT name, brewery_id from sample WHERE id IS NOT MISSING LIMIT 2;

Result   {

    "requestID": "fbea9e79-a2e2-4ab8-9fdc-14e098838cc1",

    "signature": {

        "id": "json",

        "name": "json"

    },

    "results": [

        {             "id": "Data_1",

            "name": "Result name 1"

        },

        {             "id": "Data_2",

            "name": "Result name 2"

        }     ],

    "status": "success",

    "metrics": {

        "elapsedTime": "131.492184ms",

        "executionTime": "131.261322ms",

        "resultCount": 2,

        "resultSize": 205

    }

}

Conclusion

As you have seen in this post, SQL is not the only data querying language currently available for use. There are plenty of other languages(some of them are better than SQL) that you can use for your application. So go ahead and try them in your next application.

Nieuwste