Skip to content

Conversation

@YogiLiu
Copy link

@YogiLiu YogiLiu commented Dec 23, 2024

This feature add a decorator to create table via class-style, it's friendly to type hint.

from pypika import table_class, Table, Field, Query

@table_class('customers')
class Customer(Table):
    id = Field('id')
    first_name = Field('fname')
    last_name = Field('lname')
    phone = Field('phone')

q = Query.from_(Customer).select(Customer.id, Customer.first_name, Customer.last_name, Customer.phone)

The decorator's parameters are same as Table.__init__.

@YogiLiu YogiLiu requested a review from a team as a code owner December 23, 2024 12:11
@YogiLiu YogiLiu closed this Dec 23, 2024
@YogiLiu YogiLiu reopened this Dec 23, 2024
README.rst Outdated
customers = Table('customers')
q = Query.from_(customers).select(customers.id, customers.fname, customers.lname, customers.phone)
The table also can create via class-style:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The table also can create via class-style:
The table can also be created via class-style:

self.assertEqual('"f"', T.f.get_sql(with_alias=True, quote_char='"'))
self.assertEqual(id(T), id(T.f.table))

def test_table_with_field_and_ailas(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_table_with_field_and_ailas(self):
def test_table_with_field_and_alias(self):

Copy link
Contributor

@AzisK AzisK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. Thanks for your work. Could you resolve the conflicts and updater with master branch?

@YogiLiu YogiLiu requested a review from AzisK November 25, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants