How to create a variable with the same name as the table name?
I have my schema defined like this.
And then I have this file, where I'm trying to query the users.
Is there anyway I can reuse the name of the table? For example, const
users
?
Also, I'm new to Postgres and JS ORMs in general, coming from Entity Framework, is there a way to define the model/schema in singular terms and then the ORM rename the table to a plural form? I mean, my schema would be User and then in the database, it will be Users.
Thanks!7 Replies
The javascript name of your table can be whatever you want. The string you pass as the first parameter will end up being the actual name in the database
I've seen people suggesting naming your tables [name]Table, for example, in your case
usersTable
That'll avoid name colisions.
And in javascript, whenever you have name colisions, you can rename variables at the import like this:
But in the database, won't the table name be "usersTable". I find this a bit odd. I mean, it's a table. Why call it "sometihngTable".. Any other way to do it?
Opps, sorry..
Thank you, though. 🙂
I like to name my drizzle table variables in NameCap:
export const Users = pgTable(‘users’)…
I usually leave
User
for the type. but this is just preferenceHow can I omit the
id
though from the type so I can use later?