3 ms·
Thats interesting, if I was using TypeScript to access the data, how would I keep the schemas in sync between TS and python?
by jbellew 4y ago
Thats interesting, if I was using TypeScript to access the data, how would I keep the schemas in sync between TS and python?
- rowanseymour 4y agoI'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.
- dnadler 4y agoWe 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.
- anileated 4y agoCan 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…
- replygirl 4y agoif 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
- crucialfelix 4y agoPrisma works very well and has usable migrations. Not as solid as Django's. Tiangolo of FastAPI fame is working on https://sqlmodel.tiangolo.com/ 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.