-
-
Notifications
You must be signed in to change notification settings - Fork 678
Description
Dear Sea-orm developers, hello. I have the following requests:
I would like to request support for the following features in SeaORM, with the ability to customize related fields and implement them via macro annotations:
- Custom ID Generation
-
Support custom primary key generation rules (e.g., distributed ID).
-
Auto-populate the primary key when inserting a new record.
-
Allow customization of the primary key field name (not limited to fixed names like
id).
- Soft Delete
-
Default value
0for the soft delete field on insertion; set to1instead of performing hard delete. -
Automatically add soft delete condition (e.g.,
is_deleted = 0) to all queries by default. -
Allow customization of the soft delete field name (e.g.,
deleted,is_removeinstead ofis_deleted).
- Optimistic Locking
-
Default version value
0on insertion with validation; auto increment version by1on update and soft delete. -
Allow customization of the version field name (e.g.,
lock_versioninstead ofversion).
- Auto Field Fill & Update
-
On insert: Auto populate
created_at,created_by, set soft delete field to default0, version field to default0. -
On update: Auto increment version, populate
updated_at,updated_by. -
On soft delete: Set soft delete field to
1, increment version, populateupdated_at,updated_by. -
Allow full customization of all auto-filled fields (e.g.,
create_timeinstead ofcreated_at,operatorinstead ofcreated_by).
Preferred Implementation Approach
These features are expected to be implemented through macro annotations (attributes) on entity fields, for example:
-
#[sea_orm(primary_key, generator = "distributed_id")]for custom ID generation
-
#[sea_orm(soft_delete, default = 0, deleted_value = 1)]for soft delete field
-
#[sea_orm(optimistic_lock, default = 0)]for version field
-
#[sea_orm(auto_fill = "created_at")]/#[sea_orm(auto_fill = "updated_by")]for auto-filled fields
Use Case
These features are widely used in enterprise applications and can greatly reduce boilerplate code for data integrity, traceability, and concurrency control. Customizable fields and macro-based implementation will make the features more flexible and adaptable to different project specifications.