byteally/dbrecord

Cant set explicit table name

Closed this issue · 4 comments

Currently it doesn't seem possible to specify a custom table name because of the closed GetTableName type family. This makes using dbrecord hard with existing databases.

While I'm not an expert at type familes it seems like it should be possible to make TableName an associated type of Table and instead provide a default using the current GetTableName.

Yes aliasing the table name & column names is one of the thing i would like to fix before releasing it to hackage.
Yes, an associate type in Table class which defaults to GetTableName will help.
For column alias, we can have another associated type called ColumnNames with map of field-name to db-column names using lifted type list

I have a PR that adds the associated type for TableName. I've fixed it up and compiled my application.

That led to me stumbling into the second column aliasing issue which I haven't solved. A key part of the solution to that should be that it works with dbrecord-opaleye out of the box since the Col type provided by that package already offers a symbol to define the names of columns.

Thank you for the PR.
I have added column aliasing support. The symbol that is there in Col type is actually used for Projection and Aggregation and it has to be of same name as the field-name and hence can't be used for aliasing.
I have made the necessary change in dbrecord-opaleye also. Please let me know if this solves your issue

Sample code:
https://github.com/byteally/dbrecord/blob/master/src/Lib.hs#L59

Yea that looks good, it's opt in so that we can use the default names where possible too 😄