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

dstore-js

v1.0.9

Published

A practical Storage tool

Downloads

27

Readme

dstore-js

Do you ever wish writing stuff to disk was simple? Do you ever wish it would be easy to switch between databases? Well, fret no more.

Installation

npm install dstore-js

JSON Type

import Storage from 'dstore-js'

let storage = new Storage({
        type: 'json', // sqlite, csv, ..etc
        keyValue: false,
        path: './my_storages', // default: ./storage/
    });

let store = await storage.open('my_jsons')

let jsonToSave = { 'some': 'data' }

// save json
await store.set(jsonToSave)

// get json back
let json = await store.get(0)

// get all jsons
let jsons = await store.all()

// remove json
await store.remove(0)

// delete store along with all files
await store.delete()

Mongodb

import Storage from 'dstore-js'

let storage = new Storage({
        type: 'mongodb',
        url: 'mongodb://0.0.0.0:27017',
        database: 'my_db'
    });

//Make a store object that will match a collection
let store = await storage.open(name);

// save json file
await store.set( { str: 'test', num: 123, bool: true } );

// get json file
let [ data ] = await store.get({ str: 'test' }); // { str: 'test', num: 123, bool: true }

// remove archive
await store.remove({ str: 'test' });

// get all record 
let all = await store.all();

// close connection with the db
await store.close()

// drop collection. Deletes everything!
await store.delete();

Mongodb Files

import Storage from 'dstore-js'

let storage = new Storage({
        type: 'mongoFiles',
        url: 'mongodb://0.0.0.0:27017',
        database: 'my_files'
    });

// Create a store just like Mongodb
let store = await storage.open(name);

// pdf buffer
let pdf_buffer = fs.readFileSync(fileTestDir + 'file.pdf');

// save pdf buffer
await store.set(pdf_buffer, { filename: 'buffer_file.pdf' });

// save pdf stream
await store.set(fs.createReadStream('file.pdf');, { filename: 'buffer_file.pdf' });

// save pdf from filesystem
await store.set('/path/to/file.pdf', { filename: 'buffer_file.pdf' });

// get the pdf returns an array of all the files that match the metadata
let [ data ] = await store.get({ filename: 'buffer_file.pdf' });
let {
        buffer, // <Buffer>
        metadata // { filename: 'buffer_file.pdf', uploadDate: '2024-04-08T02:29:06.376+00:00' }
} = data;
                                       
// remove pdf file or any other files that match the metadata
await store.remove({ filename: 'buffer_file.pdf' });

// get all record metadata 
let all = await store.all();

// Close client connection
await store.close()

// drop collection
await store.delete();

Mongofiles ables the ability to easily set and get values from MongoDB via Gridfs.

The input for the file is in the form of a Buffer, Readble Stream, or String, path to the file in os for the first parameter.

The second parameter is an object which must contain the property filename, and any additional metadata you might want to add. ;)

The output will always be of the form:

{
        buffer: <Buffer>
        metadata: {
                filename: <String>
                other_properties: <any>
                ...
        }
}

Where the Metadata is the same as defined in the input and must have the filename property.

Note: You can use the Mongodb store with the MongoFile store on the same database

Note: Mutiple files can have the same filename, though this is not recommended and should be enforced by the user. (that means you)

Options

new Storage({
  type, // type of db to be used. ex: json, cvs, sqlite,               
  path, // path where to store the db                   
  keyValue, // are we using a keyvalue pair to store data?  default: false           
  mutex, // use a mutex to avoid collisions? default: true
  url, // used of Mongodb and other network dbs
  database, // used of db like mongo
  })