Skip to content

Commit

Permalink
chore: adding type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuefii committed Aug 26, 2024
1 parent 08865a8 commit f83bda8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
db = SQLAlchemy()


def create_app():
def create_app() -> Flask:
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)

@app.route("/")
def home():
def home() -> str:
return render_template("index.html")

with app.app_context():
Expand Down
6 changes: 4 additions & 2 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Optional
from dotenv import load_dotenv

load_dotenv()
Expand All @@ -12,5 +13,6 @@ class Config:
SQLALCHEMY_DATABASE_URI (str): URL untuk koneksi pada database yang diambil dari variabel "DATABASE_URL" yang ada di .env.
SQLALCHEMY_TRACK_MODIFICATIONS (bool): Menonaktifkan pelacakan pada perubahan object untuk mencegah terjadinya overhead.
"""
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL")
SQLALCHEMY_TRACK_MODIFICATIONS = False

SQLALCHEMY_DATABASE_URI: str | None = os.getenv("DATABASE_URL")
SQLALCHEMY_TRACK_MODIFICATIONS: bool = False
22 changes: 11 additions & 11 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Provinces(db.Model):
name (str): Nama Provinsi yang tidak boleh kosong.
"""

code = db.Column(db.String(2), primary_key=True)
name = db.Column(db.String(255), nullable=False)
code: str = db.Column(db.String(2), primary_key=True)
name: str = db.Column(db.String(255), nullable=False)


class Regencies(db.Model):
Expand All @@ -24,11 +24,11 @@ class Regencies(db.Model):
name (str): Nama Kabupaten/Kota yang tidak boleh kosong.
"""

code = db.Column(db.String(5), primary_key=True)
province_code = db.Column(
code: str = db.Column(db.String(5), primary_key=True)
province_code: str = db.Column(
db.String(2), db.ForeignKey("provinces.code"), nullable=False
)
name = db.Column(db.String(255), nullable=False)
name: str = db.Column(db.String(255), nullable=False)
province = db.relationship("Provinces", backref=db.backref("regencies", lazy=True))


Expand All @@ -42,11 +42,11 @@ class Districts(db.Model):
name (str): Nama Kecamatan yang tidak boleh kosong.
"""

code = db.Column(db.String(8), primary_key=True)
regency_code = db.Column(
code: str = db.Column(db.String(8), primary_key=True)
regency_code: str = db.Column(
db.String(5), db.ForeignKey("regencies.code"), nullable=False
)
name = db.Column(db.String(255), nullable=False)
name: str = db.Column(db.String(255), nullable=False)
regency = db.relationship("Regencies", backref=db.backref("districts", lazy=True))


Expand All @@ -60,9 +60,9 @@ class Villages(db.Model):
name (str): Nama Desa yang tidak boleh kosong.
"""

code = db.Column(db.String(13), primary_key=True)
district_code = db.Column(
code: str = db.Column(db.String(13), primary_key=True)
district_code: str = db.Column(
db.String(8), db.ForeignKey("districts.code"), nullable=False
)
name = db.Column(db.String(255), nullable=False)
name: str = db.Column(db.String(255), nullable=False)
district = db.relationship("Districts", backref=db.backref("villages", lazy=True))

0 comments on commit f83bda8

Please sign in to comment.