Coder Social home page Coder Social logo

mayank-sfin571 / loopback4-soft-delete Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sourcefuse/loopback4-soft-delete

0.0 0.0 0.0 456 KB

A loopback4 extension for soft delete feature

License: MIT License

JavaScript 2.45% TypeScript 97.55%

loopback4-soft-delete's Introduction

loopback4-soft-delete

LoopBack

Node version Dependencies Status Loopback Core Version Loopback Build Version npm vulnerabilities

Latest version License Downloads Total Downloads

Install

npm install loopback4-soft-delete

Quick Starter

For a quick starter guide, you can refer to our loopback 4 starter application which utilizes this package for soft-deletes in a multi-tenant application.

Usage

Right now, this extension exports two abstract classes which are actually helping with soft delete operations.

  • SoftDeleteEntity - An abstract base class for all models which require soft delete feature. This class is a wrapper over Entity class from @loopback/repository adding a new attribute 'deleted' (boolean) to the model class. Same column is needed to be there in DB within that table. If you are using auto-migration of loopback 4, then, you may not need to do anything specific to add this column. If not, then please add this column to the DB table.
  • SoftCrudRepository - An abstract base class for all repositories which require soft delete feature. This class is going to be the one which handles soft delete operations and ensures soft deleted entries are not returned in responses at all. This class is a wrapper over DefaultCrudRepository class from @loopback/repository.

In order to use this extension in your LB4 application, please follow below steps.

  1. Extend models with SoftDeleteEntity class replacing Entity. For example,
import {model, property} from '@loopback/repository';
import {SoftDeleteEntity} from 'loopback4-soft-delete';

@model({
  name: 'users',
})
export class User extends SoftDeleteEntity {
  @property({
    type: 'number',
    id: true,
  })
  id?: number;

  // .... More properties
}
  1. Extend repositories with SoftCrudRepository class replacing DefaultCrudRepository. For example,
import {inject} from '@loopback/core';
import {SoftCrudRepository} from 'loopback4-soft-delete';

import {PgdbDataSource} from '../datasources';
import {User} from '../models';

export class UserRepository extends SoftCrudRepository<
  User,
  typeof User.prototype.id
> {
  constructor(@inject('datasources.pgdb') dataSource: PgdbDataSource) {
    super(User, dataSource);
  }
}

License

MIT

loopback4-soft-delete's People

Contributors

samarpan-b avatar bhupesh-sf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.