News for hackers. Stuff that matters.
Re:Django Styleguide by jbellew on Wednesday January 11, 2023 @12:01PM (#34340864)
Thats interesting, if I was using TypeScript to access the data, how would I keep the schemas in sync between TS and python?
Re:Django Styleguide by anileated on Wednesday January 11, 2023 @12:40PM (#34341491)
Can introspect and export Django models to JSON schema or similar, then in TS read it and use compiler low-level API to generate types. There may be libraries for either stage…
Re:Django Styleguide by rowanseymour on Wednesday January 11, 2023 @12:12PM (#34341008)
I've never used TypeScript to talk to a database but there might be tooling to generate classes from tables. Even if there isn't, manually keeping some TypeScript classes in sync might still be worth the effort, for being able to manage schema migrations easily elsewhere.
Re:Django Styleguide by dnadler on Wednesday January 11, 2023 @12:12PM (#34341019)
We do this manually along with a pydantic as a middleman between Django and TS. Works pretty well and is not a major inconvenience to keep things aligned.
Re:Django Styleguide by replygirl on Wednesday January 11, 2023 @01:11PM (#34342061)
if using DRF you export openapi to json and use openapi-typescript-codegen

if using graphene or strawberry you export sdl to json and use @graphql-codegen/typescript

Re:Django Styleguide by crucialfelix on Wednesday January 11, 2023 @03:02PM (#34343810)
Prisma works very well and has usable migrations. Not as solid as Django's.

Tiangolo of FastAPI fame is working on https://sqlmodel.tiangolo.com/ Which is pydantic models, SQL alchemy. Migrations are coming soon. This will probably be an excellent way to build APIs with db. Then you can generate a typescript client from the built in OpenAPI schema.