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

da-base

v0.0.1

Published

A flat file (json) db using lodash, and providing a mongo like interface.

Downloads

2

Readme

Build Status NPM version

Introduction

da-base is an in-memory data store. It provides access to the underlying data via a lodash like interface. The code is based on two classes DaBase and Chained. The first holds the complete data of the database and the second provides access to a single collections. Collections are typically arrays of data, but that's not an explicit limitation.

Usage

db = new DaBase({ name: 'four' })
db.save('nodes', [1,2,3,4])
  .map(function(a) { return a * 10 })
  .commit()
  .write();

The above code creates an in memory representation of the following JSON:

{
  "nodes": [ 10, 20, 30, 40 ]
}

This usage is a combination of both DaBase and Chained. DaBase#save returns a new collection with the given name and the (optional) value that is encapsulated by a Chained instance. The Chained instance provides map(), commit(), and write(). However, map() is carried out by the lodash library, while commit() and write() alter the original database. commit() updates the database with the value transformed by the Chained instance, and write() flushes the data to a JSON file.

API

DaBase

ctor(opts)
{
  dir: '...'      (optional) [default: ./files]
  file: '...'     (optional) [default: null]
  name: '...'     (optional) [default: db.json]
  json: '...'     (optional) [default: '{}']
  parse: function (optional) [default: JSON.parse]
}

From these options a location for a file must be derivable. So, either a full filename is given or one can be derived from the options as such: "{dir}/{name}.db". Or, possibly just the JSON might be provided which can be parsed using the parse function.

write(file)

Writes the underlying data as JSON to the Database file. The file name is derived from the dir and file and name options "dir/name.json" which would defaults to "file/db.json".

save(name, [val])

Save creates a collection in the Database with the given value if it is provided. If val is not provided it will be defaulted to an empty Array. Nothing limits the value to an array or object, but any value, however it results in a Chained instance that wraps the given value, and operations must take that value's type into consideration (see lodash).

load([file])

Loads the JSON found in the given file. If the filename is not provided it derives the file name from options given to the database on instantiation.

Chained

ctor(opts)
{
  data: [default: empty-array]
  name: [default: 'unknown']
  db:   [default: 'unknown']
}
commit(array)

Saves the given array to the database using the collection name when it was accessed using the DaBase.save(name,[val]) method. If the array is not given then the underlying data (as transformed by it's lodash interface) will be saved to the collection name.

write(file)

Writes the Database to file WITHOUT using the current data of the Chained instance. Typically, commit() is called prior write() to first push the data into the database and then serialize that data to file.

chainable lodash functions

Chainable lodash functions.

License

See license file.

The use and distribution terms for this software are covered by the Eclipse Public License 1.0, which can be found in the file 'license' at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.