@codenameryuu/adonis-lucid-soft-deletes 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +21 -44
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,16 +1,6 @@
1
- # Adonis Lucid Soft Deletes
1
+ # @codenameryuu/adonis-lucid-soft-deletes
2
2
 
3
- > Works with AdonisJS v6
4
-
5
- Docs for [AdonisJS v5](https://github.com/lookinlab/adonis-lucid-soft-deletes/tree/v1)
6
-
7
- [![npm-image]][npm-url] [![license-image]][license-url] [![typescript-image]][typescript-url]
8
-
9
- This addon adds the functionality to soft deletes Lucid Models through the `deleted_at` flag
10
-
11
- > Works with `@adonisjs/lucid@^21.1.*`
12
-
13
- Sometimes use the `deleted_at` flag for soft deletes could be not good way. More [about it](https://brandur.org/soft-deletion)
3
+ This addon adds the functionality to soft deletes Lucid Models through the `deleted_at` flag in AdonisJS 7.
14
4
 
15
5
  ## Introduction
16
6
 
@@ -24,39 +14,32 @@ as Luxon / DateTime instance.
24
14
 
25
15
  ## Installation
26
16
 
27
- Install it using `npm`, `yarn` or `pnpm`.
17
+ Install it using `npm` , `yarn` or `pnpm` .
28
18
 
29
19
  ```bash
30
- # npm
31
- npm i adonis-lucid-soft-deletes
32
-
33
- # yarn
34
- yarn add adonis-lucid-soft-deletes
35
-
36
- # pnpm
37
- pnpm add adonis-lucid-soft-deletes
20
+ yarn add @codenameryuu/adonis-lucid-soft-deletes
38
21
  ```
39
22
 
40
- After install call `configure`:
23
+ After install call `configure` :
41
24
 
42
25
  ```bash
43
- node ace configure adonis-lucid-soft-deletes
26
+ node ace configure @codenameryuu/adonis-lucid-soft-deletes
44
27
  ```
45
28
 
46
29
  ## Usage
47
30
 
48
31
  Make sure to register the provider inside `adonisrc.ts` file.
49
32
 
50
- ```ts
33
+ ```typescript
51
34
  providers: [
52
35
  // ...
53
- () => import('adonis-lucid-soft-deletes/provider'),
36
+ () => import('@codenameryuu/adonis-lucid-soft-deletes/provider'),
54
37
  ]
55
38
  ```
56
39
 
57
40
  You should add the `deleted_at` column to your database tables for models with soft deletes.
58
41
 
59
- ```ts
42
+ ```typescript
60
43
  // migrations/1234566666_users.ts
61
44
  import { BaseSchema } from '@adonisjs/lucid/schema'
62
45
 
@@ -75,7 +58,7 @@ export default class Users extends BaseSchema {
75
58
 
76
59
  ### Applying Soft Deletes to a Model
77
60
 
78
- ```ts
61
+ ```typescript
79
62
  import { compose } from '@adonisjs/core/helpers'
80
63
  import { SoftDeletes } from 'adonis-lucid-soft-deletes'
81
64
 
@@ -84,10 +67,10 @@ export default class User extends compose(BaseModel, SoftDeletes) {
84
67
  }
85
68
  ```
86
69
 
87
- Now, when you call the `.delete()` method on the model, the `deleted_at` (`customDeletedAtColumn`) column
70
+ Now, when you call the `.delete()` method on the model, the `deleted_at` ( `customDeletedAtColumn` ) column
88
71
  will be set to the current date and time. However, the model's database record will be left in the table.
89
72
 
90
- ```ts
73
+ ```typescript
91
74
  import type { HttpContext } from '@adonisjs/core/http'
92
75
  import User from '#models/user'
93
76
 
@@ -113,7 +96,7 @@ will automatically be excluded from all query results.
113
96
 
114
97
  To determine if a given model instance has been soft deleted, you may use the `.trashed` getter:
115
98
 
116
- ```ts
99
+ ```typescript
117
100
  import type { HttpContext } from '@adonisjs/core/http'
118
101
  import User from '#models/user'
119
102
 
@@ -134,7 +117,7 @@ export default class UsersController {
134
117
 
135
118
  ### Set custom column name for `deletedAt`
136
119
 
137
- ```ts
120
+ ```typescript
138
121
  import { compose } from '@adonisjs/core/helpers'
139
122
  import { SoftDeletes } from 'adonis-lucid-soft-deletes'
140
123
 
@@ -150,7 +133,8 @@ export default class User extends compose(BaseModel, SoftDeletes) {
150
133
 
151
134
  To restore a soft deleted model, you may call the `.restore()` method on a model instance.
152
135
  Also, method `.restore()` exists after methods `.withTrashed()` and `.onlyTrashed()`
153
- The `restore` method will set the model's `deleted_at` column to `null`:
136
+
137
+ The `restore` method will set the model's `deleted_at` column to `null` :
154
138
 
155
139
  ```ts
156
140
  import type { HttpContext } from '@adonisjs/core/http'
@@ -180,7 +164,7 @@ export default class TrashUsersController {
180
164
  Sometimes you may need to truly remove a model from your database.
181
165
  You may use the `.forceDelete()` method to permanently remove a soft deleted model from the database table:
182
166
 
183
- ```ts
167
+ ```typescript
184
168
  import type { HttpContext } from '@adonisjs/core/http'
185
169
  import User from '#models/user'
186
170
 
@@ -204,7 +188,7 @@ As noted above, soft deleted models will automatically be excluded from query re
204
188
  However, you may force soft deleted models to be included in a query's results
205
189
  by calling the `.withTrashed()` method on the model:
206
190
 
207
- ```ts
191
+ ```typescript
208
192
  import type { HttpContext } from '@adonisjs/core/http'
209
193
  import User from '#models/user'
210
194
 
@@ -233,7 +217,7 @@ export default class UsersController {
233
217
 
234
218
  The `.onlyTrashed()` method will retrieve **only** soft deleted models:
235
219
 
236
- ```ts
220
+ ```typescript
237
221
  import type { HttpContext } from '@adonisjs/core/http'
238
222
  import User from '#models/user'
239
223
 
@@ -250,17 +234,10 @@ export default class TrashUsersController {
250
234
 
251
235
  ### Soft Deletes methods
252
236
 
253
- Methods `.withTrashed()`, `.onlyTrashed()` and `.restore()` also available
237
+ Methods `.withTrashed()` , `.onlyTrashed()` and `.restore()` also available
254
238
  in ModelQueryBuilder for models with soft delete, example:
255
239
 
256
- ```ts
240
+ ```typescript
257
241
  await User.query().withTrashed().exec()
258
242
  await User.query().onlyTrashed().restore()
259
243
  ```
260
-
261
- [npm-image]: https://img.shields.io/npm/v/adonis-lucid-soft-deletes?logo=npm&style=for-the-badge
262
- [npm-url]: https://www.npmjs.com/package/adonis-lucid-soft-deletes
263
- [license-image]: https://img.shields.io/npm/l/adonis-lucid-soft-deletes?style=for-the-badge&color=blueviolet
264
- [license-url]: https://github.com/lookinlab/adonis-lucid-soft-deletes/blob/develop/LICENSE.md
265
- [typescript-image]: https://img.shields.io/npm/types/adonis-lucid-soft-deletes?color=294E80&label=%20&logo=typescript&style=for-the-badge
266
- [typescript-url]: https://github.com/lookinlab
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codenameryuu/adonis-lucid-soft-deletes",
3
3
  "description": "Addon for soft deletes Adonis JS 7 Lucid ORM",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "author": "codenameryuu",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/codenameryuu/adonis-lucid-soft-deletes#readme",
@@ -31,13 +31,13 @@
31
31
  "precompile": "npm run lint && npm run clean",
32
32
  "compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
33
33
  "build": "npm run compile",
34
- "quick:test": "NODE_DEBUG=\"adonis-lucid-soft-deletes\" node --enable-source-maps --loader=ts-node/esm bin/test.ts",
35
34
  "pretest": "npm run lint",
36
35
  "test": "c8 npm run quick:test",
37
36
  "typecheck": "tsc --noEmit",
38
37
  "version": "npm run build",
39
38
  "prepublishOnly": "npm run build",
40
- "release": "np"
39
+ "release": "np",
40
+ "quick:test": "NODE_DEBUG=\"adonis-lucid-soft-deletes\" node --enable-source-maps --loader=ts-node/esm bin/test.ts"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@adonisjs/assembler": "^7.7.0",