Closed guilhermemiuavortx closed 2 years ago
Agree with the expected behavior, but we are trying to let devs inject their own convention, not create a new convention (like 'snakeCase').
This PRs are an example: https://github.com/herbsjs/herbs2gql/pull/17 / https://github.com/herbsjs/herbs2gql/pull/18
Hello everyone!
I think that we can use a custom convention like this:
const { Repository } = require('@herbsjs/herbs2knex')
const connection = require('connection') // Knex initialize instance
const { ProductItem } = require('../domain/entities/productItem')
class YourRepository extends Repository {
constructor() {
super({
entity: ProductItem,
schema: 'main',
table: 'product_items',
ids: ['id'],
foreignKeys: [{ customerId: String }],
knex: connection,
// Configure the convention
options: {
convention: { inputNameRule: (str) => `snake_case_returned` }
}
})
}
}
Looks good.
The only thing I would change is the var name: currently it is toTableFieldName
.
The good news is that convetion is already a separated class: https://github.com/herbsjs/herbs2knex/blob/master/src/convention.js
Hi guys! I'm making progress on custom conventions for column names.
Soon I will open the PR.
Example:
//given
const anEntity = givenAnEntity()
const ItemRepository = givenAnRepositoryClass({
entity: anEntity,
table,
schema,
ids: ['id'],
knex: connection
})
const injection = {
convention: {
toTableFieldName: field => camelCaseConvention(field)
}
}
const itemRepo = new ItemRepository(injection)
//when
const ret = await itemRepo.find({ where: { stringTest: ['marie'] } })
//then
assert.deepStrictEqual(ret[0].toJSON(), {
id: 10,
stringTest: 'marie',
booleanTest: true
})
Hello @jhomarolo! Would be possible to mark this PR with a label in progress?
Hey guys!
PR #36
Is your feature request related to a problem? Please describe. Herbs2knex uses Snake case as convention for naming database table fields. But not every project uses this convention by default. In the project I'm working we use Camel Case in database table fields. Herbs2knex should be able to change conventions used by the Repository class methods.
I believe that snake case and camel case would be enough at the time.
Describe the solution you'd like