Git Product home page Git Product logo

qldb's Introduction

QLDB Bridge for Node

This is a simplified solution of the QLDB driver for AWS

How to use

  • Import QLDB and instantiate a client
  • Run queries using execute
import QLDB from 'qldb';

const QuantumClient = new QLDB({
  accessKey,
  secretKey,
  region,
  ledger,
});

// Later in your code
const stuff = await QuantumClient.execute('SELECT * from Stuff');

Inserting Documents

To insert a document you need to convert it to ion structures as describe here. This package provides a helper to convert javascript objects and array into ion structures.

  • Import ionize from qldb
  • Pass an array or object through the function
  • Run an insert or update statement
import QLDB, { ionize } from 'qldb';

const QuantumClient = new QLDB({
  accessKey,
  secretKey,
  region,
  ledger,
});

// Later in your code
const doc = { id: 'someId', key: 'value', n: 1, fl: 1.2, obj: { s: 's' }, arr: [1, 2] };
const stuff = await QuantumClient.execute(`INSERT INTO collection ${ionize(doc)}`);

Acid Transactions

To run multiple operations within an acid transaction, use the transaction command and pass a function to it. Whatever you return from the transaction function will be the result set from the transaction operation. All data created during the transaction will return an object as it would during normal execution.

import QLDB, { ionize } from 'qldb';

const QuantumClient = new QLDB({
  accessKey,
  secretKey,
  region,
  ledger,
});

// Later in your code
const docs = [{ id: 'someId', value: '1' }, { id: 'otherId', value: '2' }];
const [doc1, doc2] = await QuantumClient.transaction((txn) => {
  const d1 = await txn.execute(`INSERT INTO collection ${ionize(docs[0])}`);
  const d2 = await txn.execute(`INSERT INTO collection ${ionize(docs[1])}`);
  return [d1, d2];
});

// NOTE: You can iterate and use a Promise.all as well if you don't care to use the output of one entry for another

Validating documents

To validate documents as described here you can use the Quantum Client's validate function. The validate function can only take a query string that returns QLDB history.

import QuantumClient from './your/configured/QLDB/instance';

const isValid = await QuantumClient.validate(`SELECT * FROM _ql_committed_Vehicle WHERE data.VIN = '1HVBBAANXWH544237'`);

qldb's People

Contributors

lepozepo avatar dependabot[bot] avatar

Stargazers

Lemuel Okoli avatar  avatar  avatar Enrique Enciso avatar shijun avatar Salman Dabbakuti  avatar Fabrice Payet avatar Jeff William avatar Alexander Barton avatar Abdourahman Jallow avatar

Watchers

James Cloos avatar  avatar Marco Becker avatar Salman Dabbakuti  avatar

Forkers

ygnr arcblock nciso

qldb's Issues

Type error: QLDB is not a constructor

Hello @Lepozepo
I set up this module for my project and when I tried to run this example snippet for querying ledger, it shoots me with below error:

Type error: QLDB is not a constructor

are sure QLDB is a constructor? or am I missing something?

Example of process.env.TEST_VALIDATION_QUERY

Hi Lepozepo!

You did an excellent job! thank you very much,
Can you provide an example of a validation query? could be any query?

Nevermind, I didn't read the docs, sorry about that, thanks again

New Feature: Simple ACID Transactions

Usage proposal:

await QLDB.transaction(async (txn) => {
  await QLDB.execute(query1, { txn });
  await QLDB.execute(query2, { txn });
  await QLDB.execute(query3, { txn });
});

Github 'About' says 'Java' not 'JavaScript'

The Github About for this repo (top right of page) says:

About
QLDB driver for node using the Java driver

It should say QLDB driver for Node.js using the JavaScript driver.

Outdated `amazon-qldb-driver-nodejs` dependency, latest version `v1.0.0` has breaking changes.

Current dependency:

"amazon-qldb-driver-nodejs": "^0.1.1-preview.2"

There are significant changes in the v1.0.0 release of the driver. It would be great if this lib could be updated to support the latest dependencies and conform to those changes as needed.

See (in order) for changes:

https://github.com/awslabs/amazon-qldb-driver-nodejs/releases/tag/v1.0.0-rc.1

https://github.com/awslabs/amazon-qldb-driver-nodejs/releases/tag/v1.0.0-rc.2

https://github.com/awslabs/amazon-qldb-driver-nodejs/releases/tag/v1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.