angelxmoreno / angelxmoreno/bun-sqlite-orm
[Feature]: Entity lifecycle hooks (beforeSave, afterSave, etc.)
- Dominant language
- TypeScript
- Stars
- 1
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
**Problem Statement:**
Applications need to execute custom logic at specific points in entity lifecycle (validation, auditing, cache invalidation, etc.).
**Proposed Solution:**
Add decorator-based lifecycle hooks:
```typescript
@Entity('users')
export class User extends BaseEntity {
@BeforeSave()
async hashPassword() {
if (this.password && this.isChanged()) {
this.password = await bcrypt.hash(this.password, 10);
}
}
@AfterSave()
async invalidateCache() {
await cache.delete(`user:${this.id}`);
}
@BeforeDelete()
async checkDependencies() {
const postCount = await Post.count({ userId: this.id });
if (postCount > 0) {
throw new Error('Cannot delete user with existing posts');
}
}
}
```
**Lifecycle Events:**
- BeforeInsert / AfterInsert
- BeforeUpdate / AfterUpdate
- BeforeSave / AfterSave (covers both insert/update)
- BeforeDelete / AfterDelete
- BeforeLoad / AfterLoad
Contributor guide
Research direction
The issue names no files or tests; begin by locating BaseEntity and the decorator-based entity persistence path in this TypeScript/Bun ORM. Define how the listed lifecycle events should behave and add coverage for insert, update, delete, and load before considering the feature complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, typescript
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100