Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Is it possible to use SQLAlchemy mappers (or similar)? #238

@petedmarsh

Description

@petedmarsh

Is there a way to automatically map a result row from a query to a class, something like SQLAlchemy's mappers, e.g.:

notes = sqlalchemy.Table(
    "notes",
    metadata,
    sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
    sqlalchemy.Column("text", sqlalchemy.String(length=100)),
    sqlalchemy.Column("completed", sqlalchemy.Boolean),
)

class Note:
    def __init__(self, id, ...):
         self.id = id
         # ... 

rows = await databse.fetch_all(select([notes]))

note_objects = ... # ???

note_objects == [Note(1, ...), Note(2, ...)]

For simple cases like the above I can do the mapping myself fairly easily but for complicated joins the code becomes ugly and repetitive.

For clarity, I don't want/or need a full ORM, I just want to map the database rows to some data classes for ease of use elsewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions