'Convert raw SQL query to gino ORM query

How to convert this raw SQL query to Gino ORM query?

I am using FastAPI web framework and along with it Gino ORM since it's asynchronous. I just want to know if it's possible to convert a certain query to ORM syntax.

This is the raw query that is working.

select *, coalesce(sum, 0) as count_like from 
    (select sub_group.post_owner, sum(sub_group.count_like) from 
        (SELECT "post".owner_id as post_owner, "like".owner_id as like_owner,
        COUNT("like".post_id) as count_like
        from "post"
        INNER JOIN "like" ON "post".id = "like".post_id
        GROUP BY  "post".owner_id, "like".owner_id) as sub_group
    group by sub_group.post_owner) as sub_users
right join "user" on "user".id = sub_users.post_owner
order by count_like desc

Could some one help please in convert this sql query to Gino ORM query?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source