-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
52 lines (25 loc) · 1.07 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker,relationship,session
from pydantic import BaseModel
SQLALCHEMY_DATABASE_URL = "postgresql://iamhaider072:[email protected]/neondb?sslmode=require"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
Base = declarative_base()
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
#Pydantic Model
class TodoCreate(BaseModel):
title: str
description: str
#models.py
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
title = Column(String, index=True)
description = Column(String, index=True)
todos=relationship("Todo", back_populates="owner_id")
class Todo(Base):
__tablename__="todos"
id=Column(Integer,primary_key=True,index=True)
title=Column(String,index=True)
description=Column(String,index=True)
owner_id=relationship("User",back_populates="todos")