drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Generate values based on other columns with $default() and $onUpdate()

Open
#3,044 1 comment 35 reactions 0 assignees View on GitHub
enhancement qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

Currently, `$default($defaultFn)` and `$onUpdate()` don't have access to their adjacent insert/update values.
This would be useful for generating values based on other columns.

Example:
```TypeScript
const userEntity = pgTable('users', {
firstName: varchar('first_name').notNull(),
lastName: varchar('last_name').notNull(),
fullName: varchar('full_name')
.notNull()
.$default((insert) => {
return `${insert.firstName} ${insert.lastName}`;
})
.$onUpdate((update) => {
return `${update.firstName} ${update.lastName}`;
})
});
```

### Search
Access to other columns from `$default()`, `$defaultFn()` `$onUpdate()`
Access to neighbour columns from `$default()`, `$defaultFn()` `$onUpdate()`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.