32 lines
753 B
Python
32 lines
753 B
Python
|
from sqlalchemy.orm import Session
|
||
|
|
||
|
from . import models, schemas
|
||
|
|
||
|
|
||
|
def get_user(db: Session, name: str):
|
||
|
return (db
|
||
|
.query(models.User)
|
||
|
.filter(models.User.name == name).first())
|
||
|
|
||
|
|
||
|
def create_user(db: Session, user: schemas.UserCreate):
|
||
|
db_user = models.User(
|
||
|
name=user.name,
|
||
|
password=user.password + "notreallyhashed",
|
||
|
)
|
||
|
db.add(db_user)
|
||
|
db.commit()
|
||
|
db.refresh(db_user)
|
||
|
return db_user
|
||
|
|
||
|
|
||
|
def add_user_capability(db: Session, user_name: str, capability: str):
|
||
|
db_user_capability = models.UserCapability(
|
||
|
user_name=user_name,
|
||
|
capability=capability,
|
||
|
)
|
||
|
db.add(db_user_capability)
|
||
|
db.commit()
|
||
|
db.refresh(db_user_capability)
|
||
|
return db_user_capability
|