Comments (9)
@Muning69 What do you mean when you say "deleting two users"? What are the two users?
If you use one record to store some attributes related to two (or more) users, whatever it is, then if this record is deleted, everything stored in it will be deleted.
from vapor.
tableID | user_a | user_a_deletedAt | user_b | user_b_deletedAt
For example, in the above example, I may want to record the soft deletion time of different users separately in one record.
from vapor.
If user A performs a soft deletion, but user B does not, user B hopes to be able to request the data normally.
from vapor.
@Muning69 SQL databases are not designed for such use in principle.
from vapor.
@Muning69 You cannot delete such a “user” by querying the database, because the database operates on the entire record, and all operations (create, update, delete) are performed on the record. The deletedAt
field reflects the deletion of the entire record, not part of it.
You can delete, for example, user A
at the business logic level of your application, but at the database level this will be a record update, not a delete.
If you want to put two users in one record, then all operations on them are the responsibility of your application, not the database. In this case, manipulations with users do not correlate in any way with manipulations with records. Deleting a user is not equivalent to deleting a record, your application logic is completely separated from the database logic.
Accordingly, since you are building your own logic on top of the database logic, then you should go all the way and not use predefined fields, in particular, deletedAt
, but provide your own fields of similar purpose, and your own logic for processing them.
P.S. The meaning, purpose and benefits (if any) of this approach are completely unclear. However, it's up to you.
from vapor.
@mkll
What you said makes sense.
But I think Vapor can do better in this area.
After all, soft deletion is defined by Vapor.
We should be able to come up with a more convenient soft deletion solution in this regard.
from vapor.
@mkll
Sharing data from two users in a single record is commonly used in most cases. If adjustments can be made to this soft deletion, I believe it will become more user-friendly.
What I mean is that a certain field in the same record may be jointly owned by two users, and both parties can modify it. Therefore, if soft deletion can be defined separately, it would be more user-friendly.
from vapor.
This is probably out of scope for Fluent (since it's a Fluent concern and nothing to do with Vapor) as it requires some application knowledge and sharing data between different entities and managing conflict resolution is not something Fluent can solve without knowing any business logic. You can implement this yourself using Fluent's model lifecycle functionality which is designed exactly for use cases like this
from vapor.
What you said makes sense.
But I think Vapor can do better in this area.
After all, soft deletion is defined by Vapor.
Yes, you are right, soft deletion is an add-on to SQL, but, nevertheless, the logic of its operation lies entirely in the SQL paradigm, and the object on which actions are performed is a record, and not some entity of a higher order.
When we "soft delete", we delete the record. Being within the SQL paradigm, we cannot operate with anything that is inside a record (excluding, of course, SELECT). We work with records and only records, since a record is the standard unit of data storage in SQL databases.
(A simple analogy: the harbor crane handling standard 40ft containers in a seaport only works with containers, it cannot unload part of the container, it does not even know what is inside the container. Worse, if we set the task of “teaching” a crane to work with the contents of a container, then we will have to provide millions and billions of different variations of this content, and even then we will not cover all possible variations.)
In exactly the same way, Fluent knows nothing about which logical entities (users, in your case) are stored in the record. And he shouldn’t know, since this is not his level of responsibility.
Sharing data from two users in a single record is commonly used in most cases...
...and is solved in a traditional way for relational databases: by introducing one-to-many relationships.
We should be able to come up with a more convenient soft deletion solution in this regard
I have to repeat once again: Fluent works with database records at the SQL level and does not know (and should not know) anything about the objects that may be inside the records. A soft delete
is nothing more than a small, very lightweight addition that does not violate the principles of working with the SQL database, does not introduce any additional concepts or abstractions, and does not go beyond the SQL paradigm.
You are mistaken in thinking that the problem lies in the absence of the deletedAt
field you need. The problem is much more fundamental — there is no “command” in Fluent with which you could work with nested entities, such as your “users”. Fluent works with records and only records. Returning to your example, if you want to delete “user A” using Fluent, then you will delete the whole record in which he is located. And along with the record, you will delete “user B” too, of course.
from vapor.
Related Issues (20)
- commùit
- Double slash in URLs still breaks route matching with variable parts in vapor 4.92.0 HOT 2
- Trying to build on Ubuntu 20 with swift run and getting Building for debugging... error: emit-module command failed due to signal 9 HOT 2
- Unable to shutdown server HOT 1
- Title
- Vapor URLQueryContainer no longer supports valueless query parameters HOT 4
- Swift Vapor-Save records in Mysql JSON data type during mapping with swift get error- Could not convert MySQL data to String: <MYSQL_TYPE_JSON HOT 6
- Large, streamed request body may result in noSignalReceived preconditionFailure crash HOT 6
- Websocket shouldUpgrade() fail causes empty reply from server HOT 4
- Cannot setup a route returning `[Int: String]` HOT 7
- Log actual port when it's picked by the OS
- 'Flag' URL Query params don't decode into structs HOT 3
- HEAD response should allow non-zero Content-Length HOT 3
- Authentication Cache + Storage crash application HOT 2
- Default to `HTTPClient.shared` when possible HOT 1
- URLFormEncoder does not escape all reserved characters HOT 3
- Return 415 error if compressed request is detected, but not supported
- Crash after installing posix ELG as concurrency executor HOT 1
- Stored property '_id' of 'Sendable'-conforming class 'Todo' is mutable HOT 3
- [routes] does not split path parameter by '/' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vapor.