Xóa mềm trong javascript

Liên kết cần chứa id để có thể nhận định dạng dữ liệu cần xóa, liên kết này được viết dưới dạng gửi dữ liệu, hành động tới trang xử lý xử lý xóa [thực tế là điều hướng tới Bộ điều khiển xử lý dữ liệu], phương thức được

Plugin này là một nhánh rẽ từ phản đối-xóa mềm khi tác giả ngừng duy trì plugin. Vì lý do đó, dự án đã được viết lại hoàn toàn và việc sử dụng các phương pháp không dùng nữa đã được khắc phục.

yarn add objection-js-soft-delete

9

Một plugin bổ sung chức năng xóa mềm cho Phản đối. js

  • Cài đặt
  • Đăng ký plugin
  • Cách sử dụng
    • phương pháp
      • whereNotDeleted[]
      • đã xóa ở đâu[]
      • phục hồi []
      • cứngDelete[]
    • bộ lọc
      • không bị xóa
      • đã xóa
      • trong một mối quan hệ
    • Sử dụng với upsertGraph
    • Chức năng vòng đời

Cài đặt

NPM

npm i objection-js-soft-delete

sợi

yarn add objection-js-soft-delete

Đăng ký plugin

Mixin cung cấp cấu hình sau để ghi đè các tùy chọn mặc định

tên cột dọc. tên cột cho biết bản ghi có bị xóa hay không. Cột phải tồn tại trên bảng cho mô hình. Mặc định.

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

0

đã xóa Giá trị. xác định giá trị nào cho biết nếu bản ghi bị xóa. Mặc định.

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

1 [múi giờ địa phương của máy chủ]

Cũng có thể sử dụng thời gian từ cơ sở dữ liệu.

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

2

notDeletedValue. xác định giá trị nào cho biết nếu bản ghi không bị xóa. Bạn có thể đặt [và nên] tùy chọn này cùng với

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

3. Mặc định.

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

4

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

Ghi chú. Giá trị

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

3 của

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

4 sẽ dẫn đến plugin này có hành vi không mong muốn

Cách sử dụng

  • Bản ghi xóa mềm. Khi một bản ghi sẽ bị xóa thì trường đã xóa được đặt thành giá trị được chỉ định là giá trị đã xóa

npm i objection-js-soft-delete

1

phương pháp

  • whereNotDeleted[]. Chỉ trả về các bản ghi không bị xóa

npm i objection-js-soft-delete

2

  • đã xóa ở đâu[]. Chỉ trả về các bản ghi đã bị xóa

npm i objection-js-soft-delete

3

  • phục hồi []. Khôi phục bản ghi đã xóa

npm i objection-js-soft-delete

4

  • cứngDelete[]. Xóa vĩnh viễn bản ghi

npm i objection-js-soft-delete

5

bộ lọc

Bộ lọc

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

7 và

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

8 sẽ được thêm vào danh sách các bộ lọc được đặt tên cho bất kỳ mô hình nào sử dụng mixin này. Trong nội bộ, họ đang sử dụng các phương pháp

// Import objection and the plugin.

import { Model } from 'objection';

import objectionSoftDelete from 'objection-js-soft-delete';

 

// Specify the options for this plugin. This are the defaults.

const softDelete = objectionSoftDelete[{

    columnName: 'deleted_at',

    deletedValue: new Date[],

    notDeletedValue: null,

}];

 

// Inject the plugin to the model

class User extends softDelete[Model] {

  static get tableName[] {

    return 'Users';

  }

}

9 và

npm i objection-js-soft-delete

10 từ phía trên

  • không bị xóa. Chỉ trả về các bản ghi từ mối quan hệ không bị xóa

yarn add objection-js-soft-delete

0

  • đã xóa. Chỉ trả về các bản ghi từ mối quan hệ đã bị xóa

yarn add objection-js-soft-delete

1

  • Bộ lọc mối quan hệ. Một bộ lọc cũng có thể được áp dụng trực tiếp cho một mối quan hệ

yarn add objection-js-soft-delete

0

sau đó

yarn add objection-js-soft-delete

1

Sử dụng với upsertGraph

Plugin này thực sự được sinh ra từ nhu cầu xóa mềm

npm i objection-js-soft-delete

11 trong một số bảng và xóa cứng trong các bảng khác

yarn add objection-js-soft-delete

2

Chức năng vòng đời

Một vấn đề xảy ra khi thực hiện xóa mềm là lệnh gọi của bạn tới

npm i objection-js-soft-delete

12 sẽ thực sự kích hoạt các chức năng vòng đời cho

npm i objection-js-soft-delete

13, điều này có thể không được mong đợi hoặc mong muốn. Để giúp giải quyết vấn đề này, một số cờ ngữ cảnh đã được thêm vào

npm i objection-js-soft-delete

14 được chuyển vào các chức năng vòng đời để giúp phân biệt xem sự kiện đã kích hoạt [e. g. ]

npm i objection-js-soft-delete

15 là một bản cập nhật thực sự, một bản xóa mềm hoặc một bản phục hồi

Chủ Đề