Why is the syntax double in field names? #687
-
Why is the syntax: const users = pgTable('users', {
id: serial('id').primaryKey(),
fullName: text('full_name'),
phone: varchar('phone', { length: 256 }),
}); And not: const users = pgTable('users', {
id: serial().primaryKey(),
fullName: text(),
phone: varchar ({ length: 256 }),
}); |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Object keys are responsible for determining which variables you will use in your code and which keys will be inferred from the schema. Names inside type functions are responsible for the names in the database. It's useful when you want to have camelCase in your code and snake_case in the database, or even name them differently Just a small example const users = pgTable('users', {
id: serial('id').primaryKey(),
codeName: text('full_name'),
userPhone: varchar('phone', { length: 256 }),
}); But we have plans to make the string inside the column function an optional field and just use the key for the database name |
Beta Was this translation helpful? Give feedback.
-
It's useful if you need to connect between a database and a service that have different naming convention. Saying you need to connect to an already established database that has columns named like |
Beta Was this translation helpful? Give feedback.
-
Does Drizzle have an utilitu that converts incoming data from user_id to userId like its in schema? I have case now where i get data not via Drizzle but hole app is based on userId instead of user_id. Right now i just manually created new object and re-assigned |
Beta Was this translation helpful? Give feedback.
Object keys are responsible for determining which variables you will use in your code and which keys will be inferred from the schema. Names inside type functions are responsible for the names in the database. It's useful when you want to have camelCase in your code and snake_case in the database, or even name them differently
Just a small example
But we have plans to make the string inside the column function an optional field and just use the key for the database name