prompt
stringlengths
45
17.8k
completion
stringlengths
6
107
api
stringlengths
12
42
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int role_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserSource(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int role_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserSource(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime created_by: int class UserLog(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int role_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserSource(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime created_by: int class UserLog(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int class Doctor(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int role_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserSource(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime created_by: int class UserLog(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int class Doctor(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int hospital_id: int discipline_id: int prefix: str first_name: str last_name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class DoctorProcedureMap(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int role_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserSource(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime created_by: int class UserLog(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int class Doctor(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int hospital_id: int discipline_id: int prefix: str first_name: str last_name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class DoctorProcedureMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) doctor_id: int procedure_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class Discipline(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int role_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserSource(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime created_by: int class UserLog(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int class Doctor(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int hospital_id: int discipline_id: int prefix: str first_name: str last_name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class DoctorProcedureMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) doctor_id: int procedure_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class Discipline(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) discipline_group_id: int name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class DisciplineGroup(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int role_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserSource(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime created_by: int class UserLog(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int class Doctor(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int hospital_id: int discipline_id: int prefix: str first_name: str last_name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class DoctorProcedureMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) doctor_id: int procedure_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class Discipline(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) discipline_group_id: int name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class DisciplineGroup(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class Role(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import os import pathlib from datetime import datetime, date, time from decimal import Decimal from typing import Optional, List from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile from fastapi.encoders import jsonable_encoder from sqlmodel import Field, SQLModel from ..db import get_session from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession router = APIRouter() cert_path = '/uploads/user/{user_id}/cert/' avatar_path = '/uploads/user/{user_id}/avatar/' class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) state: str # Statue: pending, active, inactive id_type_id: int id_number: str = None email = str email_verified_at: Optional[datetime] = None password: str remember_token: str hospital_id: Optional[int] = None hospital_node_id: Optional[int] = None discipline_id: int first_name_thai: str last_name_thai: str first_name_english: str last_name_english: str nickname: str birth_date: date gender: str academic_degree: str is_thai_address: bool address_house_number: str address_moo: str address_soi: str address_road: str address_tambon_id: Optional[int] = None address_amphoe_id: Optional[int] = None address_province_id: Optional[int] = None address_other: str latitude: Decimal longitude: Decimal potential: str avatar_path: str document_path: str policy_accept: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserPhone(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int number: str detail: str receive_sms: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserFeedback(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int feedback_type_id: Optional[int] = None detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserNotification(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int name: str detail: str is_read: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserRole(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int role_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class UserSource(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime created_by: int class UserLog(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int class Doctor(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) user_id: int hospital_id: int discipline_id: int prefix: str first_name: str last_name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class DoctorProcedureMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) doctor_id: int procedure_id: int created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class Discipline(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) discipline_group_id: int name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class DisciplineGroup(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class Role(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class RoleModuleFunctionMap(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column", sqlmodel.sql.sqltypes.AutoString(), nullable=True, ), sa.ForeignKeyConstraint( ["dimension_id"], ["node.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_column_dimension_column"), "column", ["dimension_column"], unique=False, ) op.create_index( op.f("ix_column_dimension_id"), "column", ["dimension_id"], unique=False, ) op.create_index(op.f("ix_column_id"), "column", ["id"], unique=False) op.create_index(op.f("ix_column_name"), "column", ["name"], unique=False) op.create_table( "noderelationship", sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("child_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ["child_id"], ["node.id"], ), sa.ForeignKeyConstraint( ["parent_id"], ["node.id"], ), sa.PrimaryKeyConstraint("parent_id", "child_id"), ) op.create_index( op.f("ix_noderelationship_child_id"), "noderelationship", ["child_id"], unique=False, ) op.create_index( op.f("ix_noderelationship_parent_id"), "noderelationship", ["parent_id"], unique=False, ) op.create_table( "query", sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column", sqlmodel.sql.sqltypes.AutoString(), nullable=True, ), sa.ForeignKeyConstraint( ["dimension_id"], ["node.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_column_dimension_column"), "column", ["dimension_column"], unique=False, ) op.create_index( op.f("ix_column_dimension_id"), "column", ["dimension_id"], unique=False, ) op.create_index(op.f("ix_column_id"), "column", ["id"], unique=False) op.create_index(op.f("ix_column_name"), "column", ["name"], unique=False) op.create_table( "noderelationship", sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("child_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ["child_id"], ["node.id"], ), sa.ForeignKeyConstraint( ["parent_id"], ["node.id"], ), sa.PrimaryKeyConstraint("parent_id", "child_id"), ) op.create_index( op.f("ix_noderelationship_child_id"), "noderelationship", ["child_id"], unique=False, ) op.create_index( op.f("ix_noderelationship_parent_id"), "noderelationship", ["parent_id"], unique=False, ) op.create_table( "query", sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column", sqlmodel.sql.sqltypes.AutoString(), nullable=True, ), sa.ForeignKeyConstraint( ["dimension_id"], ["node.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_column_dimension_column"), "column", ["dimension_column"], unique=False, ) op.create_index( op.f("ix_column_dimension_id"), "column", ["dimension_id"], unique=False, ) op.create_index(op.f("ix_column_id"), "column", ["id"], unique=False) op.create_index(op.f("ix_column_name"), "column", ["name"], unique=False) op.create_table( "noderelationship", sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("child_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ["child_id"], ["node.id"], ), sa.ForeignKeyConstraint( ["parent_id"], ["node.id"], ), sa.PrimaryKeyConstraint("parent_id", "child_id"), ) op.create_index( op.f("ix_noderelationship_child_id"), "noderelationship", ["child_id"], unique=False, ) op.create_index( op.f("ix_noderelationship_parent_id"), "noderelationship", ["parent_id"], unique=False, ) op.create_table( "query", sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column( "submitted_query",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column", sqlmodel.sql.sqltypes.AutoString(), nullable=True, ), sa.ForeignKeyConstraint( ["dimension_id"], ["node.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_column_dimension_column"), "column", ["dimension_column"], unique=False, ) op.create_index( op.f("ix_column_dimension_id"), "column", ["dimension_id"], unique=False, ) op.create_index(op.f("ix_column_id"), "column", ["id"], unique=False) op.create_index(op.f("ix_column_name"), "column", ["name"], unique=False) op.create_table( "noderelationship", sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("child_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ["child_id"], ["node.id"], ), sa.ForeignKeyConstraint( ["parent_id"], ["node.id"], ), sa.PrimaryKeyConstraint("parent_id", "child_id"), ) op.create_index( op.f("ix_noderelationship_child_id"), "noderelationship", ["child_id"], unique=False, ) op.create_index( op.f("ix_noderelationship_parent_id"), "noderelationship", ["parent_id"], unique=False, ) op.create_table( "query", sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column( "submitted_query", sqlmodel.sql.sqltypes.AutoString(), nullable=False, ), sa.Column("executed_query",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column", sqlmodel.sql.sqltypes.AutoString(), nullable=True, ), sa.ForeignKeyConstraint( ["dimension_id"], ["node.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_column_dimension_column"), "column", ["dimension_column"], unique=False, ) op.create_index( op.f("ix_column_dimension_id"), "column", ["dimension_id"], unique=False, ) op.create_index(op.f("ix_column_id"), "column", ["id"], unique=False) op.create_index(op.f("ix_column_name"), "column", ["name"], unique=False) op.create_table( "noderelationship", sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("child_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ["child_id"], ["node.id"], ), sa.ForeignKeyConstraint( ["parent_id"], ["node.id"], ), sa.PrimaryKeyConstraint("parent_id", "child_id"), ) op.create_index( op.f("ix_noderelationship_child_id"), "noderelationship", ["child_id"], unique=False, ) op.create_index( op.f("ix_noderelationship_parent_id"), "noderelationship", ["parent_id"], unique=False, ) op.create_table( "query", sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column( "submitted_query", sqlmodel.sql.sqltypes.AutoString(), nullable=False, ), sa.Column("executed_query", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("scheduled", sa.DateTime(), nullable=True), sa.Column("started", sa.DateTime(), nullable=True), sa.Column("finished", sa.DateTime(), nullable=True), sa.Column("state",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column", sqlmodel.sql.sqltypes.AutoString(), nullable=True, ), sa.ForeignKeyConstraint( ["dimension_id"], ["node.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_column_dimension_column"), "column", ["dimension_column"], unique=False, ) op.create_index( op.f("ix_column_dimension_id"), "column", ["dimension_id"], unique=False, ) op.create_index(op.f("ix_column_id"), "column", ["id"], unique=False) op.create_index(op.f("ix_column_name"), "column", ["name"], unique=False) op.create_table( "noderelationship", sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("child_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ["child_id"], ["node.id"], ), sa.ForeignKeyConstraint( ["parent_id"], ["node.id"], ), sa.PrimaryKeyConstraint("parent_id", "child_id"), ) op.create_index( op.f("ix_noderelationship_child_id"), "noderelationship", ["child_id"], unique=False, ) op.create_index( op.f("ix_noderelationship_parent_id"), "noderelationship", ["parent_id"], unique=False, ) op.create_table( "query", sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column( "submitted_query", sqlmodel.sql.sqltypes.AutoString(), nullable=False, ), sa.Column("executed_query", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("scheduled", sa.DateTime(), nullable=True), sa.Column("started", sa.DateTime(), nullable=True), sa.Column("finished", sa.DateTime(), nullable=True), sa.Column("state", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("progress", sa.Float(), nullable=True), sa.ForeignKeyConstraint( ["database_id"], ["database.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_query_catalog"), "query", ["catalog"], unique=False) op.create_index( op.f("ix_query_database_id"), "query", ["database_id"], unique=False, ) op.create_index( op.f("ix_query_executed_query"), "query", ["executed_query"], unique=False, ) op.create_index(op.f("ix_query_finished"), "query", ["finished"], unique=False) op.create_index(op.f("ix_query_progress"), "query", ["progress"], unique=False) op.create_index(op.f("ix_query_scheduled"), "query", ["scheduled"], unique=False) op.create_index(op.f("ix_query_schema_"), "query", ["schema_"], unique=False) op.create_index(op.f("ix_query_started"), "query", ["started"], unique=False) op.create_index(op.f("ix_query_state"), "query", ["state"], unique=False) op.create_index( op.f("ix_query_submitted_query"), "query", ["submitted_query"], unique=False, ) op.create_table( "table", sa.Column("id", sa.Integer(), nullable=True), sa.Column("node_id", sa.Integer(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column", sqlmodel.sql.sqltypes.AutoString(), nullable=True, ), sa.ForeignKeyConstraint( ["dimension_id"], ["node.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_column_dimension_column"), "column", ["dimension_column"], unique=False, ) op.create_index( op.f("ix_column_dimension_id"), "column", ["dimension_id"], unique=False, ) op.create_index(op.f("ix_column_id"), "column", ["id"], unique=False) op.create_index(op.f("ix_column_name"), "column", ["name"], unique=False) op.create_table( "noderelationship", sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("child_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ["child_id"], ["node.id"], ), sa.ForeignKeyConstraint( ["parent_id"], ["node.id"], ), sa.PrimaryKeyConstraint("parent_id", "child_id"), ) op.create_index( op.f("ix_noderelationship_child_id"), "noderelationship", ["child_id"], unique=False, ) op.create_index( op.f("ix_noderelationship_parent_id"), "noderelationship", ["parent_id"], unique=False, ) op.create_table( "query", sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column( "submitted_query", sqlmodel.sql.sqltypes.AutoString(), nullable=False, ), sa.Column("executed_query", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("scheduled", sa.DateTime(), nullable=True), sa.Column("started", sa.DateTime(), nullable=True), sa.Column("finished", sa.DateTime(), nullable=True), sa.Column("state", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("progress", sa.Float(), nullable=True), sa.ForeignKeyConstraint( ["database_id"], ["database.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_query_catalog"), "query", ["catalog"], unique=False) op.create_index( op.f("ix_query_database_id"), "query", ["database_id"], unique=False, ) op.create_index( op.f("ix_query_executed_query"), "query", ["executed_query"], unique=False, ) op.create_index(op.f("ix_query_finished"), "query", ["finished"], unique=False) op.create_index(op.f("ix_query_progress"), "query", ["progress"], unique=False) op.create_index(op.f("ix_query_scheduled"), "query", ["scheduled"], unique=False) op.create_index(op.f("ix_query_schema_"), "query", ["schema_"], unique=False) op.create_index(op.f("ix_query_started"), "query", ["started"], unique=False) op.create_index(op.f("ix_query_state"), "query", ["state"], unique=False) op.create_index( op.f("ix_query_submitted_query"), "query", ["submitted_query"], unique=False, ) op.create_table( "table", sa.Column("id", sa.Integer(), nullable=True), sa.Column("node_id", sa.Integer(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial migration Revision ID: 5f31ff8814e7 Revises: Create Date: 2022-04-30 19:39:20.164043+00:00 """ # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import import sqlalchemy as sa import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. revision = "5f31ff8814e7" down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "database", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("URI", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("read_only", sa.Boolean(), nullable=True), sa.Column("async", sa.Boolean(), nullable=True), sa.Column("cost", sa.Float(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_database_URI"), "database", ["URI"], unique=False) op.create_index(op.f("ix_database_async"), "database", ["async"], unique=False) op.create_index(op.f("ix_database_cost"), "database", ["cost"], unique=False) op.create_index( op.f("ix_database_description"), "database", ["description"], unique=False, ) op.create_index(op.f("ix_database_id"), "database", ["id"], unique=False) op.create_index( op.f("ix_database_read_only"), "database", ["read_only"], unique=False, ) op.create_table( "node", sa.Column("name", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "type", sa.Enum("SOURCE", "TRANSFORM", "METRIC", "DIMENSION", name="nodetype"), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("expression", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) op.create_index(op.f("ix_node_description"), "node", ["description"], unique=False) op.create_index(op.f("ix_node_expression"), "node", ["expression"], unique=False) op.create_index(op.f("ix_node_id"), "node", ["id"], unique=False) op.create_table( "column", sa.Column( "type", sa.Enum( "BYTES", "STR", "FLOAT", "INT", "DECIMAL", "BOOL", "DATETIME", "DATE", "TIME", "TIMEDELTA", "LIST", "DICT", name="columntype", ), nullable=True, ), sa.Column("id", sa.Integer(), nullable=True), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("dimension_id", sa.Integer(), nullable=True), sa.Column( "dimension_column", sqlmodel.sql.sqltypes.AutoString(), nullable=True, ), sa.ForeignKeyConstraint( ["dimension_id"], ["node.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_column_dimension_column"), "column", ["dimension_column"], unique=False, ) op.create_index( op.f("ix_column_dimension_id"), "column", ["dimension_id"], unique=False, ) op.create_index(op.f("ix_column_id"), "column", ["id"], unique=False) op.create_index(op.f("ix_column_name"), "column", ["name"], unique=False) op.create_table( "noderelationship", sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("child_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ["child_id"], ["node.id"], ), sa.ForeignKeyConstraint( ["parent_id"], ["node.id"], ), sa.PrimaryKeyConstraint("parent_id", "child_id"), ) op.create_index( op.f("ix_noderelationship_child_id"), "noderelationship", ["child_id"], unique=False, ) op.create_index( op.f("ix_noderelationship_parent_id"), "noderelationship", ["parent_id"], unique=False, ) op.create_table( "query", sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column( "submitted_query", sqlmodel.sql.sqltypes.AutoString(), nullable=False, ), sa.Column("executed_query", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("scheduled", sa.DateTime(), nullable=True), sa.Column("started", sa.DateTime(), nullable=True), sa.Column("finished", sa.DateTime(), nullable=True), sa.Column("state", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("progress", sa.Float(), nullable=True), sa.ForeignKeyConstraint( ["database_id"], ["database.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_query_catalog"), "query", ["catalog"], unique=False) op.create_index( op.f("ix_query_database_id"), "query", ["database_id"], unique=False, ) op.create_index( op.f("ix_query_executed_query"), "query", ["executed_query"], unique=False, ) op.create_index(op.f("ix_query_finished"), "query", ["finished"], unique=False) op.create_index(op.f("ix_query_progress"), "query", ["progress"], unique=False) op.create_index(op.f("ix_query_scheduled"), "query", ["scheduled"], unique=False) op.create_index(op.f("ix_query_schema_"), "query", ["schema_"], unique=False) op.create_index(op.f("ix_query_started"), "query", ["started"], unique=False) op.create_index(op.f("ix_query_state"), "query", ["state"], unique=False) op.create_index( op.f("ix_query_submitted_query"), "query", ["submitted_query"], unique=False, ) op.create_table( "table", sa.Column("id", sa.Integer(), nullable=True), sa.Column("node_id", sa.Integer(), nullable=False), sa.Column("database_id", sa.Integer(), nullable=False), sa.Column("catalog", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("schema_", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("table",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """
SQLModel.metadata.create_all(engine)
sqlmodel.SQLModel.metadata.create_all
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement =
select(Device)
sqlmodel.select
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with Session(engine) as session: statement =
select(Project)
sqlmodel.select
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with Session(engine) as session: statement = select(Project) results = session.exec(statement).all() return results @api.post("/tasks/{task_uuid}", response_model=Task) def upsert_task(task_uuid: str, task: Task) -> Task: """Upsert a task. It is used to create a task in the database if it does not already exists, else it is used to update the existing one. Args: task_uuid: The uuid of the task to upsert. task: The task data. Returns: The upserted task. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with Session(engine) as session: statement = select(Project) results = session.exec(statement).all() return results @api.post("/tasks/{task_uuid}", response_model=Task) def upsert_task(task_uuid: str, task: Task) -> Task: """Upsert a task. It is used to create a task in the database if it does not already exists, else it is used to update the existing one. Args: task_uuid: The uuid of the task to upsert. task: The task data. Returns: The upserted task. """ with Session(engine) as session: # check if the task exists statement = select(Task).where(Task.uuid == task_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = task # sync the data for key, value in task.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/tasks/{task_uuid}", response_model=TaskWithProject) def select_task(task_uuid: str): """Select a task. It is used to get a task data from the database. Args: task_uuid: The uuid of the task to get the data from. Returns: The task data. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with Session(engine) as session: statement = select(Project) results = session.exec(statement).all() return results @api.post("/tasks/{task_uuid}", response_model=Task) def upsert_task(task_uuid: str, task: Task) -> Task: """Upsert a task. It is used to create a task in the database if it does not already exists, else it is used to update the existing one. Args: task_uuid: The uuid of the task to upsert. task: The task data. Returns: The upserted task. """ with Session(engine) as session: # check if the task exists statement = select(Task).where(Task.uuid == task_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = task # sync the data for key, value in task.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/tasks/{task_uuid}", response_model=TaskWithProject) def select_task(task_uuid: str): """Select a task. It is used to get a task data from the database. Args: task_uuid: The uuid of the task to get the data from. Returns: The task data. """ with Session(engine) as session: statement = select(Task, Project).join(Project).where(Task.uuid == task_uuid) task, project = session.exec(statement).first() # type: ignore result = TaskWithProject() for key, value in task.dict().items(): setattr(result, key, value) result.project = project return result @api.get("/tasks", response_model=List[TaskWithProject]) def select_tasks(): """Select all tasks. It is used to get all tasks data from the database. Returns: All tasks data. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with Session(engine) as session: statement = select(Project) results = session.exec(statement).all() return results @api.post("/tasks/{task_uuid}", response_model=Task) def upsert_task(task_uuid: str, task: Task) -> Task: """Upsert a task. It is used to create a task in the database if it does not already exists, else it is used to update the existing one. Args: task_uuid: The uuid of the task to upsert. task: The task data. Returns: The upserted task. """ with Session(engine) as session: # check if the task exists statement = select(Task).where(Task.uuid == task_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = task # sync the data for key, value in task.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/tasks/{task_uuid}", response_model=TaskWithProject) def select_task(task_uuid: str): """Select a task. It is used to get a task data from the database. Args: task_uuid: The uuid of the task to get the data from. Returns: The task data. """ with Session(engine) as session: statement = select(Task, Project).join(Project).where(Task.uuid == task_uuid) task, project = session.exec(statement).first() # type: ignore result = TaskWithProject() for key, value in task.dict().items(): setattr(result, key, value) result.project = project return result @api.get("/tasks", response_model=List[TaskWithProject]) def select_tasks(): """Select all tasks. It is used to get all tasks data from the database. Returns: All tasks data. """ with Session(engine) as session: statement = select(Task, Project).join(Project) results = session.exec(statement).all() tasks = [] for task, project in results: result = TaskWithProject() for key, value in task.dict().items(): setattr(result, key, value) result.project = project tasks.append(result) return tasks @api.put("/tasks/clean") def clean_tasks(): """Clean all tasks. It is used to run maintenance queries on the database in order to keep consistent data on tasks. """ with
Session(engine)
sqlmodel.Session
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement =
select(Device)
sqlmodel.select
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement =
select(Device)
sqlmodel.select
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement =
select(Project)
sqlmodel.select
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement =
select(Project)
sqlmodel.select
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with Session(engine) as session: statement = select(Project) results = session.exec(statement).all() return results @api.post("/tasks/{task_uuid}", response_model=Task) def upsert_task(task_uuid: str, task: Task) -> Task: """Upsert a task. It is used to create a task in the database if it does not already exists, else it is used to update the existing one. Args: task_uuid: The uuid of the task to upsert. task: The task data. Returns: The upserted task. """ with Session(engine) as session: # check if the task exists statement =
select(Task)
sqlmodel.select
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with Session(engine) as session: statement = select(Project) results = session.exec(statement).all() return results @api.post("/tasks/{task_uuid}", response_model=Task) def upsert_task(task_uuid: str, task: Task) -> Task: """Upsert a task. It is used to create a task in the database if it does not already exists, else it is used to update the existing one. Args: task_uuid: The uuid of the task to upsert. task: The task data. Returns: The upserted task. """ with Session(engine) as session: # check if the task exists statement = select(Task).where(Task.uuid == task_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = task # sync the data for key, value in task.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/tasks/{task_uuid}", response_model=TaskWithProject) def select_task(task_uuid: str): """Select a task. It is used to get a task data from the database. Args: task_uuid: The uuid of the task to get the data from. Returns: The task data. """ with Session(engine) as session: statement = select(Task, Project).join(Project).where(Task.uuid == task_uuid) task, project = session.exec(statement).first() # type: ignore result = TaskWithProject() for key, value in task.dict().items(): setattr(result, key, value) result.project = project return result @api.get("/tasks", response_model=List[TaskWithProject]) def select_tasks(): """Select all tasks. It is used to get all tasks data from the database. Returns: All tasks data. """ with Session(engine) as session: statement =
select(Task, Project)
sqlmodel.select
# -*- coding: utf-8 -*- from typing import List from database import engine from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from models import Device, Project, Task, TaskWithProject from sqlmodel import Session, SQLModel, select # init fastapi app: FastAPI = FastAPI() # init CORS app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) # mount api endpoint api: FastAPI = FastAPI(title="Scitizen") app.mount("/api", api) @app.on_event("startup") def on_startup() -> None: """Setup event on app. It is used to create the database and the tables. """ SQLModel.metadata.create_all(engine) @api.post("/devices/{device_uuid}", response_model=Device) def upsert_device(device_uuid: str, device: Device) -> Device: """Upsert a device. It is used to create a device in the database if it does not already exists, else it is used to update the existing one. Args: device_uuid: The uuid of the device to upsert. device: The device data. Returns: The upserted device. """ with Session(engine) as session: # check if the device exists statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = device # sync the data for key, value in device.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/devices/{device_uuid}", response_model=Device) def select_device(device_uuid: str): """Select a device. It is used to get a device data from the database. Args: device_uuid: The uuid of the device to get the data from. Returns: The device data. """ with Session(engine) as session: statement = select(Device).where(Device.uuid == device_uuid) result = session.exec(statement).first() return result @api.get("/devices", response_model=List[Device]) def select_devices(): """Select all devices. It is used to get all devices data from the database. Returns: All devices data. """ with Session(engine) as session: statement = select(Device) results = session.exec(statement).all() return results @api.post("/projects/{project_uuid}", response_model=Project) def upsert_project(project_uuid: str, project: Project) -> Project: """Upsert a project. It is used to create a project in the database if it does not already exists, else it is used to update the existing one. Args: project_uuid: The uuid of the project to upsert. project: The project data. Returns: The upserted project. """ with Session(engine) as session: # check if the project exists statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = project # sync the data for key, value in project.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/projects/{project_uuid}", response_model=Project) def select_project(project_uuid: str): """Select a project. It is used to get a project data from the database. Args: project_uuid: The uuid of the project to get the data from. Returns: The project data. """ with Session(engine) as session: statement = select(Project).where(Project.uuid == project_uuid) result = session.exec(statement).first() return result @api.get("/projects", response_model=List[Project]) def select_projects(): """Select all projects. It is used to get all projects data from the database. Returns: All projects data. """ with Session(engine) as session: statement = select(Project) results = session.exec(statement).all() return results @api.post("/tasks/{task_uuid}", response_model=Task) def upsert_task(task_uuid: str, task: Task) -> Task: """Upsert a task. It is used to create a task in the database if it does not already exists, else it is used to update the existing one. Args: task_uuid: The uuid of the task to upsert. task: The task data. Returns: The upserted task. """ with Session(engine) as session: # check if the task exists statement = select(Task).where(Task.uuid == task_uuid) result = session.exec(statement).first() # if not, create it if result is None: result = task # sync the data for key, value in task.dict(exclude_unset=True).items(): setattr(result, key, value) # persist the data to the database session.add(result) session.commit() session.refresh(result) return result @api.get("/tasks/{task_uuid}", response_model=TaskWithProject) def select_task(task_uuid: str): """Select a task. It is used to get a task data from the database. Args: task_uuid: The uuid of the task to get the data from. Returns: The task data. """ with Session(engine) as session: statement =
select(Task, Project)
sqlmodel.select
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int =
Field(default=None, primary_key=True)
sqlmodel.Field
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int = Field(default=None, primary_key=True) name: str users: List["User"] =
Relationship(back_populates="group")
sqlmodel.Relationship
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int = Field(default=None, primary_key=True) name: str users: List["User"] = Relationship(back_populates="group") class User(SQLModel, table=True): id: int =
Field(default=None, primary_key=True)
sqlmodel.Field
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int = Field(default=None, primary_key=True) name: str users: List["User"] = Relationship(back_populates="group") class User(SQLModel, table=True): id: int = Field(default=None, primary_key=True) username: str = Field(sa_column=Column('username', VARCHAR, unique=True)) email: EmailStr password: str first_name: str last_name: str public_key: str private_key: str profile_pic: Optional[str] is_staff: bool =
Field(default=False)
sqlmodel.Field
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int = Field(default=None, primary_key=True) name: str users: List["User"] = Relationship(back_populates="group") class User(SQLModel, table=True): id: int = Field(default=None, primary_key=True) username: str = Field(sa_column=Column('username', VARCHAR, unique=True)) email: EmailStr password: str first_name: str last_name: str public_key: str private_key: str profile_pic: Optional[str] is_staff: bool = Field(default=False) group_id: Optional[int] =
Field(foreign_key="usergroup.id")
sqlmodel.Field
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int = Field(default=None, primary_key=True) name: str users: List["User"] = Relationship(back_populates="group") class User(SQLModel, table=True): id: int = Field(default=None, primary_key=True) username: str = Field(sa_column=Column('username', VARCHAR, unique=True)) email: EmailStr password: str first_name: str last_name: str public_key: str private_key: str profile_pic: Optional[str] is_staff: bool = Field(default=False) group_id: Optional[int] = Field(foreign_key="usergroup.id") group: Optional[UserGroup] =
Relationship(back_populates="users")
sqlmodel.Relationship
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int = Field(default=None, primary_key=True) name: str users: List["User"] = Relationship(back_populates="group") class User(SQLModel, table=True): id: int = Field(default=None, primary_key=True) username: str = Field(sa_column=Column('username', VARCHAR, unique=True)) email: EmailStr password: str first_name: str last_name: str public_key: str private_key: str profile_pic: Optional[str] is_staff: bool = Field(default=False) group_id: Optional[int] = Field(foreign_key="usergroup.id") group: Optional[UserGroup] = Relationship(back_populates="users") class RemoteUser(SQLModel, table=True): id: int =
Field(default=None, primary_key=True)
sqlmodel.Field
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int = Field(default=None, primary_key=True) name: str users: List["User"] = Relationship(back_populates="group") class User(SQLModel, table=True): id: int = Field(default=None, primary_key=True) username: str = Field(sa_column=
Column('username', VARCHAR, unique=True)
sqlmodel.Column
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey from typing import List, Optional from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column from pydantic import EmailStr class UserGroup(SQLModel, table=True): id: int = Field(default=None, primary_key=True) name: str users: List["User"] = Relationship(back_populates="group") class User(SQLModel, table=True): id: int = Field(default=None, primary_key=True) username: str = Field(sa_column=Column('username', VARCHAR, unique=True)) email: EmailStr password: str first_name: str last_name: str public_key: str private_key: str profile_pic: Optional[str] is_staff: bool = Field(default=False) group_id: Optional[int] = Field(foreign_key="usergroup.id") group: Optional[UserGroup] = Relationship(back_populates="users") class RemoteUser(SQLModel, table=True): id: int = Field(default=None, primary_key=True) remote_id: str = Field(sa_column=
Column('username', VARCHAR, unique=True)
sqlmodel.Column
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str =
Field(nullable=True, default=None)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID =
Field(nullable=True, default=None)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID =
Field(nullable=True, default=None)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str =
Field(nullable=True, default=None)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str = Field(nullable=True, default=None) cred_rev_id: str =
Field(nullable=True, default=None)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str = Field(nullable=True, default=None) cred_rev_id: str = Field(nullable=True, default=None) class IssueCredential(IssueCredentialBase, BaseTable, table=True): # This is the class that represents the table pass class IssueCredentialCreate(IssueCredentialBase): # This is the class that represents interface for creating a tenant # we must set all the required fields, # but do not need to set optional (and shouldn't) pass class IssueCredentialRead(IssueCredentialBase): # This is the class that represents interface for reading a tenant # here we indicate id, created_at and updated_at must be included id: uuid.UUID created_at: datetime updated_at: datetime class IssueCredentialUpdate(BaseModel): # This is our update interface # This does NOT inherit from IssueCredentialBase, # so no need to worry about accidentally updating id or other fields id: uuid.UUID issue_state: str =
Field(nullable=False)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str = Field(nullable=True, default=None) cred_rev_id: str = Field(nullable=True, default=None) class IssueCredential(IssueCredentialBase, BaseTable, table=True): # This is the class that represents the table pass class IssueCredentialCreate(IssueCredentialBase): # This is the class that represents interface for creating a tenant # we must set all the required fields, # but do not need to set optional (and shouldn't) pass class IssueCredentialRead(IssueCredentialBase): # This is the class that represents interface for reading a tenant # here we indicate id, created_at and updated_at must be included id: uuid.UUID created_at: datetime updated_at: datetime class IssueCredentialUpdate(BaseModel): # This is our update interface # This does NOT inherit from IssueCredentialBase, # so no need to worry about accidentally updating id or other fields id: uuid.UUID issue_state: str = Field(nullable=False) workflow_id: uuid.UUID =
Field(nullable=True, default=None)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str = Field(nullable=True, default=None) cred_rev_id: str = Field(nullable=True, default=None) class IssueCredential(IssueCredentialBase, BaseTable, table=True): # This is the class that represents the table pass class IssueCredentialCreate(IssueCredentialBase): # This is the class that represents interface for creating a tenant # we must set all the required fields, # but do not need to set optional (and shouldn't) pass class IssueCredentialRead(IssueCredentialBase): # This is the class that represents interface for reading a tenant # here we indicate id, created_at and updated_at must be included id: uuid.UUID created_at: datetime updated_at: datetime class IssueCredentialUpdate(BaseModel): # This is our update interface # This does NOT inherit from IssueCredentialBase, # so no need to worry about accidentally updating id or other fields id: uuid.UUID issue_state: str = Field(nullable=False) workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID =
Field(nullable=True, default=None)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str = Field(nullable=True, default=None) cred_rev_id: str = Field(nullable=True, default=None) class IssueCredential(IssueCredentialBase, BaseTable, table=True): # This is the class that represents the table pass class IssueCredentialCreate(IssueCredentialBase): # This is the class that represents interface for creating a tenant # we must set all the required fields, # but do not need to set optional (and shouldn't) pass class IssueCredentialRead(IssueCredentialBase): # This is the class that represents interface for reading a tenant # here we indicate id, created_at and updated_at must be included id: uuid.UUID created_at: datetime updated_at: datetime class IssueCredentialUpdate(BaseModel): # This is our update interface # This does NOT inherit from IssueCredentialBase, # so no need to worry about accidentally updating id or other fields id: uuid.UUID issue_state: str = Field(nullable=False) workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str =
Field(nullable=True, default=None)
sqlmodel.Field
import uuid from datetime import datetime from sqlmodel import Field from api.db.models.base import BaseModel, BaseTable class IssueCredentialBase(BaseModel): tenant_id: uuid.UUID = Field(nullable=False) wallet_id: uuid.UUID = Field(nullable=False) connection_id: uuid.UUID = Field(nullable=False) cred_type: str = Field(nullable=False) cred_protocol: str = Field(nullable=False) cred_def_id: str = Field(nullable=True, default=None) credential: str = Field(nullable=False) issue_role: str = Field(nullable=False) issue_state: str = Field(nullable=False) # workflow_id will be null until the tenant kcks it off workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str = Field(nullable=True, default=None) cred_rev_id: str = Field(nullable=True, default=None) class IssueCredential(IssueCredentialBase, BaseTable, table=True): # This is the class that represents the table pass class IssueCredentialCreate(IssueCredentialBase): # This is the class that represents interface for creating a tenant # we must set all the required fields, # but do not need to set optional (and shouldn't) pass class IssueCredentialRead(IssueCredentialBase): # This is the class that represents interface for reading a tenant # here we indicate id, created_at and updated_at must be included id: uuid.UUID created_at: datetime updated_at: datetime class IssueCredentialUpdate(BaseModel): # This is our update interface # This does NOT inherit from IssueCredentialBase, # so no need to worry about accidentally updating id or other fields id: uuid.UUID issue_state: str = Field(nullable=False) workflow_id: uuid.UUID = Field(nullable=True, default=None) cred_exch_id: uuid.UUID = Field(nullable=True, default=None) rev_reg_id: str = Field(nullable=True, default=None) cred_rev_id: str =
Field(nullable=True, default=None)
sqlmodel.Field
from typing import Optional from sqlmodel import Field, SQLModel class UserBase(SQLModel): name: str class User(UserBase, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
import uuid from logging import getLogger from typing import Optional from fastapi import UploadFile from sqlmodel import select, Session from .models import User logger = getLogger("uvicorn.error") def get_user(username: str, session: Session) -> Optional[User]: statement =
select(User)
sqlmodel.select
from typing import TYPE_CHECKING, Union from uuid import UUID from sqlalchemy.schema import Column, ForeignKey, UniqueConstraint from sqlmodel import Field, Relationship from sqlmodel.sql.sqltypes import GUID from joj.horse.models.base import BaseORMModel from joj.horse.models.domain import Domain from joj.horse.models.domain_role import DomainRole from joj.horse.models.permission import DefaultRole from joj.horse.utils.errors import BizError, ErrorCode if TYPE_CHECKING: from joj.horse.models.user import User class DomainUser(BaseORMModel, table=True): # type: ignore[call-arg] __tablename__ = "domain_users" __table_args__ = (UniqueConstraint("domain_id", "user_id"),) role: str domain_id: UUID = Field( sa_column=Column( GUID, ForeignKey("domains.id", ondelete="CASCADE"), nullable=False ) ) domain: "Domain" =
Relationship(back_populates="users")
sqlmodel.Relationship
from typing import TYPE_CHECKING, Union from uuid import UUID from sqlalchemy.schema import Column, ForeignKey, UniqueConstraint from sqlmodel import Field, Relationship from sqlmodel.sql.sqltypes import GUID from joj.horse.models.base import BaseORMModel from joj.horse.models.domain import Domain from joj.horse.models.domain_role import DomainRole from joj.horse.models.permission import DefaultRole from joj.horse.utils.errors import BizError, ErrorCode if TYPE_CHECKING: from joj.horse.models.user import User class DomainUser(BaseORMModel, table=True): # type: ignore[call-arg] __tablename__ = "domain_users" __table_args__ = (UniqueConstraint("domain_id", "user_id"),) role: str domain_id: UUID = Field( sa_column=Column( GUID, ForeignKey("domains.id", ondelete="CASCADE"), nullable=False ) ) domain: "Domain" = Relationship(back_populates="users") user_id: UUID = Field( sa_column=Column( GUID, ForeignKey("users.id", ondelete="CASCADE"), nullable=False ) ) user: "User" =
Relationship(back_populates="domain_users")
sqlmodel.Relationship
import os from fastapi import * from psycopg2.errors import UndefinedTable from sqlmodel import Session, select, text from sqlalchemy.exc import ProgrammingError from .models.timelog import TimeLog from .models.calendar import Calendar from .utils import ( engine, create_db, tags_metadata, execute_sample_sql, ) from .api import ( user, timelog, forecast, epic, epic_area, client, rate, team, role, sponsor, capacity, demand, ) import csv app = FastAPI(title="timeflow app API", openapi_tags=tags_metadata) app.include_router(timelog.router) app.include_router(forecast.router) app.include_router(user.router) app.include_router(epic.router) app.include_router(epic_area.router) app.include_router(client.router) app.include_router(rate.router) app.include_router(team.router) app.include_router(role.router) app.include_router(sponsor.router) app.include_router(capacity.router) app.include_router(demand.router) @app.on_event("startup") def on_startup(): with
Session(engine)
sqlmodel.Session
import os from fastapi import * from psycopg2.errors import UndefinedTable from sqlmodel import Session, select, text from sqlalchemy.exc import ProgrammingError from .models.timelog import TimeLog from .models.calendar import Calendar from .utils import ( engine, create_db, tags_metadata, execute_sample_sql, ) from .api import ( user, timelog, forecast, epic, epic_area, client, rate, team, role, sponsor, capacity, demand, ) import csv app = FastAPI(title="timeflow app API", openapi_tags=tags_metadata) app.include_router(timelog.router) app.include_router(forecast.router) app.include_router(user.router) app.include_router(epic.router) app.include_router(epic_area.router) app.include_router(client.router) app.include_router(rate.router) app.include_router(team.router) app.include_router(role.router) app.include_router(sponsor.router) app.include_router(capacity.router) app.include_router(demand.router) @app.on_event("startup") def on_startup(): with Session(engine) as session: if os.getenv("TIMEFLOW_DEV") == "true": try: statement = select(TimeLog) results = session.exec(statement) except ProgrammingError: create_db() execute_sample_sql() elif os.getenv("TIMEFLOW_DEV") == "false": try: statement = select(TimeLog) results = session.exec(statement) except ProgrammingError: create_db() @app.on_event("startup") def implement_calendar_table(): with
Session(engine)
sqlmodel.Session
import os from fastapi import * from psycopg2.errors import UndefinedTable from sqlmodel import Session, select, text from sqlalchemy.exc import ProgrammingError from .models.timelog import TimeLog from .models.calendar import Calendar from .utils import ( engine, create_db, tags_metadata, execute_sample_sql, ) from .api import ( user, timelog, forecast, epic, epic_area, client, rate, team, role, sponsor, capacity, demand, ) import csv app = FastAPI(title="timeflow app API", openapi_tags=tags_metadata) app.include_router(timelog.router) app.include_router(forecast.router) app.include_router(user.router) app.include_router(epic.router) app.include_router(epic_area.router) app.include_router(client.router) app.include_router(rate.router) app.include_router(team.router) app.include_router(role.router) app.include_router(sponsor.router) app.include_router(capacity.router) app.include_router(demand.router) @app.on_event("startup") def on_startup(): with Session(engine) as session: if os.getenv("TIMEFLOW_DEV") == "true": try: statement =
select(TimeLog)
sqlmodel.select
import os from fastapi import * from psycopg2.errors import UndefinedTable from sqlmodel import Session, select, text from sqlalchemy.exc import ProgrammingError from .models.timelog import TimeLog from .models.calendar import Calendar from .utils import ( engine, create_db, tags_metadata, execute_sample_sql, ) from .api import ( user, timelog, forecast, epic, epic_area, client, rate, team, role, sponsor, capacity, demand, ) import csv app = FastAPI(title="timeflow app API", openapi_tags=tags_metadata) app.include_router(timelog.router) app.include_router(forecast.router) app.include_router(user.router) app.include_router(epic.router) app.include_router(epic_area.router) app.include_router(client.router) app.include_router(rate.router) app.include_router(team.router) app.include_router(role.router) app.include_router(sponsor.router) app.include_router(capacity.router) app.include_router(demand.router) @app.on_event("startup") def on_startup(): with Session(engine) as session: if os.getenv("TIMEFLOW_DEV") == "true": try: statement = select(TimeLog) results = session.exec(statement) except ProgrammingError: create_db() execute_sample_sql() elif os.getenv("TIMEFLOW_DEV") == "false": try: statement =
select(TimeLog)
sqlmodel.select
import os from fastapi import * from psycopg2.errors import UndefinedTable from sqlmodel import Session, select, text from sqlalchemy.exc import ProgrammingError from .models.timelog import TimeLog from .models.calendar import Calendar from .utils import ( engine, create_db, tags_metadata, execute_sample_sql, ) from .api import ( user, timelog, forecast, epic, epic_area, client, rate, team, role, sponsor, capacity, demand, ) import csv app = FastAPI(title="timeflow app API", openapi_tags=tags_metadata) app.include_router(timelog.router) app.include_router(forecast.router) app.include_router(user.router) app.include_router(epic.router) app.include_router(epic_area.router) app.include_router(client.router) app.include_router(rate.router) app.include_router(team.router) app.include_router(role.router) app.include_router(sponsor.router) app.include_router(capacity.router) app.include_router(demand.router) @app.on_event("startup") def on_startup(): with Session(engine) as session: if os.getenv("TIMEFLOW_DEV") == "true": try: statement = select(TimeLog) results = session.exec(statement) except ProgrammingError: create_db() execute_sample_sql() elif os.getenv("TIMEFLOW_DEV") == "false": try: statement = select(TimeLog) results = session.exec(statement) except ProgrammingError: create_db() @app.on_event("startup") def implement_calendar_table(): with Session(engine) as session: try: statement =
select(Calendar.year_name)
sqlmodel.select
import os from fastapi import * from psycopg2.errors import UndefinedTable from sqlmodel import Session, select, text from sqlalchemy.exc import ProgrammingError from .models.timelog import TimeLog from .models.calendar import Calendar from .utils import ( engine, create_db, tags_metadata, execute_sample_sql, ) from .api import ( user, timelog, forecast, epic, epic_area, client, rate, team, role, sponsor, capacity, demand, ) import csv app = FastAPI(title="timeflow app API", openapi_tags=tags_metadata) app.include_router(timelog.router) app.include_router(forecast.router) app.include_router(user.router) app.include_router(epic.router) app.include_router(epic_area.router) app.include_router(client.router) app.include_router(rate.router) app.include_router(team.router) app.include_router(role.router) app.include_router(sponsor.router) app.include_router(capacity.router) app.include_router(demand.router) @app.on_event("startup") def on_startup(): with Session(engine) as session: if os.getenv("TIMEFLOW_DEV") == "true": try: statement = select(TimeLog) results = session.exec(statement) except ProgrammingError: create_db() execute_sample_sql() elif os.getenv("TIMEFLOW_DEV") == "false": try: statement = select(TimeLog) results = session.exec(statement) except ProgrammingError: create_db() @app.on_event("startup") def implement_calendar_table(): with Session(engine) as session: try: statement = select(Calendar.year_name).where(Calendar.id == 1) result = session.exec(statement).one() except Exception as e: print(e) values_sql = f"""INSERT INTO app_db.calendar (date, year_number, year_name, quarter_number, quarter_name , month_number, month_name, week_number, week_name, week_day_number, week_day_name) VALUES """ with open("backend/calendar.csv") as csvfile: reader = csv.reader(csvfile, delimiter=",", quotechar="|") values_list = [] for index, row in enumerate(reader): if index > 0 and row[0] != "": _row = [f"'{item}'" for item in row] row_sql = ", ".join(_row) values = f"({row_sql})," values_sql += values values_sql += f"({row_sql});" session.execute(
text(values_sql)
sqlmodel.text
from sqlmodel import create_engine, SQLModel, Session from .config import settings engine = create_engine( settings.db.uri, echo=settings.db.echo, connect_args=settings.db.connect_args ) def init_db():
SQLModel.metadata.create_all(engine)
sqlmodel.SQLModel.metadata.create_all
from sqlmodel import create_engine, SQLModel, Session from .config import settings engine = create_engine( settings.db.uri, echo=settings.db.echo, connect_args=settings.db.connect_args ) def init_db(): SQLModel.metadata.create_all(engine) def drop_db():
SQLModel.metadata.drop_all(engine)
sqlmodel.SQLModel.metadata.drop_all
from sqlmodel import create_engine, SQLModel, Session from .config import settings engine = create_engine( settings.db.uri, echo=settings.db.echo, connect_args=settings.db.connect_args ) def init_db(): SQLModel.metadata.create_all(engine) def drop_db(): SQLModel.metadata.drop_all(engine) def get_session(): with
Session(engine)
sqlmodel.Session
from sqlmodel import Session from aot_quotes.common.db import Quotes, engine def seed_data(filename): with
Session(engine)
sqlmodel.Session
from unittest.mock import patch import pytest from sqlalchemy.exc import NoResultFound from sqlmodel import Session, create_engine, delete from ...conftest import get_testing_print_function def test_tutorial(clear_sqlmodel): from docs_src.tutorial.one import tutorial005 as mod mod.sqlite_url = "sqlite://" mod.engine =
create_engine(mod.sqlite_url)
sqlmodel.create_engine
from unittest.mock import patch import pytest from sqlalchemy.exc import NoResultFound from sqlmodel import Session, create_engine, delete from ...conftest import get_testing_print_function def test_tutorial(clear_sqlmodel): from docs_src.tutorial.one import tutorial005 as mod mod.sqlite_url = "sqlite://" mod.engine = create_engine(mod.sqlite_url) with pytest.raises(NoResultFound): mod.main() with
Session(mod.engine)
sqlmodel.Session
from unittest.mock import patch import pytest from sqlalchemy.exc import NoResultFound from sqlmodel import Session, create_engine, delete from ...conftest import get_testing_print_function def test_tutorial(clear_sqlmodel): from docs_src.tutorial.one import tutorial005 as mod mod.sqlite_url = "sqlite://" mod.engine = create_engine(mod.sqlite_url) with pytest.raises(NoResultFound): mod.main() with Session(mod.engine) as session: # TODO: create delete() function # TODO: add overloads for .exec() with delete object session.exec(
delete(mod.Hero)
sqlmodel.delete
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] =
Field(default=None, foreign_key="vrf.id", primary_key=True)
sqlmodel.Field
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True) device_id: Optional[int] = Field( default=None, foreign_key="device.id", primary_key=True ) class Platform(SQLModel, table=True): """Used to define platforms""" id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True) device_id: Optional[int] = Field( default=None, foreign_key="device.id", primary_key=True ) class Platform(SQLModel, table=True): """Used to define platforms""" id: Optional[int] = Field(default=None, primary_key=True) platform_name: str =
Field(index=True)
sqlmodel.Field
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True) device_id: Optional[int] = Field( default=None, foreign_key="device.id", primary_key=True ) class Platform(SQLModel, table=True): """Used to define platforms""" id: Optional[int] = Field(default=None, primary_key=True) platform_name: str = Field(index=True) class Vrf(SQLModel, table=True): """used to define VRFs""" id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True) device_id: Optional[int] = Field( default=None, foreign_key="device.id", primary_key=True ) class Platform(SQLModel, table=True): """Used to define platforms""" id: Optional[int] = Field(default=None, primary_key=True) platform_name: str = Field(index=True) class Vrf(SQLModel, table=True): """used to define VRFs""" id: Optional[int] = Field(default=None, primary_key=True) vrf_name: str =
Field(index=True)
sqlmodel.Field
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True) device_id: Optional[int] = Field( default=None, foreign_key="device.id", primary_key=True ) class Platform(SQLModel, table=True): """Used to define platforms""" id: Optional[int] = Field(default=None, primary_key=True) platform_name: str = Field(index=True) class Vrf(SQLModel, table=True): """used to define VRFs""" id: Optional[int] = Field(default=None, primary_key=True) vrf_name: str = Field(index=True) devices: List["Device"] =
Relationship(back_populates="vrfs", link_model=VrfLink)
sqlmodel.Relationship
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True) device_id: Optional[int] = Field( default=None, foreign_key="device.id", primary_key=True ) class Platform(SQLModel, table=True): """Used to define platforms""" id: Optional[int] = Field(default=None, primary_key=True) platform_name: str = Field(index=True) class Vrf(SQLModel, table=True): """used to define VRFs""" id: Optional[int] = Field(default=None, primary_key=True) vrf_name: str = Field(index=True) devices: List["Device"] = Relationship(back_populates="vrfs", link_model=VrfLink) class Device(SQLModel, table=True): """Used to define a simple device""" id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True) device_id: Optional[int] = Field( default=None, foreign_key="device.id", primary_key=True ) class Platform(SQLModel, table=True): """Used to define platforms""" id: Optional[int] = Field(default=None, primary_key=True) platform_name: str = Field(index=True) class Vrf(SQLModel, table=True): """used to define VRFs""" id: Optional[int] = Field(default=None, primary_key=True) vrf_name: str = Field(index=True) devices: List["Device"] = Relationship(back_populates="vrfs", link_model=VrfLink) class Device(SQLModel, table=True): """Used to define a simple device""" id: Optional[int] = Field(default=None, primary_key=True) name: str =
Field(index=True)
sqlmodel.Field
"""All Models for database are defined here""" from typing import Optional, List from sqlalchemy import Column, ForeignKey, Integer from sqlmodel import Field, SQLModel, Relationship class VrfLink(SQLModel, table=True): """Used for vrf to device link""" vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True) device_id: Optional[int] = Field( default=None, foreign_key="device.id", primary_key=True ) class Platform(SQLModel, table=True): """Used to define platforms""" id: Optional[int] = Field(default=None, primary_key=True) platform_name: str = Field(index=True) class Vrf(SQLModel, table=True): """used to define VRFs""" id: Optional[int] = Field(default=None, primary_key=True) vrf_name: str = Field(index=True) devices: List["Device"] = Relationship(back_populates="vrfs", link_model=VrfLink) class Device(SQLModel, table=True): """Used to define a simple device""" id: Optional[int] = Field(default=None, primary_key=True) name: str = Field(index=True) mgmt: str platform_id: Optional[int] = Field( sa_column=Column( Integer, ForeignKey("platform.id", ondelete="SET NULL", onupdate="CASCADE") ) ) vrfs: List["Vrf"] =
Relationship(back_populates="devices", link_model=VrfLink)
sqlmodel.Relationship
from typing import TYPE_CHECKING, List, Optional from sqlmodel import Field, Relationship, SQLModel if TYPE_CHECKING: from .hero import Hero class TeamBase(SQLModel): name: str headquarters: str class Team(TeamBase, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field