Insert returning api to match select columns
I have the following helpers to select the right columns and ensure I don't leak sensitive data:
However when I come to call
insert().returning()
it seems the .returning() method takes a different shape and I'll need to duplicate my objects values above from boolean true
to table.columnKey
Anyway around this duplication?
6 Replies
what's the purpose of
true
in select object? why it doesn't just contain relevant columns like in returning object?Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
the docs say to select columns you use
columnName: true

@Titan you could possibly create a conversion function that utilises both
getTableColumns(table)
(https://orm.drizzle.team/docs/goodies#get-typed-table-columns) and maybe also InferSelectModel<typeof table>
(https://orm.drizzle.team/docs/goodies#type-api)useful thanks, I wonder if that works in a Drizzle relational query "columns" option as shown in the screenshot above. The example only shows it's usage in db.select which makes me doubtful, will have to give it a go thanks
I think you will need to write an automatic mapping function
SelectColumnsToReturningColumns
, but I think you should be able to get the values needed for returning columns from getTableColumns
@Titan Here is a possible conversion function