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

textdb

v0.3.7

Published

simple text based db

Downloads

41

Readme

textdb

Simple text based db for node.js

Project goals are:

  • in memory database, for nodejs
  • can persist data (read/write) in a simple text based format
  • support for relational data
  • completely in javascript (actually, typescript)
  • support for localstorage and use in browser (someday)

My usecase is for small (local) node applications. I want to be able to edit/read my personal data in plain text, and not having the hassle to setup a real database.

Also, if/when localStorage and browser is supported, this project may have an interest for some so-called isomorphic applications.

Status

This is a work VERY much in progress. Please don't use this in production for anything important.

  • not production ready AT ALL
  • most likely not performant for many cases (still very naive implementation)
  • all the DB data is loaded in memory.
  • no persistence so far: it can only read from a folder, but not write to it yet
  • basic implementation for update/delete operations. These operations are probably not safe (for example, no check is done to make sure the new data is valid)

Installation

With npm:

npm install textdb  --save

This package is written in typescript, and compiled for es2015. I personally use the following flags to run it:

  • --harmony: to enable general harmony features
  • --harmony-destructuring: destructuring objects
  • --harmony_default_parameters: default arguments for function parameters

In a node project, to import the main TextDB class:

var TextDB = require('textdb').default

Still not totally sure on the best way to proceed, but the 'default' part is still necessary. Someday, I will test and improve the build process.

Short User Guide

To instantiate a new empty (in memory) DB:

var TextDB = require('textdb).default

var db = new TextDB()

To add a table to the DB:

  db.createTable('accounts', {
    id: {type: 'word'},
    initialBalance: {type: 'amount'},
    description: {type: 'string'}
  })

To insert a record:

  db.insert('accounts', {id: 'current', initialBalance: 1000, description: 'main account'})
  db.insert('accounts', {id: 'savings', initialBalance: 50000, description: 'savings account'})

To query the db:

    const account = db.query('accounts', {where: c => c.initialBalance > 2000})

To update a record:

    db.update('accounts', 'current', {initialBalance: 42})

To delete a record:

    db.delete('accounts', 'current')

Note that deleting a record will fail if the record is reachable by a 'many2one' field.

Reading from a folder

A db can be created with a valid path

var db = new TextDB({path: '/path/to/my/data/folder'})

This will read all files from the folder, create the corresponding tables, and insert the records. See the test/ folder for an example.

A valid textdb folder is a folder with:

  • a __schema__.json file, which contains a description of all the tables in the database
  • a file for each of those tables, with one record per line

Fields

Basic fields

Here are the various type of fields currently supported:

  • string
  • integer
  • word
  • selection
  • date
  • amount

Relational fields

In addition to those fields, textdb currently supports:

  • many2one

Support for one2many will be added at some point.