Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 98d4ea3

Browse files
author
rafgger
committed
working version, docker needs to be running
1 parent b129f42 commit 98d4ea3

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

‎app/database.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from sqlalchemy import create_engine
22
from sqlalchemy.ext.declarative import declarative_base
33
from sqlalchemy.orm import sessionmaker
4+
from .config import settings
5+
from fastapi_utils.guid_type import setup_guids_postgresql
46

5-
SQLITE_DATABASE_URL = "sqlite:///./note.db"
7+
POSTGRES_URL = f"postgresql://{settings.POSTGRES_USER}:{settings.POSTGRES_PASSWORD}@{settings.POSTGRES_HOSTNAME}:{settings.DATABASE_PORT}/{settings.POSTGRES_DB}"
68

79
engine = create_engine(
8-
SQLITE_DATABASE_URL, echo=True, connect_args={"check_same_thread": False}
10+
POSTGRES_URL, echo=True
911
)
12+
setup_guids_postgresql(engine)
1013
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
1114

1215
Base = declarative_base()
@@ -18,3 +21,4 @@ def get_db():
1821
yield db
1922
finally:
2023
db.close()
24+

‎app/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
from .database import Base
22
from sqlalchemy import TIMESTAMP, Column, String, Boolean
33
from sqlalchemy.sql import func
4-
from fastapi_utils.guid_type import GUID, GUID_DEFAULT_SQLITE
4+
from fastapi_utils.guid_type import GUID, GUID_SERVER_DEFAULT_POSTGRESQL
55

66

77
class Note(Base):
88
__tablename__ = 'notes'
9-
id = Column(GUID, primary_key=True, default=GUID_DEFAULT_SQLITE)
9+
id = Column(GUID, primary_key=True,
10+
server_default=GUID_SERVER_DEFAULT_POSTGRESQL)
1011
title = Column(String, nullable=False)
1112
content = Column(String, nullable=False)
1213
category = Column(String, nullable=True)
13-
published = Column(Boolean, nullable=False, default=True)
14+
published = Column(Boolean, nullable=False, server_default='True')
1415
createdAt = Column(TIMESTAMP(timezone=True),
1516
nullable=False, server_default=func.now())
1617
updatedAt = Column(TIMESTAMP(timezone=True),
1718
default=None, onupdate=func.now())
19+

‎requirements.txt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
# anyio==3.6.2
2-
# autopep8==1.7.1
3-
# certifi==2022年9月24日
4-
# charset-normalizer==2.1.1
5-
# click==8.1.3
6-
# colorama==0.4.6
7-
# dnspython==2.2.1
8-
# email-validator==1.3.0
9-
# fastapi==0.85.1
10-
# fastapi-utils==0.2.1
11-
# greenlet==1.1.3.post0
12-
# h11==0.14.0
13-
# httptools==0.5.0
14-
# idna==3.4
15-
# itsdangerous==2.1.2
16-
# Jinja2==3.1.2
17-
# MarkupSafe==2.1.1
18-
# orjson==3.8.1
19-
# psycopg2==2.9.5
20-
# pycodestyle==2.9.1
21-
# pydantic==1.10.2
22-
# python-dotenv==0.21.0
23-
# python-multipart==0.0.5
24-
# PyYAML==6.0
1+
anyio#==3.6.2
2+
autopep8#==1.7.1
3+
certifi#==2022年9月24日
4+
charset-normalizer#==2.1.1
5+
click#==8.1.3
6+
colorama#==0.4.6
7+
dnspython#==2.2.1
8+
email-validator#==1.3.0
9+
fastapi#==0.85.1
10+
fastapi-utils#==0.2.1
11+
greenlet#==1.1.3.post0
12+
h11#==0.14.0
13+
httptools#==0.5.0
14+
idna#==3.4
15+
itsdangerous#==2.1.2
16+
Jinja2#==3.1.2
17+
MarkupSafe#==2.1.1
18+
orjson#==3.8.1
19+
psycopg2#==2.9.5
20+
pycodestyle#==2.9.1
21+
pydantic#==1.10.2
22+
python-dotenv#==0.21.0
23+
python-multipart#==0.0.5
24+
PyYAML#==6.0
2525
requests #==2.28.1
2626
six #==1.16.0
2727
sniffio #==1.3.0

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /