lookinlab / adonis-lucid-soft-deletes Goto Github PK
View Code? Open in Web Editor NEWAddon for soft deletes AdonisJS Lucid ORM
License: MIT License
Addon for soft deletes AdonisJS Lucid ORM
License: MIT License
Hi
When using preload, I think that deleted_at should be added to all tables involved.
For example, if a link between book and author is removed, the search will still bring the link, because the deleted_at is for the Book table, I think I should add it to the author_book table as well.
A 'deletedAt' property on type 'User' cannot be assigned to the same property on base type 'LucidRow & { $forceDelete: boolean; DeletedIn: DateTime | null; read-only discarded: boolean; $getQueryFor(action: "insert", client: QueryClientContract): InsertQueryBuilderContract<...>; $getQueryFor(action: "update" | ... 1 more ... | "update", client: QueryClientContract): ModelQueryBuilderContract<...>; delete(): ...'.
After upgrading my application to AdonisJS V6, I've encountered an issue with the useTransaction()
method's type definition. In version 5, calling this method preserved the instance type, enabling IntelliSense for subsequent method calls. However, in version 6, useTransaction()
returns a type of any
, which disrupts IntelliSense and affects code clarity.
Code Example:
const product = await new Product()
.fill({ /* property values */ })
.useTransaction(trx) // Now returns `any`, affecting IntelliSense
.save();
// Here, "product" is inferred as `any`, losing type specificity
Expected Behavior:
In AdonisJS V5, useTransaction()
would return the specific type of the instance (e.g., this
), allowing for continued IntelliSense support and type safety in chained method calls.
Actual Behavior:
In AdonisJS V6, useTransaction()
returns any
, leading to a loss of IntelliSense and type safety for any subsequent chained method calls.
Additional Information:
Navigating to the definition of useTransaction()
takes me to mixin.d.ts
from SoftDeletes, unlike in V5, where it would lead to the LucidRow
interface definition in AdonisJS.
Request:
Could the type definition for useTransaction()
be adjusted to maintain the instance's type, as in V5, to support IntelliSense and enhance developer experience? Any guidance or workarounds would also be greatly appreciated.
Repository:
I created this repository with the issue: https://github.com/GustavoSabel/issue-soft-deletes-adonisjsv6
adonis core v5.5.3
Typescript
I followed the setup its not working it can't find this moduel '@ioc:Adonis/Addons/LucidSoftDeletes'
Hi,
Is it currently possible to soft delete pivot records?
Imagine I have a relationship like the following:
users
(many to many)
user_addresses
addresses
The library does work well when addresses
are soft deleted, despite the pivot relationship still being there (user.addresses
relationship is empty).
However, I would also like the pivot table record to be soft deleted as well (when calling the likes of detach
). Is that possible out of the box with this package? I couldn't find any references in the codebase for pivot
or many to many
that looked like they handle the automatic pivot model that adonis creates
Hi,
Recently I updated Adonis, Lucid, and soft-deletes to their latest versions, and now where query in preload is broken.
Following are the version updates:
@adonisjs/core ^5.5.3 → ^5.8.3
@adonisjs/lucid ^17.1.0 → ^18.0.0
adonis-lucid-soft-deletes ^1.3.3 → ^1.4.1
I get the "Cannot read properties of undefined (reading 'method')" error.
So I inspected to find the error and seems like the issue is caused by the toQuery()
method on line 32 of the following file:
https://github.com/lookinlab/adonis-lucid-soft-deletes/blob/develop/src/SoftDeletes/index.ts
Replacing const isGroupLimitQuery = query.toQuery().includes('adonis_group_limit_counter')
with
let sqlQuery = query.toSQL().toNative()
const isGroupLimitQuery = sqlQuery.sql.includes('adonis_group_limit_counter');
seem to fix the issue.
I can create a PR if that helps.
Thanks
Hello,
Can you provide a contributing guide please?
I think I found an issue and I want to verify it !
Thanks for this module !
These interfaces describe both methods as if they had no parameters:
adonis-lucid-soft-deletes/adonis-typings/querybuilder.ts
Lines 11 to 13 in 79288ec
adonis-lucid-soft-deletes/adonis-typings/mixin.ts
Lines 17 to 20 in 79288ec
But they actually have one:
adonis-lucid-soft-deletes/src/SoftDeletes/index.ts
Lines 26 to 28 in 79288ec
Prerequisites
Hello,
Using Soft deletes on a preloaded model with group limit will create an error :
const associations = await Association.query()
.preload('tags', (tags) => tags.groupLimit(3))
.paginate(page, this.PER_PAGE)
There is an error because the no retrieval of deleted items clause is added at the end of the query.
Hello, thanks for this great package. I've implemented according to your readme, and unfortunately got the below error, when trying to delete a user.
"update `users` set `updated_at` = '2021-08-19 09:27:52', `deleted_at` = 2021-08-19 09:27:52.239 +00:00 where `id` = 8 - ER_BAD_FIELD_ERROR: Unknown column '_zone' in 'field list'"
Could you please help me out with this? Thanks in advance!
My package.json
:
{
"name": "my-backend",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "node ace build --production",
"start": "node server.js",
"dev": "node ace serve --watch",
"lint": "eslint . --ext=.ts",
"format": "prettier --write ."
},
"devDependencies": {
"@adonisjs/assembler": "^5.3.2",
"adonis-preset-ts": "^2.1.0",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-adonis": "^1.3.2",
"eslint-plugin-prettier": "^3.4.0",
"pino-pretty": "^5.1.1",
"prettier": "^2.3.2",
"typescript": "^4.2.4",
"youch": "^2.2.2",
"youch-terminal": "^1.1.1"
},
"dependencies": {
"@adonisjs/core": "^5.1.9",
"@adonisjs/lucid": "^15.0.3",
"@adonisjs/repl": "^3.1.4",
"adonis-lucid-filter": "^4.0.2",
"adonis-lucid-soft-deletes": "^1.2.0",
"luxon": "^2.0.1",
"mysql": "^2.18.1",
"phc-argon2": "^1.1.2",
"proxy-addr": "^2.0.7",
"reflect-metadata": "^0.1.13",
"source-map-support": "^0.5.19"
}
}
AdonisJS app is running in docker, if that matters.
When trying to use Hook Global using the model presented in the link (https://adocasts.com/lessons/how-to-use-adonisjs-model-hooks-to-log-all-user-actions), all queries made in models that use softdelete returns the error (select * from model_with_soft_deletes...
), where it changes the real table name to model_with_soft_deletes. Any idea how I can solve it? Thank's for your time.
Steps to reproduce:
const user = await UserFactory.create();
await user.delete();
assert.isTrue(!!user.deletedAt);
assert.isTrue(user.$isDeleted);
Expected Output:
Actual Output:
Assertion Error: expected false to be true
on the assert.isTrue(user.$isDeleted);
line.Is there another expected way to check if a model is "soft deleted", or would you consider this a bug? Considering that this package replaces delete
functionality entirely, I would personally expect $isDeleted
to be true.
Hello,
When using the paginate function, the total counts the deleted record. So, in a database of 3 users with one deleted. Total will be 3 instead of 2 !
To fixed, we need to refer to the documentation
A pull request is ready to fix this issue (will be created after you accept #2) and a reproduction repository can be found here
Thanks for you works!
❯ migrated database/migrations/1698706721243_user_soft_deletes
Migrated in 1.38 s
❯ error database/seeders/development/0_User
select * from "model_with_soft_deletes" where "email" in ($1, $2, $3, $4, $5) and "model_with_soft_deletes"."deleted_at" is null for update - relation "model_with_soft_deletes" does not exist
Was I supposed to make a model for this? If so, that is not explained in your docs and the code is so heavily abstracted I can't make heads or tails of where "model_with_soft_deletes" is even coming from.
I'm also getting the same error as 16.
// set custom `deletedAt` column name
@column.dateTime({ columnName: 'customDeletedAtColumn' })
public deletedAt?: DateTime | null
public deletedAt?: DateTime | null
produces the following TypeScript error:
Property 'deletedAt' in type 'User' is not assignable to the same property in base type 'LucidRow & { $forceDelete: boolean; deletedAt: DateTime | null; readonly trashed: boolean; $getQueryFor(action: "insert", client: QueryClientContract): InsertQueryBuilderContract<...>; $getQueryFor(action: "update" | ... 1 more ... | "refresh", client: QueryClientContract): ModelQueryBuilderContract<...>; delete(): ...'.
Type 'DateTime | null | undefined' is not assignable to type 'DateTime | null'.
Type 'undefined' is not assignable to type 'DateTime | null'.ts(2416)
(property) User.deletedAt?: DateTime | null | undefined
The problem is in this two lines:
this.model
is LucidModel
and query
is a function, as well as $getColumn
is method of LucidModel
but not ModelQueryBuilderContract
. So it should be this.model.$getColumn()
.
Prerequisites
Hello, this case will delete row instead of setting deleted_at
await Categories
.query()
.whereIn('id', ids)
.delete()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.