drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.22k stars 565 forks source link

[FEATURE]: Method to convert all fields to camelCase when using db.execute #2842

Open GetPsyched opened 3 weeks ago

GetPsyched commented 3 weeks ago

Describe what you want

EDIT: The casing can be fetched from the global config, as described in #2834, instead of having some arbitrary method for it.

When using db.execute, the fields remain the same case as they are in the DB; this is totally valid and acceptable. However, it would be neat to have a method on it ($toCamelCase) that converts all the fields to camelCase.

For example, running this method:

await db.execute(sql`SELECT foo_bar FROM table`);

currently outputs { foo_bar: 'some-value' }, but with something like $toCamelCase,

await db.execute(sql`SELECT foo_bar FROM table`).$toCamelCase;

it would output { fooBar: 'some-value' }.

Currently I do this manually; I wonder if the team would consider this since it's kind of subjective. Feel free to close if this is not planned.

L-Mario564 commented 3 weeks ago

This exact feature is being worked on right now: https://github.com/drizzle-team/drizzle-orm/discussions/2834

GetPsyched commented 3 weeks ago

At first glance that did seem like it directly fixes my issue, but not really.

The discussion is primarily talking about taking the camelCase column names defined in TS and convert them to snake_case for running any SQL queries. What I want is the exact opposite. When running db.execute, I want the output object to have the keys in camelCase instead of whatever case exists in the schema.

This definitely can be an extension of that discussion but as of writing, I don't see anything mentioned confirming that the opposite will also be supported.

L-Mario564 commented 3 weeks ago

The discussion is primarily talking about taking the camelCase column names defined in TS and convert them to snake_case for running any SQL queries. What I want is the exact opposite. When running db.execute, I want the output object to have the keys in camelCase instead of whatever case exists in the schema.

Oh, what you're talking about will also be supported soon, so both camelCase to snake_case and the opposite will be supported soon. This isn't mentioned in the discussion so I should've been more clear about that.

GetPsyched commented 3 weeks ago

Oh okay; was that discussed privately somewhere?

L-Mario564 commented 3 weeks ago

Oh okay; was that discussed privately somewhere?

Yes, in an internal discussion with advocates and team members.