What is QLDB?
What is the QLDB Repository API and why is it useful for Eclipse Dirigible projects?
What are the limitations when using QLDB?
Sign up for AWS or use an existing account.
Create an AWS Identity and Access Management (IAM) user:
dirigible_qldb_user
.Password - AWS Management Console access
and then enter your new user password in the text box.Permissions.
Set permissions
, choose Add user to group
.Create group
.dirigible_qldb_group
.Filter policies
input, search for the term qldb
.AmazonQLDBReadOnly
, AmazonQLDBFullAccess
and AmazonQLDBConsoleFullAccess
.Create group
.check box
for your new group. Choose Refresh
if necessary to see the group in the list.Next: Tags
.Next: Review
to see the list of group memberships to be added to the new user. When you are ready to proceed, choose Create user
.Notice: You can read more on how to Create an IAM user in the AWS doccumentation here.
Get an IAM access key (Used by the QLDB Driver in Eclipse Dirigible to establish connections securely).
Users
.Security credentials
tab.Access keys
section, choose Create access key
.Access key ID
and Secret access key
they will be used in the next step.Access key ID: AKIAIOSFODNN7EXAMPLE
Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Notice: You can read more on how to Get an IAM access key in the AWS documentation here.
Setup the credentials and region on the machine you are running Eclipse Dirigible.
~/.aws/credentials
, where the tilde character (~) represents your home directory:
[default]
region = eu-west-2
aws_access_key_id = your_access_key_id
aws_secret_access_key = your_secret_access_key
Notice: Replace (eu-west-2
, your_access_key_id
, your_secret_access_key
) with your credentials from the last step.
Setup a ledger:
Getting started
.Ledger information
– The Ledger name should be pre-populated with vehicle-registration
, change that to myTestLedger
.Permission mode
- choose Standard – (Recommended)
(A permissions mode that enables access control with finer granularity for ledgers, tables, and PartiQL commands.)Encrypt data at rest
– choose Use AWS owned KMS key
(Use a KMS key that is owned and managed by AWS on your behalf. This is the default option and requires no additional setup.)Create ledger
.myTestLedger
and wait for the ledger's status to become Active.Notice: You can read more on how to setup a ledger in the AWS QLDB documentation here.
releng/pom.xml
file (described in the first step of the Custom Stack documentation) with:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
### 3. Create an Eclipse Dirigible Project with AWS QLDB
- Create a new Project
- Add a `qldbSample.js` or `qldbSample.mjs` file to the project.
- Add the following content with an example usage of the QLDBRepository API to the file: </br>
:warning: <i> Notice: If you are using a `.mjs` file replace the first line with `import { QLDBRepository } from "@dirigible/qldb"`</i>
const QLDBRepository = require("qldb/QLDBRepository");
// 1. Create a repository for the ledger 'myTestLedger' that works with a table 'tableName' const qldb = new QLDBRepository("myTestLedger", "tableName");
// 2. [OPTIONAL] Create the table as it doesn't exist in your ledger, // on the next execution of this script - comment out this line or it will fail. qldb.createTable();
// 3. Insert a JS Object as a record. let inserted = qldb.insert({ email: "test@mail.com", number: 123, status: false });
// Notice: The inserted object now has a 'documentId' property, // which is the id of the record generated by QLDB console.log("Inserted entry: " + inserted);
// 4.1 Update a record inserted.email = "q@mail.com"; inserted.number = 5; inserted.status = false; let updated = qldb.update(inserted); console.log("Updated entry: " + updated);
// 4.2 [OPTIONAL] Update a record with an object // let updatedRaw = qldb.update({ // email: "text@mail.com", // number: 50000, // status: true, // documentId: "7ekJBB1FEm1EmhJBqH0WLX" // }); // Notice: Unlike insertion where the 'documentId' is generated by QLDB, // in 'update' the object must have a 'documentId' property defined // with value - a valid documentId of an entry in your table.
// 5. Get all current records in the repository. let allRecords = qldb.getAll(); console.log("allRecords: " + allRecords);
// 6.1 Delete a record let deletedId = qldb.delete(updated); console.log("Deleted entry with id: " + deletedId);
// 6.2 [OPTIONAL] Delete a record by ID // deletedId = qldb.delete(updated.documentId); // console.log("Deleted entry with id: " + deletedId);
// 7. Get array with all transactions for the table let transactionHistory = qldb.getHistory(); console.log("Transaction History:" + transactionHistory);
// 8. [OPTIONAL] Drop the table // qldb.dropTable(); // Notice: In QLDB dropping a table simply inactivates it, // you can reactivate a table that you have dropped by running // an SQL UNDROP statement in PartiQL
PartiQL editor
.Choose a ledger
dropdown select myTestLedger
.Notice: This can be useful if you want to create, delete or restore deleted tables. Read more here.