48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import asyncio
|
|
import datetime
|
|
|
|
from sqlalchemy import select, func
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy.orm import joinedload
|
|
|
|
from backend.session import session_maker
|
|
from models import User, PaymentRecord
|
|
|
|
|
|
async def main():
|
|
session: AsyncSession = session_maker()
|
|
try:
|
|
d = datetime.date.today()
|
|
d = d.replace(day=1)
|
|
print(d)
|
|
stmt = (
|
|
select(
|
|
PaymentRecord
|
|
)
|
|
.select_from(PaymentRecord)
|
|
.options(
|
|
joinedload(
|
|
PaymentRecord.user
|
|
)
|
|
)
|
|
.where(
|
|
func.date(func.date_trunc('month', PaymentRecord.start_date)) == d,
|
|
func.date(func.date_trunc('month', PaymentRecord.end_date)) == d,
|
|
PaymentRecord.start_date == PaymentRecord.end_date,
|
|
# PaymentRecord.user_id.in_(request.user_ids)
|
|
)
|
|
)
|
|
print(stmt.compile(compile_kwargs={
|
|
'literal_binds': True
|
|
}))
|
|
query_result = (await session.scalars(stmt)).all()
|
|
print(query_result)
|
|
except Exception as e:
|
|
print(e)
|
|
await session.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(main())
|