forked from codesensei-courses/fastapi_fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_user.py
36 lines (25 loc) · 811 Bytes
/
create_user.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
"""
create_user.py
-------------
A convenience script to create a user.
"""
from getpass import getpass
from sqlmodel import SQLModel, Session, create_engine
from schemas import User
engine = create_engine(
"sqlite:///carsharing.db",
connect_args={"check_same_thread": False}, # Needed for SQLite
echo=True # Log generated SQL
)
if __name__ == "__main__":
print("Creating tables (if necessary)")
SQLModel.metadata.create_all(engine)
print("--------")
print("This script will create a user and save it in the database.")
username = input("Please enter username\n")
pwd = getpass("Please enter password\n")
with Session(engine) as session:
user = User(username=username)
user.set_password(pwd)
session.add(user)
session.commit()