angelxmoreno / angelxmoreno/bun-sqlite-orm

[Feature]: Entity lifecycle hooks (beforeSave, afterSave, etc.)

Open
#37 0 comments 0 reactions 0 assignees View on GitHub
decorators feature lifecycle low-priority minor
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.