Last active
January 31, 2022 09:44
-
-
Save Goldziher/ba6d23e4ab157b6a46cbb9d4b2d0a48f to your computer and use it in GitHub Desktop.
starlite sql alchemy plugin example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Column, Float, Integer, String | |
from sqlalchemy.orm import declarative_base | |
Base = declarative_base() | |
class Company(Base): | |
id = Column(Integer, primary_key=True) | |
name = Column(String) | |
worth = Column(Float) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlite import post, get | |
from models import Company | |
@post(path="/companies") | |
def create_company(data: Company) -> Company: | |
... | |
@get(path="/companies") | |
def get_companies() -> List[Company]: | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlite import Starlite, SQLAlchemyPlugin | |
from endpoints import create_company, get_companies | |
app = Starlite(route_handlers=[create_company, get_companies], plugins=[SQLAlchemyPlugin()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment