sqlboiler icon indicating copy to clipboard operation
sqlboiler copied to clipboard

More in-depth db mapping in config

Open stverhae opened this issue 8 years ago • 2 comments

First of: congrats on this excellent library! We're looking to convert from gorm to sqlboiler and it's looking promising : )

The main issue we have is the lack of control over model generation, especially coming from a code first environment where you can define exactly which fields and relationships you want included and how they should be named.

Is there any way an optional mapping/whitelist per table could be added to the sqlboiler.toml? Much like the whitelist we have now but for fields/relationships of each table, so you can specify which fields you want included in your model. This mapping could also be used to handle custom field names (I've seen it referenced a couple of times as a fix for name collisions).

Right now we can use the QueryMod select to choose fields when querying a model, but these do not work for objects loaded trough eager loading. When working with records with large amounts of data this becomes a huge performance hit.

I would be open to contributing parts of this fix trough a PR, but first wanted to check your view on the matter first and also the status of mappings in the upcoming v3 release.

stverhae avatar Mar 12 '18 10:03 stverhae

@stverhae Well one thing to consider is this issue which should be fixed in v3: https://github.com/volatiletech/sqlboiler/issues/69

Though reading this I considered that maybe we only need user-specified mapping and instead of sqlboiler trying ascii acrobatics to rename things properly it simply detects and produces conflict errors which users have the ability to fix in a sane and specified way.

aarondl avatar Mar 12 '18 23:03 aarondl

We now have the ability to blacklist or whitelist columns per table (v3 code). This should assist. There may be possibilites where foreign keys are referencing columns or tables removed by this method that causes problems. If we find those cases we'll create bugs and solve them then.

The naming piece will be separately controlled and will be taken care of as a different issue since I didn't really see them as related or something I could intertwine. Hope this helps. I'm considering this resolved for the time being, but it may not be up to your standards. Please continue to discuss if this is insufficient.

aarondl avatar Jun 01 '18 17:06 aarondl