drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Add a `column.mapWith` that applies to every query - `$onSelect`

Open
#3,174 2 comments 1 reaction 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

There are cases where a column might always be decoded in a certain way, so instead of adding `.mapWith(myMapper)` to every query, we can instead add `$onSelect` on table declaration that essentially adds `mapWith` to every query implicitly.

```ts
function decodeValue(value: number): string {
// Decode logic here...
return decoded;
}

const table = pgTable('table', {
encoded: integer().notNull().$onSelect(decodeValue)
});

const result = await db.select().from(table); // { encoded: string }[]
```

This functionality can also complement the feature request mentioned in #2870, leading to Drizzle incorporating a "global" custom encoder and decoder for certain columns.

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.