Skip to content

Instantly share code, notes, and snippets.

@Goldziher
Last active January 31, 2022 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Goldziher/ba6d23e4ab157b6a46cbb9d4b2d0a48f to your computer and use it in GitHub Desktop.
Save Goldziher/ba6d23e4ab157b6a46cbb9d4b2d0a48f to your computer and use it in GitHub Desktop.
starlite sql alchemy plugin example
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)
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]:
...
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