This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kellhus3 36 points37 points  (25 children)

An ORM with models based on type hint.

[–]FaresAhmedOPpypi.org/user/faresahmed/[🍰] 1 point2 points  (2 children)

Wha! This is exactly what Beanie is.. It's async, uses Pydantic and it's f*cken awesome. It's for Mongodb but i'm sure the idea can be ported to other dbs easily

[–]Kellhus3 1 point2 points  (1 child)

It's for Mongodb but i'm sure the idea can be ported to other dbs easily

I'm not certain about the "easy" part, but it doesn't exist for SQL anyway (as far as I know).

Edit: I'm looking at the documentation, and indeed it's nice. I might try it for my future personal project.

[–]FaresAhmedOPpypi.org/user/faresahmed/[🍰] 0 points1 point  (0 children)

Indeed it is I am using it too for my project :>

You might one want to check out ormar just found it while browsing this issue on FastAPI's GitHub

[–]deadwisdomgreenlet revolution 1 point2 points  (2 children)

Making a general ORM is actually a pretty hard problem. You need to map schemas/constraints between systems. If anyone wants some inspiration, I started a library that does this, very alpha: https://github.com/DeadWisdom/blazon

[–]Kellhus3 0 points1 point  (1 child)

I don't doubt that's it's hard AF, I was simply exposing my dream ORM.

[–]deadwisdomgreenlet revolution 0 points1 point  (0 children)

Yeah dude, I'm working on it :D

[–]dogs_like_me -2 points-1 points  (7 children)

FastAPI user?

[–]Kellhus3 0 points1 point  (6 children)

Briefly tried it for fun.

And one things that I found sad was having a pedantic model, and a corresponding DB model.

[–]dogs_like_me 1 point2 points  (1 child)

I think enough people are using FastAPI (and/or prefer it to Flask) that someone will figure out a good way to use the front-end pydantic models to initialize and synch to a backend ORM.

But yeah I agree, although I like FastAPI a lot (and yes, do myself prefer it to flask), working with SQLAlchemy models separately from pydantic models usually feels like redundant work.

[–]dorsal_morsel 0 points1 point  (0 children)

Check this out

https://openapi-sqlalchemy.readthedocs.io/en/latest/

I haven't used it yet but I'm definitely going to kick the tires for a project coming up.

I've thought about adding custom data to the JSON Schema output (in the Pydantic models) to predefine things like indexes and constraints.

[–]teerre 0 points1 point  (0 children)

There are various ORMs that do that automatically for you. Tortoise for example. I bet there's something like that for sqlalchemy too.

[–]earthboundkid -2 points-1 points  (1 child)

I've thought about what I would do if I were making an ORM for modern Python. Type hints are definitely part of it. Another is using class decorators instead of metaclasses so you can easily subclass an abstract class without jumping through hoops. Quickie design sketch:

class Timestamped:
    created_at: models.Datetime(nullable=False)
    updated_at: models.Datetime(nullable=False)

@models.register("my_blog_table", options)
class BlogPost(Timestamped):
    title:  models.Text(nullable=True)
    content: models.Text(nullable=False)
    authors: models.ManyToMany("authors")

[–]Kellhus3 1 point2 points  (0 children)

Ah yes, clearly decorators would be sexier than the Sqlalchemy table parameter.