Tori
Tori

Reputation: 1

How to 'SELECT *...' (select ALL) in Pony ORM?

community! I work with MySQL and need to 'translate' query to Pony ORM. I have a big table 'clients' with a lot of columns and my problem is to write each column in methods for work with database. So I have something like:

    @db_session
    def get_client_info_by(self, **criteria) -> Union[dict, None]:
        """Return client's info from database by specified criteria"""
        if not criteria:  # If no criteria provided, return None
            return None

        query = select(c for c in self.clients)
        for attr, value in criteria.items():  # Add filters to the query based on the criteria
            query = query.filter(lambda c: getattr(c, attr) == value)
        client = query[:]

        if client:
            client_info = {
                'id': client[0].id,
                'first_name': client[0].first_name,
                'last_name': client[0].last_name,
                'type': client[0].type,
                'language_id': client[0].language_id,
                'country_id': client[0].country_id,
                # a lot of other columns ... (about 50)
                'created_at': client[0].created_at,
                'updated_at': client[0].updated_at
            }
            return client_info
        else:
            return None

Well, I need query without writing about all columns, maybe there is query like 'SELECT * FROM ...' to get all info about client, but not only specific info.

Upvotes: 0

Views: 157

Answers (1)

noob
noob

Reputation: 86

did you tried raw SQL queries example

clients.select_by_sql('SELECT * FROM clients')

Upvotes: 1

Related Questions