Skip to content

Create a SQLModel class to query a MATERIALIZED VIEW #638

Closed Answered by Pk13055
Pk13055 asked this question in Questions
Discussion options

You must be logged in to vote

Solved it by using a custom class mapper! (ref.)

from datetime import datetime

from pydantic import condecimal
from sqlalchemy.orm import registry
from sqlalchemy.schema import Index
from sqlalchemy.sql import func
from sqlmodel import SQLModel, select

from ..utils.db_view import create_materialized_view

mapper_registry = registry()


class Usage(SQLModel):
    """View combining user, rate and consumption data

    NOTE: any changes to the `_Usage` schema must be reflected here
    """

    __tablename__ = "usage"

    user_id: int
    ts: datetime
    plan_id: int
    units: condecimal(max_digits=8, decimal_places=5)
    rate: condecimal(max_digits=6, decimal_places=5)
    cost: conde…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Pk13055
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
1 participant