question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SPIKE: Generate SQL models from fields in pydantic models

See original GitHub issue

Overview

Currently, we manually define the SQL models for the caching system. Look into automatically generating the table columns from the fields of pydantic models that are associated with these caching tables.

Specification

This is the general idea, but obviously not the implementation

class ContractEvents(SQLModel):
    id: Optional[int]
    event: str
    ...

class ContractEventsCache(ContractEvents, table=true):
    some_fk_field: some_data_type = Field(some_fk, ...)

Dependencies

sqlmodel -> https://sqlmodel.tiangolo.com/

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
johnson2427commented, Jul 27, 2022

@fubuloubu, @banteg I am using sqlmodel in a RestAPI service that I am building out. And while it has some pretty interesting features, it is not an end all be all solution. I think it would be a mistake to integrate this into Ape. This spike will remain open, I am still attempting to generate SQL fields using the pydantic models, just not with sqlmodel.

1reaction
johnson2427commented, Jul 14, 2022

alembic would probably be the move here @fubuloubu

Read more comments on GitHub >

github_iconTop Results From Across the Web

FastAPI and Pydantic - Intro - SQLModel
In this group of chapters we will see how to combine SQLModel table models representing tables in the SQL database as all the...
Read more >
[QUESTION] How to bridge Pydantic models with SQLAlchemy?
So, Pydantic and SQLAlchemy are separated. Pydantic is used for documentation, validation, and data serialization. SQLAlchemy for SQL ORM stuff.
Read more >
Code Generation - pydantic
The datamodel-code-generator project is a library and command-line utility to generate pydantic models from just about any data source, ...
Read more >
How to generate Pydantic & SQLAlchemy/GinoORM models ...
This article demonstrates how to generate ORM & Pydantic models from DDL files with O!MyModels library. With one command or 1 line of...
Read more >
Models - pydantic
Creating models without validation; __fields_set__: Set of names of fields which were set ... class SQLModel(BaseModel): __tablename__ = 'my_table' id = sa.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found