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

@nsilly/repository

v4.0.5

Published

NF Repository is a abstract layer of Sequelize Application, that make application more easy to understand and flexible to maintain.

Downloads

223

Readme

NF Repository

NF Repository is a abstract layer of Sequelize Application, that make application more easy to understand and flexible to maintain.

You want to know a little more about the Repository pattern? Read this great article.

Table of Contents

  • Installation
  • Methods
  • Usage

Installation

NPM

Execute the following command to get the latest version of the package:

npm install @nsilly/repository

If Yarn

yarn add @nsilly/repository

Methods

RepositoryInterface

  • get()
  • first()
  • paginate(limit = 20)
  • findById(id)
  • create(attributes)
  • update(attributes, id)
  • updateOrCreate(attributes, values)
  • firstOrCreate(attributes, values)
  • deleteById(id)
  • delete()
  • orderBy(column, direction = 'asc');
  • with(relation);
  • has(relation);
  • whereHas(relation, callback);
  • withScope(scope);

Usage

Create a Model

Create your Sequelize Model normally

"use strict";

module.exports = (sequelize, DataTypes) => {
  var Demo = sequelize.define(
    "demo",
    {
      name: DataTypes.STRING,
      type: DataTypes.STRING
    },
    {
      underscored: true
    }
  );

  return Demo;
};

Create a Repository

import models from "your_sequelize_model_folder";
import { Repository } from "@nsilly/repository";

export default class DemoRepository extends Repository {
  Models() {
    return models.product;
  }
}

Use methods

Find all results in Repository

const repository = new DemoRepository();
const items = await repository.get();

Find all results in Repository with pagination

const repository = new DemoRepository();
const items = await repository.paginate(10);

Find item by id

const repository = new DemoRepository();
const item = await repository.findById(123);

Loading the Model relationships

const repository = new DemoRepository();
const items = await repository.with("relation").get();

Find by result by field name

const repository = new DemoRepository();
const items = await repository.where("name", "your_name").get();

Find by result by multiple values in one field

const repository = new DemoRepository();
const items = await repository.whereIn("id", [1, 2, 3, 4, 5]).get();

Find by result by excluding multiple values in one field

const repository = new DemoRepository();
const items = await repository.whereNotIn("id", [6, 7, 8, 9, 10]).get();

Find all using custom scope

const repository = new DemoRepository();
const items = await repository
  .withScope("scope")
  .withScope("another_scope")
  .get();

Create new entry in Repository

const repository = new DemoRepository();
const item = await repository.create(attributes);

Update entry in Repository

const repository = new DemoRepository();
const item = await repository.update(attributes, id);

Delete entry in Repository

const repository = new DemoRepository();
const item = await repository.deleteById(id);

Delete entry in Repository by multiple fields

const repository = new DemoRepository();
const item = await repository
  .where("name", "item_should_be_deleted")
  .where("another_field", "another_case_should_be_deleted")
  .delete();