Code Monkey home page Code Monkey logo

pg-infinity-table's Introduction

pg-infinity-table

This package combines redis cache and multiple postgres database together to contain a large(infinite) tables spanning across DBs,with following features

  1. Row count partitioning.
  2. Search with inbuilt time ranges.
  3. Self Id generation or User provided Ids for primary key(user provided id limited to 20000000).
  4. Custom schema defination.
  5. Custom indexes.
  6. Normal CRUD operations.
  7. Paginated results for all calls.

Getting Started

  1. Install using npm i pg-infinity-table
  2. Require in your project. const infinityType = require('pg-infinity-table');
  3. Run postgres as local docker if required. docker run --name pg-12.4 -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=pg-infinity-meta -p 5432:5432 -d postgres:12.4-alpine
  4. Run redis as local docker if required. docker run -p 6379:6379 -itd --rm redis:latest
  5. Create 2 worker database for table across DB Eg: Infinity-1 & Infinity-2
  6. Instantiate with a postgres readers and writers and connections to redis.
  7. All done, Start using it!!.

Examples/Code snippets

  1. Initialize
const infinityTableType = require('pg-infinity-table');
const metaRedisConectionString = "redis://127.0.0.1:6379/";
const metaPGConectionString = "postgres://postgres:mysecretpassword@localhost:5432/pg-infinity-meta?application_name=perf-test";
const readConfigParams = {
    connectionString: metaPGConectionString,
    application_name: "Infinity Test",
    max: 4 //4 readers
};
const writeConfigParams = {
    connectionString: metaPGConectionString,
    application_name: "Infinity Test",
    max: 2 //2 Writer
};
const infinityDatabase = await infinityTableType(metaRedisConectionString, readConfigParams, writeConfigParams)
  1. Add Resources
const maxTablesPerResource = 1000; //Maximum Tables that will be used to create infinity tables.
const maxRowsPerTable = 100; //<-Row Partitioning
const readConfigParamsDB1 = {
    connectionString: "postgres://postgres:@localhost:5432/Infinity-1",
    application_name: "e2e Test",
    max: 4 //4 readers
};
const writeConfigParamsDB1 = {
    connectionString: "postgres://postgres:@localhost:5432/Infinity-1",
    application_name: "e2e Test",
    max: 2 //2 Writer
};
const readConfigParamsDB2 = {
    connectionString: "postgres://postgres:@localhost:5432/Infinity-2",
    application_name: "e2e Test",
    max: 4 //4 readers
};
const writeConfigParamsDB2 = {
    connectionString: "postgres://postgres:@localhost:5432/Infinity-2",
    application_name: "e2e Test",
    max: 2 //2 Writer
};
let resourceId = await infinityDatabase.registerResource(readConfigParamsDB1, writeConfigParamsDB1, maxTablesPerResource, maxRowsPerTable);
console.log("Resource Id:" + resourceId);

resourceId = await infinityDatabase.registerResource(readConfigParamsDB2, writeConfigParamsDB2, maxTablesPerResource, maxRowsPerTable);
console.log("Resource Id:" + resourceId);
  1. Create Infinity Table
const TableDefinition = [{
    "name": "time",
    "datatype": "bigint"
},
{
    "name": "tagid",
    "datatype": "integer"
},
{
    "name": "value",
    "datatype": "double",
},
{
    "name": "quality",
    "datatype": "integer"
}];

const boundlessTable = await infinityDatabase.createTable(TableDefinition);
const tableId = boundlessTable.TableIdentifier;
console.log("Table Created: " + tableId);
  1. Insert Data
let ctr = 200;
let rows = [];
while (ctr > 0) {
    rows.push({ "time": ctr, "tagid": ctr, "value": ctr, "quality": ctr })
    ctr--;
}

console.time("Insertion");
const result = await boundlessTable.insert(rows);
console.timeEnd("Insertion");
  1. Search Data
const filter = {
    "conditions": [
        {
            "name": "value",
            "operator": "=",
            "values": [
                10
            ]
        },
        {
            "name": "quality",
            "operator": "=",
            "values": [
                1
            ]
        }
    ],
    "combine": "$1:raw OR $2:raw"
}
const results = await boundlessTable.search(undefined, undefined, filter);
console.log(results);
  1. Load Existing Table
const boundlessTable = await infinityDatabase.loadTable(TypeId);

Built with

  1. Authors love for Open Source.
  2. pg-promise.
  3. ioredis.
  4. redis-scripto.

Contributions

  1. New ideas/techniques are welcomed.
  2. Raise a Pull Request.

Current Version:

0.0.1[Beta]

License

This project is contrubution to public domain and completely free for use, view LICENSE.md file for details.

pg-infinity-table's People

Contributors

lragji avatar omkar-manohar avatar vitaly-t avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.