Nebulous Plasma Muffin

    @web3-systems/multichain-cache
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0-beta.1 • Public • Published

    Multichain In-Memory Database

    Build Coverage Status ts GPLv3 license npm

    The @web3-systems/multichain-in-memory-database node module is an in-memory database for multichain EVM state: transactions, receipts, logs and memoized computes.

    Blockchain state is loaded into the memory for high-performance queries in both the browser and backend systems.

    To learn more about indexing, queries, DynamicViews and other database related features reference LokiJS

    💾 Installation

    Install NPM package:

    npm install @web3-systems/multichain-in-memory-database
    yarn add @web3-systems/multichain-in-memory-database

    Clone from Github:

    git clone https://github.com/web3-systems/multichain-in-memory-database

    📖 Overview

    The multichain databases/caches are managed using a MultichainInMemoryDatabase instance. The instance is an adapter for the LokiJS multi-environment, in-memory database with performant indexing and queries.

    🏎️ Quickstart

    In just a few lines a new chain database can be initialized - enabling advanced search queries in both browsers and backends.

    import MultichainInMemoryDatabase from '@web3-systems/multichain-in-memory-database';
    const chainIdDefault = 1;
    let inMemoryDatabase: MultichainInMemoryDatabase;
    inMemoryDatabase = new MultichainInMemoryDatabase(chainIdDefault);
    inMemoryDatabase.initializeDefaultCollections(chainIdDefault, 'indexeddb');
    inMemoryDatabase.insertMultiple('transactions', transactionList, chainIdDefault);
    const findQuery = {data: { $eq: '0x0' }};
    const documents = inMemoryDatabase.find('transactions', findQuery, chainIdDefault);

    🪜 Examples

    Simple Search - FindQuery

    The primary operators currently supported are:

    $eq - filter for document(s) with property of (strict) equality
    $ne - filter for document(s) with property not equal to provided value
    $aeq - filter for document(s) with property of abstract (loose) equality
    $dteq - filter for document(s) with date property equal to provided date value
    $gt - filter for document(s) with property greater than provided value
    $gte - filter for document(s) with property greater or equal to provided value
    $lt - filter for document(s) with property less than provided value
    $lte - filter for document(s) with property less than or equal to provided value
    $between - filter for documents(s) with property between provided vals.

    Find Transaction Hash

    To find a single transaction use a find query with an equal operator matching the hash.

    export interface FindQuery {
      [key: string]: any;
    }

    The FindQuery object is similar to a MongoDB find filter object.

    const findQuery = {
        hash: { 
            $eq: '0x0' 
        },
    };

    Advanced Search - ChainedQuery

    ChainedQuery Interface All inputs are optional when constucting a chained query.

    export interface ChainedQuery {
      find?: any;
      where?: any;
      simplesort?: any;
      offset?: any;
      limit?: any;
    }

    Basic ChainedQuery

    A straight-forward example is using limit and find to return the first a single transaction matching the data inputs.

    const chainedQuery = {
        limit: 1,
        find: {
            data: {
                $eq: '0x2'
            },
        },
    };
    
    const documents = inMemoryDatabase.search('transactions', chainedQuery, 1);
    /*
        [
            {
                hash: '0x0',
                data: '0x2',
            }
        ]
    */

    Complex ChainedQuery

    A straight-forward example is using limit and find to return the first a single transaction matching the data inputs.

    const chainedQuery = {
        offset: 0,
        limit: 10,
        find: {
            data: {
                $eq: '0x2'
            },
        },
        simplesort: 'blockNumber',
        where: () =>{},
    };
    
    const documents = inMemoryDatabase.search('transactions', chainedQuery, 1);
    /*
        [
            {
                hash: '0x0',
                data: '0x2',
            }
        ]
    */

    💻 Developer Experience

    The package is setup using the TSDX zero-config CLI which includes:

    • Typescript
    • Rollup
    • Jest
    • Prettier
    • ESLint

    Keywords

    none

    Install

    npm i @web3-systems/multichain-cache

    DownloadsWeekly Downloads

    2

    Version

    0.1.0-beta.1

    License

    MIT

    Unpacked Size

    101 kB

    Total Files

    47

    Last publish

    Collaborators

    • sudokames
    • kamesdev