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

datajson

v2.1.3

Published

Low-Level Data Manager in json file

Downloads

13

Readme

Datajson

Datajson is a data handler type bson that offers ODM environment giving all a simple and solid structure for processing.

Its structure is inspired by the Mongoose ODM. Using similar resources to handle and manipulate files type json

Init

  var datajson = require('datajson')({
    'path' : '/path/app/data',
    'modelPath' : '/path/app/model'
  });

  var model = datajson.model; // all model load

The setting options are Datajson:

  • path : Path where the files will be saved, default: dirname
  • indenting : If not required indentation for the writing of files, null, otherwise set to decimal values or '\t'. These data will be passed as the third parameter of JSON.stringify()
  • ext : json file extension, default: .json
  • modelPath : the model file path

Create a model

You can deploy directly from the file templates that are working. But for better organization suggest that write in a separate folder, with this example.

File: /model/profile.js

module.exports = function(Model){
  return new Model({
      name: 'profile',
      schema: {
          name: {
              required: true,
              type: String
          },
          description: String,
          active: {
              default: false,
              type: Boolean
          },
          categorie: {
              default: 'dev',
              type: String
          },
          birth: {
              required: true,
              type: Date
        },
        age: Number
    }
  })
}

From the model you can manipulate your bank as an MDG

Methods

These are the methods of model

  • add : Inserts a new line.
  • update : Updates values of one or more lines
  • delete : Delete a specific line
  • find : Search and returns values
  • findOne : Search and returns the first value found
  • findOne : Search and returns the first value found
  • findById : Search for a specific id
  • query : Defines a query
  • date : Sets past values for a line
  • drop : Completely removes a file
  • save : Concludes the methods add, update and remove returns a registered entity and ready for use
  • exec : Executes methods find's, return entity or object list
  • then : Used to set a callback to treatment result of the action.

Query

Logical operators

And, Or and Not

Comparison

  • $eq : Matches values that are equal to a specified value.
  • $gt : Matches values that are greater than a specified value.
  • $gte : Matches values that are greater than or equal to a specified value.
  • $lt : Matches values that are less than a specified value.
  • $lte : Matches values that are less than or equal to a specified value.
  • $in : Matches any of the values specified in an array.
  • $nin : Matches none of the values specified in an array.

Using queries

The query can be applied in the search methods, or by adding query method.

model.profile.find({"age" : { "$gt" : 18 } })

In this example we get the data from all major profiles 18 years of age. If we want to get over 18 or disabled the profile would be like this:

model.profile.find({
  "$or" : { "age" : { "$gt" : 18 }, "active" : false }
})

A more complex search:

Let's find users with the name Philippe or Martin, age less than or equal to 20 years and above 15 years. For this we will use the names regex

model.profile.find({
  "$or" : [
    {"name" : /philippe/gi},
    {"name" : /martin/gi}
  ],
  "$and" : [
    {"age" : { "$eq": 15 }},
    {"age" : { "$lte": 20 }}
  ]
})

Known bugs

Bug 1

In line 32 of /src/datajson.js you will find this:

      var model = require(path.resolve(modelPath, file))(Model).init(merge(true, defaultConfig, config))
})

But it should be like this:

      var model = require(path.resolve(modelPath, file))(Model).init(config)
})

It happens that when passing the value to the variable 'config' for some reason for me unknown variable is populated by several values which are the Model properties. The only solution I found was to pass again the merge function, so the config is not changed. Surely this is happening for some stupid of me. So if you know a solution, be sure to contribute