-
-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Hey,
I'm just migrating from using schemats (https://www.npmjs.com/package/schemats) and would like to work with knex-types, but there's few features missing. I thought rather than forking and just adding it for myself I'll make this project better(?) for everyone who uses it. I hope it's fine.
First thing is an idea that sprouted from this comment. I've looked into suggested approach (asterisk argument for overrides being function taking type and name) and found there are two problems with this:
- technical - typescript doesnt allow inconsistent types, so you cannot have object Record<string, string> with special string (*) that takes function. As explained here.
- user experience - there's no way to say which types are overwrite with asterisk so we need to turn off any default formatting and ask user to provide formatting for all of the types.
But working on that I came up with (i think) better solution: another option - formatters - it's a set of optional functions that each formats different type (right now I have column, enum, enumEl(ement) and table, but im not 100% sold on these).
It would look like this:
/**
* Custom formatters for specific type of data - enum, enumEl, table and column.
*
* If any type is null/not specified default formatter for this type will be used.
*
* @example
* formatters: {
* column: (name) => kebabCase(name),
* table: (name) => upperFirst(name),
* }
*/
formatters?: {
column?: (name: string) => string;
enum?: (name: string) => string;
enumEl?: (name: string) => string;
table?: (name: string) => string;
};
I think it could solve multiple problems: columns with space formatters = { column: name =>
"${name}"}
, obviously camelCasing columns, but also escaping column namesformatters={ column: name => quoteColumnName(name)
. I think It would add a lot of freedom for users.
I rarely contribute to open source*, so I just wrote code thinking I'll go straight to pushing Pull requests... So I have few things already written. And It seems I cant push to this repo 😅
What should I do next? 🙇
*
I'd love to write more for open source projects, but Im not sure where to start and to be honest it's a bit scary.