-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Naming of columns #221
Comments
Would be nice to have this. I have an existing database with a column name called 'class'. So named the field 'class_' in the definition. But then obviously table accesses fail. So needed a workaround. Already wanted to make a view in the database to change the offending name. But then looked into the code and found this workaround:
Seems to do the job nicely, albeit a bit of a hack. |
Alas, while fetching and updating works, creating and initializing a new instance doesn't.
|
@gmos I had a quick go at fixing this issue - still need to write some more tests, but hopefully should be able to release it soon. |
|
@gmos There's a new version on PyPI which supports this feature now. Hopefully it solves your issue. This should now work: class LoraKey(Table, tablename="copy_lora_key", db=DB):
class_ = Varchar(null=False, length=1, db_column_name='class') |
There's also this approach for anyone coming across this in the future: Line 955 in 6938913
So it's: from piccolo.table import create_table_class
LoraKey = create_table_class(
class_kwargs={'tablename': 'copy_lora_key', 'db': DB},
class_members={'class': Varchar(null=False, length=1)}
) A bit harder to read, but useful in a pinch. |
Just installed the new version. Works perfectly. Thnx. |
Discussed in #206
Allow
Table
columns to map to database columns with different names.For example:
In the example above, when doing queries, you will use
MyTable.name
, but the actual column in the database is calledperson_name
.This is useful when using Piccolo on legacy databases with non-ideal column names.
The text was updated successfully, but these errors were encountered: