-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AS-695: convert database to snake case #87
Conversation
knexfile.js
Outdated
if (process.env.SNAKE_MAPPER) { | ||
test = { ...test, ...knexSnakeCaseMappers() }; | ||
development = { ...development, ...knexSnakeCaseMappers() }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this result in the case mappers always being applied? I was thinking more something like:
const mappers = process.env.SNAKE_MAPPER ? knexSnakeCaseMappers() : {};
module.exports = {
test: {
...mappers,
[settings]
},
development: {
...mappers,
[settings]
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, yours does exactly the same thing in a slightly more verbose way. I didn't see the last 2 lines 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... well in this case you wouldn't set SNAKE_MAPPER
env var when running the migration command, but I've added it to the npm script for seed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I can use your syntax to tidy it up.
@@ -30,7 +30,8 @@ module.exports = connection => { | |||
const settings = { | |||
client: 'pg', | |||
useNullAsDefault: true, | |||
connection | |||
connection, | |||
...knexSnakeCaseMappers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if we could use the knexfile here, rather than duplicating settings in 2 places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate ticket? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, it would take longer to write the ticket than to just make the change. But I see what you're saying, stay in your lane 🚗
a2c8ff4
to
5e91fce
Compare
The mapping is performed by
knexSnakeCaseMappers
, for more information see https://vincit.github.io/objection.js/#snake-case-to-camel-case-conversion.