upper/db

Table names through reflection

dsincl12 opened this issue · 3 comments

Hi everyone,

This project really seem to fill a need I have and I'm mighty glad I stumbled upon it again :)

A quick question:

I just went through the tour and my first reaction when I saw col := sess.Collection("books") was, why isn't that handled with reflection? Any sizeable project will sooner or later end up with a typo.

It seems trivial to just use a more advanced version of:

a := model.Account{}
t := reflect.TypeOf(a)
t.Name() -> Account

But handling Pascal casing and pluralization (i.e. TaxRate -> tax_rates) etc to get the correct table names.

The result would be something like col := sess.Collection(model.Person) which would be a more type safe way to handle things.

Is there a reason why this hasn't been done or would a PR to add this be welcomed?

Keep up the good work!

I think it is inappropriate to use reflection to get the model name. I don’t think it’s a good choice to put the table prefix in the model name.

Asday commented

Django does both things to incredible success. Do you have more concrete reasoning than "I don't like it"?

You are right, a complete table name mapping should include prefix name configuration, structure name reflection, and custom table name.