drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Expose SQL decoder

Open
#4,203 2 comments 2 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

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

> **TL;DR** make the `SQL` class implement `DriverValueDecoder`

Right now, the `SQL` class [holds an internal decoder](https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/sql/sql.ts#L111-L112). It would result very handy to have this decoder exposed in any way, preferably by extending the `DriverValueDecoder` interface, although removing the `@internal` annotation would suffice.

This would be very helpful in building composable helpers:

```ts
function max(column: Column) {
return sql`max(${column})`.mapWith(column)
}

function coalesce(expression: SQL, defaultValue: any) {
return sql`coalesce(${expression}, ${defaultValue})`.mapWith(expression) // we would be able to pass any SQL to `.mapWith`
}

// .. later in a query
coalesce(max(table.column), 0) // would be mapped with the same decoder as `column`
```

> ⚠️ very naive implementation for illustration purposes only

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.