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
24.15k stars 615 forks source link

[FEATURE]: Option to insert the model name into data #713

Closed mees-van-wel closed 2 weeks ago

mees-van-wel commented 1 year ago

Describe want to want

Drizzle does not introduce data classes/model classes, instead just returning/working with simple native JS data structures (plain objects, arrays, etc.).

This is a problem when the identity of data is needed. There are lots of cases where identity is needed. Here are two cases I am currently working with:

Suggested solution

Ideally something as simple as this:

const db = drizzle(client, {
  insertModelNames: true | { fieldName: string, case: "lower" | "upper" | "pascal" }
})
L-Mario564 commented 2 weeks ago

Drizzle exposes getTableName and getTableConfig functions which can be used to identify tables:

const { name, schema } = getTableConfig(table);
const identifier = `${schema}.${name}`;

This should cover the use cases you mentioned. I'll be closing this issue; however, if you have a use case where none of the previously mentioned functions work, let me know.