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

next-model-local-storage-connector

v0.4.2

Published

LocalStorage connector for next-model package.

Downloads

8

Readme

NextModelLocalStorageConnector

LocalStorage connector for NextModel package.

Build Status

Special keys for queries:

  • $and
  • $or
  • $not
  • $null
  • $notNull
  • $in
  • $notIn
  • $between
  • $notBetween
  • $eq
  • $lt
  • $lte
  • $gt
  • $gte
  • $match
  • $filter

Roadmap / Where can i contribute

See GitHub project for current progress/tasks

  • Fix Typos
  • CI is missing for some Databases
  • Add more examples
  • Add exists, join and subqueries
  • There are already some tests, but not every test case is covered.

TOC

Example

Create Connector

The constructor allows to pass an prefix or postfix.

const connector = new NextModelKnexConnector({
  prefix: 'app_',
});
const connector = new NextModelKnexConnector({
  postfix: '_test',
});
const connector = new NextModelKnexConnector({
  prefix: 'app_',
  postfix: '_test',
});

Use Connector

The connector is used to connect your models to a database.

const User = class User extends NextModel {
  static get connector() {
    return connector;
  }

  static get modelName() {
    return 'User';
  }

  static get schema() {
    return {
      id: { type: 'integer' },
      name: { type: 'string' },
    };
  }
}

Create an base model with the connector to use it with multiple models.

const BaseModel = class BaseModel extends NextModel {
  static get connector() {
    return connector;
  }
});

const User = class User extends BaseModel {
  static get modelName() {
    return 'User';
  }

  static get schema() {
    return {
      id: { type: 'integer' },
      name: { type: 'string' },
    };
  }
}

const Address = class Address extends BaseModel {
  static get modelName() {
    return 'Address';
  }

  static get schema() {
    return {
      id: { type: 'integer' },
      street: { type: 'string' },
    };
  }
}

Build Queries

This connector allows to filter the data. Samples of possible queries are listed below.

Where

An object passed as where clause will query for object property and value.

User.where({ name: 'foo' });

If the Object has multiple properties the properties are connected with and.

User.where({ name: 'foo', age: 18 });

An where query can be connected with another where or an orWhere. A second query will encapsulate the query on the topmost layer.

User.where({ name: 'foo', age: 18 }).orWhere({ name: 'bar' });

And

Special properties are starting with an $ sign. The $and property connects all values which are passed as Array with an SQL and operator.

User.where({ $and: [
  { name: 'foo' },
]});
User.where({ $and: [
  { name: 'foo' },
  { age: 18 },
]});

The special properties can also chained with other where queries.

User.where({ $and: [
  { name: 'foo' },
  { age: 18 },
]}).orWhere({ $and: [
  { name: 'bar' },
  { age: 21 },
]});

Or

The $or property works similar to the $and property and connects all values with or.

User.where({ $or: [
  { name: 'foo' },
]});
User.where({ $or: [
  { name: 'foo' },
  { name: 'bar' },
]});
User.where({ $or: [
  { name: 'foo' },
  { age: 18 },
]}).where({ $or: [
  { name: 'bar' },
  { age: 21 },
]});

Not

The child object of an $not property will be inverted.

User.where({ $not: {
  name: 'foo'
}});
User.where({ $not: {
  name: 'foo',
  age: 18,
}});
User.where({ $not: {
  name: 'foo',
  age: 18,
}}).where({ $not: {
  name: 'bar',
  age: 21,
}});

Nesting

The $and, $or and $not properties can be nested as deeply as needed.

User.where({ $not: {
  $or: [
    { name: 'foo' },
    { age: 21 },
  ],
}});
User.where({ $not: {
  $and: [
    { name: 'foo' },
    { $or: [
      { age: 18 },
      { age: 21 },
    ]},
  ],
}});

Null

The $null property checks for unset columns and takes the column name as value.

User.where({ $null: 'name' });

NotNull

The $notNull property checks if an column is set and takes the column name as value.

User.where({ $notNull: 'name' });

Equation

There are five different equation properties available.

  • $eq checks for equal
  • $lt checks for lower
  • $gt checks for greater

$lt, $gt also allows equal values.

The property needs to be an object as value with the column name as key and the equation as value.

User.where({ $lt: { age: 18 } });
User.where({ $lt: { age: 18, size: 180 } });
User.where({ $lte: { age: 18 } });
User.where({ $lte: { age: 18, size: 180 } });

In

The $in property needs an object as value with the column name as key and the Array of values as value.

User.where({ $in: {
  name: ['foo', 'bar'],
}});

If multiple properties are present they get connected by an and operator.

User.where({ $in: {
  name: ['foo', 'bar'],
  age: [18, 19, 20, 21],
}});

NotIn

$notIn works same as $in but inverts the result.

User.where({ $notIn: {
  name: ['foo', 'bar'],
}});
User.where({ $notIn: {
  name: ['foo', 'bar'],
  age: [18, 19, 20, 21],
}});

Between

The $between property needs an object as value with the column name as key and an Array with the min and max values as value.

User.where({ $between: {
  age: [18, 21],
}});

If multiple properties are present they get connected by an and operator.

User.where({ $between: {
  age: [18, 21],
  size: [160, 185],
}});

NotBetween

$notBetween works same as $between but inverts the result.

User.where({ $notBetween: {
  age: [18, 21],
}});
User.where({ $notBetween: {
  age: [18, 21],
  size: [160, 185],
}});

Match

The $match property needs an object as value with the column name as key and an regex with the min and max values as value.

User.where({ $between: {
  age: [18, 21],
}});

If multiple properties are present they get connected by an and operator.

User.where({ $between: {
  age: [18, 21],
  size: [160, 185],
}});

Filter

The $filter property allows to write custom filter queries. Pass an function to filter the items.

User.where({ $filter: (item) => {
  return ...
}});

Changelog

See history for more details.

  • 0.1.0 2017-02-25 First release compatible with NextModel 0.2.0
  • 0.2.0 2017-02-25 Added missing dependency for CI
  • 0.3.0 2017-02-25 Improved browser compatibility
  • 0.4.0 2017-02-27 Stored nextId separately
  • 0.4.1 2017-02-27 Updated next-model dependency
  • 0.4.2 2017-02-28 Updated next-model dependency