Earlier quoted context omitted.
A lot of people have this misconception that Pydantic models are only useful for returning API responses. This is proliferated by all-in-one frameworks like FastAPI. They are useful in and of themselves as internal business/domain objects, though. For a lot of cases I prefer lighter weight dataclasses that have less ceremony and runtime slowdown with the validation layer, but we use Pydantic models all over the place…
Pydantic models are validating. Hence their natural place is interfaces with external systems, outside the reach of your typechecker.
Show HN: Oxyde – Pydantic-native async ORM with a Rust core
81–90 of 91 posts
Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#82Why would one want to couple these two? Doesn't that couple, say, your API interface with your database schema? Whereas in reality these are separate concepts, even if, yes, sometimes you return a 'user' from an API that looks the same as the 'user' in the database? Honest question, I only just recently got into FastAPI and I was a bit confused at first that yes, it seemed like a lot of duplication, but after a littl…
A lot of people have this misconception that Pydantic models are only useful for returning API responses. This is proliferated by all-in-one frameworks like FastAPI. They are useful in and of themselves as internal business/domain objects, though. For a lot of cases I prefer lighter weight dataclasses that have less ceremony and runtime slowdown with the validation layer, but we use Pydantic models all over the place…
Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#83Earlier quoted context omitted.
Pydantic models are validating. Hence their natural place is interfaces with external systems, outside the reach of your typechecker.
dataclasses can do validation too and are faster
Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#84As a non ORM person - I do love the Pydantic functionality that comes out of the box w pyscopg3. https://www.psycopg.org/psycopg3/docs/advanced/typing.html#e...
Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#85Earlier quoted context omitted.
The two sources of truth are for two disparate adapters. Neither the API nor the DB define the domain, but both must adapt the domain to their respective implementation concerns. The ontology of your persistence layer should be entirely uncoupled from that of your API, which must accommodate an external client. In theory, anyway.
I'd rather define my db domain in-code so I do not have to worry about writing the queries without type hinting. Raw sql -> eh, I don't have the patience Raw sql w type hints -> better, I at least get a compilation error when I do something wrong, and preferably a suggestion ORM -> this usually introduces it's own abstraction that needs it's own maintenance, but at least it's more code-oriented. Yes, SQL is an awesom…
Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#86Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#87I’ve replaced about 900 lines of raw SQL and got validation and dashboard for free.
The only gotcha I ran into is that Ty didn’t recognize some of the generated types, but that’s also a young project so I’m willing to turn a blind eye.
Really solid, thank you
Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#88Earlier quoted context omitted.
Cool, that does sound like what I was after. To expand a bit on this, what I'm thinking about is a modular monolith architecture. It's also a pragmatic approach where you don't need to split into separate (micro)services yet, but you still want things to be modular and able to split later if need be. While things are still in the same monolith there's no point actually doing the serialise/deserialise step to enable i…
The way I see it, having everything as Pydantic makes this natural. Your DB model, your request schema, your response DTO are all BaseModels. Converting between them is just model_dump() and model_validate(), or plain inheritance. No adapters, no mapping layers. So when you need to split things apart, it's straightforward rather than painful.
Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#89Re: Show HN: Oxyde – Pydantic-native async ORM with a Rust core
#90Why would one want to couple these two? Doesn't that couple, say, your API interface with your database schema? Whereas in reality these are separate concepts, even if, yes, sometimes you return a 'user' from an API that looks the same as the 'user' in the database? Honest question, I only just recently got into FastAPI and I was a bit confused at first that yes, it seemed like a lot of duplication, but after a littl…
Suppose an API GET /users/:username call returns a "User" type. If returns the the same type as in your database, wouldn't you also get their password hash as well with that request? How do coupled frameworks deal with this?