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

@exio.tech/crbl

v1.0.1

Published

Liner fs CR(UD) Database, without Updates(U) and Deletes(D)

Downloads

5

Readme

CRBL

CRBL is a line by line "database" without Updates and Deletes, hence the name:

C(CREATE)R(READ)BL(By Line)

What means line by line - it means each item stored in database as single line of file.

Usage

As we starting from scratch, lets create and connect to database from code:

const { CRBL } = require('crbl')

const db = await CRBL.createAndConnect('/path/to/db', {
    fileCapacity: 10, // files in store will contain max 10 lines.
    fileExtension: 'ext' // newly created files will have extension .txt
})

Note: We assume that we can use top level await. In node environment you need to create async function to execute presented examples.

Lets continue and insert items to it and query them:

// 4 synchronous calls of Insert Async operation will executed in same order,
// as if they were synchronous.
db.insert().one('1').then()
db.insert().many(['2','3']).then()
db.insert('4').then()

await db.insert(['5','6'])

const result = await db.query()
console.log(result)
// will be printed:
// {
//   queryItems: [
//     { id: 0, item: '1' },
//     { id: 1, item: '2' },
//     { id: 2, item: '3' },
//     { id: 3, item: '4' },
//     { id: 4, item: '5' },
//     { id: 5, item: '6' }
//   ],
//   lCount: 6,
//   fCount: 1
// }

Insert operations above will be executed in same order they called. This is for case when multiple write operations performed agains single file. To avoid mixing lines, we take this solution.

In the example above, first will be performed all insertes, and when final insert operation is finish, database will be queried for all lines.

You can also query concrete files in database store:

await db.insert().many(['7','8','9','10','11','12','13'])

const result = await db.query().segment(0) // query first(0 based index) file in 
console.log(result)
// will be printed:
// {
//   queryItems: [
//     { id: 0, item: '1' },
//     { id: 1, item: '2' },
//     { id: 2, item: '3' },
//     { id: 3, item: '4' },
//     { id: 4, item: '5' },
//     { id: 5, item: '6' },
//     { id: 6, item: '7' },
//     { id: 7, item: '8' },
//     { id: 8, item: '9' },
//     { id: 9, item: '10' }
//   ],
//   lCount: 13,
//   fCount: 2
// }

Or ranges of files:

const result = await db.query().segmentRange([0, 1]) // query first two files in database
console.log(result)
// will be printed:
// {
//   queryItems: [
//     { id: 0, item: '1' },
//     { id: 1, item: '2' },
//     { id: 2, item: '3' },
//     { id: 3, item: '4' },
//     { id: 4, item: '5' },
//     { id: 5, item: '6' },
//     { id: 6, item: '7' },
//     { id: 7, item: '8' },
//     { id: 8, item: '9' },
//     { id: 9, item: '10' },
//     { id: 10, item: '11' },
//     { id: 11, item: '12' },
//     { id: 12, item: '13' }
//   ],
//   lCount: 13,
//   fCount: 2
// }

You can also skip some lines and limit the result.

const result = await db.query().skip(4).limit(7) // query 7 items after 4-th line.
console.log(result)
// will be printed:
// {
//   queryItems: [
//     { id: 4, item: '5' },
//     { id: 5, item: '6' },
//     { id: 6, item: '7' },
//     { id: 7, item: '8' },
//     { id: 8, item: '9' },
//     { id: 9, item: '10' },
//     { id: 10, item: '11' }
//   ],
//   lCount: 13,
//   fCount: 2
// }

Note: Order of .skip() and .limit() calls not matter, firs will be performed skip operation and then limit.

You can also performe search operations with find method:

const result = await db.query()
    .skip(4)
    .limit(7)
    .find(line => line === '5' || line === '10') // query 7 items after 4-th line.
console.log(result)
// will be printed:
// {
//   queryItems: [ { id: 4, item: '5' }, { id: 9, item: '10' } ],
//   lCount: 13,
//   fCount: 2
// }