drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Convert rows returned by `db.execute` from SQL column name to TypeScript column name
- 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
Let's say I have a table where a column whose SQL name and TS name are different
```ts
export const users = pgTable("users", {
userId: bigint("user_id", { mode: "number" }).notNull().primaryKey(),
};
```
If I query using Drizzle's normal `select` syntax
```ts
const data = await db.select().from(users);
console.log(data.at(0));
```
the column name in the returned object is `userId` as expected.
But if I query using raw SQL
```ts
const data = await db.execute(
sql`select * from "users" where "user_id" = ${userId}`,
);
console.log(data.rows.at(0));
```
the column name is `user_id`. Now this is still expected, after all I ran a raw query and should expect a raw SQL response. But I think it would be nice to have an utility function to help auto convert between the SQL values and the TS values so I don't have to manually do
```ts
return {
userId: Number(rawValue.user_id),
displayName: rawValue.display_name,
// ...
};
```
for every column in that table.
Contributor guide
Research direction
Start by tracing the db.execute raw-query path and the pgTable schema definitions shown in the issue, focusing on where SQL column names and TypeScript names are available. Done means a utility can convert returned raw rows using those mappings, including the example user_id to userId case, without requiring manual per-column objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, sql, typescript
- Domain
- backend-api-design, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100