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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cbor-db

v1.0.12

Published

An embedded database for typescript and nodejs. Built as a tiny wrapper around level using borc for encoding.

Downloads

7

Readme

Cbor-DB

Node.js%20CI Version Downloads/week License Known Vulnerabilities

An embedded database for typescript and nodejs. Built as a tiny wrapper around level using borc for encoding.

Overview

Cbor-DB is a performant database designed for embedded projects and low traffic web apps. It uses cbor for encoding instead of json which enables smaller storage size as well as storage of arbitrary blobs.

Cbor-DB is loosely based on Depot-DB, like Depot-DB, it has a different, yet familiar query language. Typescript.

In cbor-db the "where" is a function that is passed all of the documents in the db.

If the function returns true, the document is added to the collection, otherwise it is ignored. This is simple and yet performs well thanks to the use of streams.

The same goes for "sort". The sort function is passed two documents ("a" and "b") and returns a number determining which one goes first. If the sort function returns a number greater than zero "a" is at a higher index than "b", less than zero and "b" comes first. If it returns 0 they "a" and "b" equivalent.

Installation

npm i --save cbor-db

Basic Usage

import { DB } from 'cbor-db'

// Define a document type.
// All documents must have a readonly id field
// that is of type string | number
type Person = {
    id: string
    firstname: string
    lastname: string
    age: number
}

// Initialize a people database (Stored in /databases/people)
// If running in node, the directory will be created if it
// doesn't exist.
const people = DB.create<Person>('/databases/people')

// You can also create an in memory DB that
// uses memdown. Useful for development and testing.
const inMemPeope = DB.create<Person>(':mem:')

// Store some people
people.put({ id: 1, firstname: 'John', lastname: 'Doe', age: 32 })
people.put({ id: 2, firstname: 'Jane', lastname: 'Doe', age: 32 })
people.put({ id: 3, firstname: 'Tim', lastname: 'Burton', age: 59 })
people.put({ id: 4, firstname: 'Stark', lastname: 'Doe', age: 45 })

// Query people
const findPeopleOlderThan = async (age: number): Promise<Person[]> =>
    people.find({
        where: (person) => person.age > age,
    })

// Find a person by their key (rejects if person is not found)
const getPersonById = async (id: number): Promise<Person> => people.get(1)

const tryItOut = async () => {
    const found = await findPeopleOlderThan(40)
    found.forEach((p) => {
        console.log(p.firstname)
        // Tim
        // Stark
    })

    const person = await getPersonById(1)
    console.log(person.firstname) // 'John'
}

API Docs

Full API documentation can be found here