Hands-On With Quantum Ledger Database(QLDB)
By: Salman Dabbakuti
Tags: Nodejs, Qldb, Cloud Computing, Database, AWS

Image source: Groupemiage

In the previous article, I have explained what is quantum ledger database, benefits, use-cases, and how it differs from regular databases and how it is related to the blockchain. This article is to show how to set up Amazon’s QLDB and use it in our Nodejs application as a Database. I see this as a more realistic implementation. Hopefully this guide will get you on the road to “getting started with QLDB” without too much of a headache.

Recap:

Amazon QLDB is a fully managed ledger database that provides a transparent, immutable, and cryptographically verifiable transaction log ‎owned by a central trusted authority. Amazon QLDB tracks each and every application data change and maintains a complete and verifiable history of changes over time. QLDB fits perfectly for applications that need a scalable centralized ledger database where it needs to record all the transaction history overtime with added cryptographic security.

Getting Started:

First, let’s log into AWS and open the Amazon QLDB from Services:

Then, in the QLDB Dashboard, create a ledger by clicking on “Create ledger”:

It will take around a minute to create a ledger. Once the ledger is created, click on the Query editor from the sidebar and then choose a newly created database from the Ledger dropdown.

On the left just below the ledger dropdown, you can see a list of tables created on a selected database, On the right, there is a query execution pane and just below it, there is an output pane to show the result of a query.

PartiQL: One query language for all your data:

Before going further, we should be familiar with database query language — PartiQL and why Amazon introduced it to a few of its purpose-built databases including QLDB. Amazon announced PartiQL support for its own needs to query and transform vast amounts and varieties of data — not just SQL tabular data, but also nested and semi-structured data. PartiQL has the capability to efficiently query data, regardless of where(SQL Databases or NoSQL Databases) or in what format(JSON document model or table-rows model) it is stored. Since QLDB is a No-SQL Database(Semi-SQL & Semi-NoSQL) that can store semi-structured document model data in a table-rows format, PartiQL perfectly suits to QLDB. PartiQL is backward-compatible with SQL, queries are similar to SQL. So, it can leverage current SQL developers to offer robust ways to query and manage vast amounts and varieties of data.

PartiQL Syntax:

Don’t get scared, we are not here to learn a whole new query language. as we already know, PartiQL is similar to SQL. So let’s have a quick look at PartiQL syntax for CRUD operations.

Let’s Create, Update, Read, Delete student’s marks from the database.

Create:

In order to store student marks in the database, we first need to create a table. Let’s start creating a table named “Students” with PartiQL. Here is the query to create a table

CREATE TABLE <table name> EX:

CREATE TABLE Students

Easy right?, So, now we have an empty table Students. Let’s add a student’s marks into it. Once the query succeeded, it will return a unique documentId for each document stored.