Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loopback4-soft-delete

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loopback4-soft-delete

A loopback-next extension for soft delete feature

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.1K
increased by4.84%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 11 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc