Fix sql queries.
Use two variants of orm.