npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

orbit-db-tablestore

v0.0.15

Published

An orbit-db datastore that can be indexed and searched without downloading the entire dataset

Downloads

34

Readme

orbit-db-tablestore

Gitter npm version

An indexed and remoted loaded datastore for orbit-db. Indexed fields are searchable and sortable.

An orbit-db datastore that can be indexed and searched without downloading the entire dataset. Allows the creation of SQL-like tables. Access using ipfs-http-client.

The goal is to be able to load and search large datasets quickly in a browser.

Used in orbit-db.

Table of Contents

Install

npm install orbit-db
npm install orbit-db-tablestore
npm install ipfs-http-client

Usage

First, create an instance of OrbitDB:

const ipfsClient = require('ipfs-http-client')
const OrbitDB = require('orbit-db')
const TableStore = require('orbit-db-tablestore')


const ipfs = ipfsClient({
    host: "localhost",
    port: 5001,
    protocol: 'http'
  })

OrbitDB.addDatabaseType(TableStore.type, TableStore)

const orbitdb = await OrbitDB.createInstance(ipfs)

Creating a table

Each table starts with a schema definition. Creating a schema defines the fields and indexes that will be created in the table. Multiple columns can be indexed and searched. Each index is implemented as a B-tree.

The properties of an index are:

  • primary - This designates a column as the primary key. There should only be one.
  • type - The data type the column will hold. Supported values are 'string', 'number', and 'boolean'
  • unique - Whether the column has unique values.

To create a table we'll start by creating a JS class that has a static getter named 'constraints'. It should also contain matching properties for every contraint defined.

class Player {

    static get constraints() {
        return {
            id: { primary: true, unique:true, type: 'number' },
            name: { unique: false, type: 'string' },
            currentTeam: { unique: false, type: 'string' },
            battingHand: { unique: false, type: 'string' },
            throwingHand: { unique: false, type: 'string' }
        }
    }

    constructor() {
        this.id = null
        this.name = null
        this.currentTeam = null
        this.battingHand = null
        this.throwingHand = null
    }
    
}

/** Put in an async function **/

let table = await orbitdb.open("testschema", {
    create: true, 
    type: "table"
})


//Create the schema. Only needs to be done when creating the table initially. 
await table.createSchema(Player)

Loading an existing table

let store = await orbitdb.open(ADDRESS_OF_DATASTORE, {
    type: "table"
})

await store.load()

Insert JSON objects into the table.

 await table.put(5, {
    id: 5,
    name: "Andrew McCutchen",
    currentTeam: "PIT",
    battingHand: "R",
    throwingHand: "R"

await table.put(6, {
    id: 6,
    name: "Pedro Alvarez",
    currentTeam: "BAL",
    battingHand: "R",
    throwingHand: "R"
})

await table.put(8, {
    id: 8,
    name: "Jordy Mercer",
    currentTeam: "PIT",
    battingHand: "L",
    throwingHand: "R"
})


await table.put(9, {
    id: 9,
    name: "Doug Drabek",
    currentTeam: "BAL",
    battingHand: "L",
    throwingHand: "R"
})
  • Note: The key and the primary key values should match.

Query the table by the primary key

let player = await table.get(9)

console.log(player)

//Prints 
// {
//     id: 9,
//     name: "Doug Drabek",
//     currentTeam: "BAL",
//     battingHand: "L",
//     throwingHand: "R",
//     someOtherData: "day"
// }

Query the full list. Takes an offset and a limit as parameters


let list = await table.list(0, 10) //offset 0, limit 10

Query the table by the indexed fields. Returns an array with all matching values.


let teamPIT = await table.getByIndex("currentTeam", "PIT", 100, 0) //100 is the limit and 0 is the offset
let teamBAL = await table.getByIndex("currentTeam", "BAL", 100, 0)

let battingR = await table.getByIndex("battingHand", "R", 100, 0)
let battingL = await table.getByIndex("battingHand", "L", 100, 0)

let throwingR = await table.getByIndex("throwingHand", "R", 100, 0)    

Count the records

let count = await table.count()

Commit your changes.

Your changes are persisted to disk when you call commit(). Before commit() the store will respond with the old data when queried. Multiple calls to "put" can be made inside the same transaction.

Todo: There should be an auto-commit option somewhere.

await table.commit()

License

MIT