prompt
stringlengths
45
17.8k
completion
stringlengths
6
107
api
stringlengths
12
42
from datetime import datetime from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union from uuid import UUID from fastapi_pagination.ext.async_sqlmodel import paginate from fastapi_pagination import Params, Page from fastapi.encoders import jsonable_encoder from pydantic import BaseModel from sqlmodel import SQLModel, select, func from sqlalchemy.orm import selectinload from sqlmodel.ext.asyncio.session import AsyncSession from sqlmodel.sql.expression import Select, SelectOfScalar ModelType = TypeVar("ModelType", bound=SQLModel) CreateSchemaType = TypeVar("CreateSchemaType", bound=BaseModel) UpdateSchemaType = TypeVar("UpdateSchemaType", bound=BaseModel) SchemaType = TypeVar("SchemaType", bound=BaseModel) T = TypeVar("T", bound=SQLModel) class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]): def __init__(self, model: Type[ModelType]): """ CRUD object with default methods to Create, Read, Update, Delete (CRUD). **Parameters** * `model`: A SQLAlchemy model class * `schema`: A Pydantic model (schema) class """ self.model = model async def get( self, db_session: AsyncSession, *, id: Union[UUID, str] ) -> Optional[ModelType]: response = await db_session.exec(select(self.model).where(self.model.id == id).options(selectinload('*'))) return response.first() async def get_by_ids(self, db_session: AsyncSession, list_ids: List[Union[UUID, str]],) -> Optional[List[ModelType]]: response = await db_session.exec(select(self.model).where(self.model.id.in_(list_ids))) return response.all() async def get_count( self, db_session: AsyncSession ) -> Optional[ModelType]: response = await db_session.exec(select(
func.count()
sqlmodel.func.count
from datetime import datetime from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union from uuid import UUID from fastapi_pagination.ext.async_sqlmodel import paginate from fastapi_pagination import Params, Page from fastapi.encoders import jsonable_encoder from pydantic import BaseModel from sqlmodel import SQLModel, select, func from sqlalchemy.orm import selectinload from sqlmodel.ext.asyncio.session import AsyncSession from sqlmodel.sql.expression import Select, SelectOfScalar ModelType = TypeVar("ModelType", bound=SQLModel) CreateSchemaType = TypeVar("CreateSchemaType", bound=BaseModel) UpdateSchemaType = TypeVar("UpdateSchemaType", bound=BaseModel) SchemaType = TypeVar("SchemaType", bound=BaseModel) T = TypeVar("T", bound=SQLModel) class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]): def __init__(self, model: Type[ModelType]): """ CRUD object with default methods to Create, Read, Update, Delete (CRUD). **Parameters** * `model`: A SQLAlchemy model class * `schema`: A Pydantic model (schema) class """ self.model = model async def get( self, db_session: AsyncSession, *, id: Union[UUID, str] ) -> Optional[ModelType]: response = await db_session.exec(select(self.model).where(self.model.id == id).options(selectinload('*'))) return response.first() async def get_by_ids(self, db_session: AsyncSession, list_ids: List[Union[UUID, str]],) -> Optional[List[ModelType]]: response = await db_session.exec(select(self.model).where(self.model.id.in_(list_ids))) return response.all() async def get_count( self, db_session: AsyncSession ) -> Optional[ModelType]: response = await db_session.exec(select(func.count()).select_from(
select(self.model)
sqlmodel.select
from datetime import datetime from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union from uuid import UUID from fastapi_pagination.ext.async_sqlmodel import paginate from fastapi_pagination import Params, Page from fastapi.encoders import jsonable_encoder from pydantic import BaseModel from sqlmodel import SQLModel, select, func from sqlalchemy.orm import selectinload from sqlmodel.ext.asyncio.session import AsyncSession from sqlmodel.sql.expression import Select, SelectOfScalar ModelType = TypeVar("ModelType", bound=SQLModel) CreateSchemaType = TypeVar("CreateSchemaType", bound=BaseModel) UpdateSchemaType = TypeVar("UpdateSchemaType", bound=BaseModel) SchemaType = TypeVar("SchemaType", bound=BaseModel) T = TypeVar("T", bound=SQLModel) class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]): def __init__(self, model: Type[ModelType]): """ CRUD object with default methods to Create, Read, Update, Delete (CRUD). **Parameters** * `model`: A SQLAlchemy model class * `schema`: A Pydantic model (schema) class """ self.model = model async def get( self, db_session: AsyncSession, *, id: Union[UUID, str] ) -> Optional[ModelType]: response = await db_session.exec(
select(self.model)
sqlmodel.select
from datetime import datetime from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union from uuid import UUID from fastapi_pagination.ext.async_sqlmodel import paginate from fastapi_pagination import Params, Page from fastapi.encoders import jsonable_encoder from pydantic import BaseModel from sqlmodel import SQLModel, select, func from sqlalchemy.orm import selectinload from sqlmodel.ext.asyncio.session import AsyncSession from sqlmodel.sql.expression import Select, SelectOfScalar ModelType = TypeVar("ModelType", bound=SQLModel) CreateSchemaType = TypeVar("CreateSchemaType", bound=BaseModel) UpdateSchemaType = TypeVar("UpdateSchemaType", bound=BaseModel) SchemaType = TypeVar("SchemaType", bound=BaseModel) T = TypeVar("T", bound=SQLModel) class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]): def __init__(self, model: Type[ModelType]): """ CRUD object with default methods to Create, Read, Update, Delete (CRUD). **Parameters** * `model`: A SQLAlchemy model class * `schema`: A Pydantic model (schema) class """ self.model = model async def get( self, db_session: AsyncSession, *, id: Union[UUID, str] ) -> Optional[ModelType]: response = await db_session.exec(select(self.model).where(self.model.id == id).options(selectinload('*'))) return response.first() async def get_by_ids(self, db_session: AsyncSession, list_ids: List[Union[UUID, str]],) -> Optional[List[ModelType]]: response = await db_session.exec(select(self.model).where(self.model.id.in_(list_ids))) return response.all() async def get_count( self, db_session: AsyncSession ) -> Optional[ModelType]: response = await db_session.exec(select(func.count()).select_from(select(self.model).subquery())) return response.one() async def get_multi( self, db_session: AsyncSession, *, skip: int = 0, limit: int = 100 ) -> List[ModelType]: response = await db_session.exec(
select(self.model)
sqlmodel.select
"""v1-messages Revision ID: b01986f67aa3 Revises: <KEY> Create Date: 2022-06-01 16:00:25.954662 """ from alembic import op import sqlalchemy as sa import sqlmodel from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = "<KEY>" down_revision = "c9b007919a5d" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "message", sa.Column( "message_id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False, ), sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True), sa.Column("sent_time", postgresql.TIMESTAMP(), nullable=True), sa.Column( "created_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column( "updated_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column("tenant_id",
sqlmodel.sql.sqltypes.GUID()
sqlmodel.sql.sqltypes.GUID
"""v1-messages Revision ID: b01986f67aa3 Revises: <KEY> Create Date: 2022-06-01 16:00:25.954662 """ from alembic import op import sqlalchemy as sa import sqlmodel from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = "<KEY>" down_revision = "c9b007919a5d" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "message", sa.Column( "message_id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False, ), sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True), sa.Column("sent_time", postgresql.TIMESTAMP(), nullable=True), sa.Column( "created_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column( "updated_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column("tenant_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("contact_id",
sqlmodel.sql.sqltypes.GUID()
sqlmodel.sql.sqltypes.GUID
"""v1-messages Revision ID: b01986f67aa3 Revises: <KEY> Create Date: 2022-06-01 16:00:25.954662 """ from alembic import op import sqlalchemy as sa import sqlmodel from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = "<KEY>" down_revision = "c9b007919a5d" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "message", sa.Column( "message_id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False, ), sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True), sa.Column("sent_time", postgresql.TIMESTAMP(), nullable=True), sa.Column( "created_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column( "updated_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column("tenant_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("contact_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("status",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""v1-messages Revision ID: b01986f67aa3 Revises: <KEY> Create Date: 2022-06-01 16:00:25.954662 """ from alembic import op import sqlalchemy as sa import sqlmodel from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = "<KEY>" down_revision = "c9b007919a5d" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "message", sa.Column( "message_id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False, ), sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True), sa.Column("sent_time", postgresql.TIMESTAMP(), nullable=True), sa.Column( "created_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column( "updated_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column("tenant_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("contact_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("role",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""v1-messages Revision ID: b01986f67aa3 Revises: <KEY> Create Date: 2022-06-01 16:00:25.954662 """ from alembic import op import sqlalchemy as sa import sqlmodel from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = "<KEY>" down_revision = "c9b007919a5d" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "message", sa.Column( "message_id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False, ), sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True), sa.Column("sent_time", postgresql.TIMESTAMP(), nullable=True), sa.Column( "created_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column( "updated_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column("tenant_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("contact_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("role", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("deleted", sa.Boolean(), nullable=False), sa.Column("content",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""v1-messages Revision ID: b01986f67aa3 Revises: <KEY> Create Date: 2022-06-01 16:00:25.954662 """ from alembic import op import sqlalchemy as sa import sqlmodel from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = "<KEY>" down_revision = "c9b007919a5d" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "message", sa.Column( "message_id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False, ), sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True), sa.Column("sent_time", postgresql.TIMESTAMP(), nullable=True), sa.Column( "created_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column( "updated_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column("tenant_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("contact_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("role", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("deleted", sa.Boolean(), nullable=False), sa.Column("content", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column( "revocation_comment",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""v1-messages Revision ID: b01986f67aa3 Revises: <KEY> Create Date: 2022-06-01 16:00:25.954662 """ from alembic import op import sqlalchemy as sa import sqlmodel from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = "<KEY>" down_revision = "c9b007919a5d" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( "message", sa.Column( "message_id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False, ), sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True), sa.Column("sent_time", postgresql.TIMESTAMP(), nullable=True), sa.Column( "created_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column( "updated_at", postgresql.TIMESTAMP(), server_default=sa.text("now()"), nullable=False, ), sa.Column("tenant_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("contact_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("role", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("deleted", sa.Boolean(), nullable=False), sa.Column("content", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column( "revocation_comment", sqlmodel.sql.sqltypes.AutoString(), nullable=True ), sa.Column("state",
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine =
create_engine(sqlite_url, echo=True)
sqlmodel.create_engine
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables():
SQLModel.metadata.create_all(engine)
sqlmodel.SQLModel.metadata.create_all
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement =
select(ProductType)
sqlmodel.select
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement =
select(Tag)
sqlmodel.select
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with Session(engine) as session: statement = select(Tag).limit(4) results = session.exec(statement) tags = results.all() print(tags) def select_next_four_tags(): with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with Session(engine) as session: statement = select(Tag).limit(4) results = session.exec(statement) tags = results.all() print(tags) def select_next_four_tags(): with Session(engine) as session: statement = select(Tag).offset(4).limit(4) results = session.exec(statement) tags = results.all() print(tags) def update_tag(): with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with Session(engine) as session: statement = select(Tag).limit(4) results = session.exec(statement) tags = results.all() print(tags) def select_next_four_tags(): with Session(engine) as session: statement = select(Tag).offset(4).limit(4) results = session.exec(statement) tags = results.all() print(tags) def update_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == "Con Maionese") results = session.exec(statement) # mayo = results.one() mayo = results.first() print("Tag:", mayo) mayo.name = "<NAME>" session.add(mayo) session.commit() session.refresh(mayo) print(mayo) def delete_tag(): with
Session(engine)
sqlmodel.Session
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement =
select(ProductType)
sqlmodel.select
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement =
select(Tag)
sqlmodel.select
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with Session(engine) as session: statement =
select(Tag)
sqlmodel.select
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with Session(engine) as session: statement = select(Tag).limit(4) results = session.exec(statement) tags = results.all() print(tags) def select_next_four_tags(): with Session(engine) as session: statement = select(Tag).offset(4).limit(4) results = session.exec(statement) tags = results.all() print(tags) def update_tag(): with Session(engine) as session: statement =
select(Tag)
sqlmodel.select
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with Session(engine) as session: statement = select(Tag).limit(4) results = session.exec(statement) tags = results.all() print(tags) def select_next_four_tags(): with Session(engine) as session: statement = select(Tag).offset(4).limit(4) results = session.exec(statement) tags = results.all() print(tags) def update_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == "Con Maionese") results = session.exec(statement) # mayo = results.one() mayo = results.first() print("Tag:", mayo) mayo.name = "<NAME>" session.add(mayo) session.commit() session.refresh(mayo) print(mayo) def delete_tag(): with Session(engine) as session: statement =
select(Tag)
sqlmodel.select
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with Session(engine) as session: statement = select(Tag).limit(4) results = session.exec(statement) tags = results.all() print(tags) def select_next_four_tags(): with Session(engine) as session: statement = select(Tag).offset(4).limit(4) results = session.exec(statement) tags = results.all() print(tags) def update_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == "Con Maionese") results = session.exec(statement) # mayo = results.one() mayo = results.first() print("Tag:", mayo) mayo.name = "<NAME>" session.add(mayo) session.commit() session.refresh(mayo) print(mayo) def delete_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == "<NAME>") results = session.exec(statement) no_mayo = results.first() print("no_mayo: ", no_mayo) session.delete(no_mayo) session.commit() print("Deleted:", no_mayo) statement =
select(Tag)
sqlmodel.select
# Lettura dati con SQLModel, all, first, one; update; delete # https://sqlmodel.tiangolo.com/tutorial/select/ e seguito from typing import Optional from sqlmodel import Field, SQLModel, Session, create_engine, select class Tag(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class ProductType(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" engine = create_engine(sqlite_url, echo=True) def create_db_and_tables(): SQLModel.metadata.create_all(engine) def create_entities(): tag_offerta = Tag(name="Offerta") tag_maionese = Tag(name="Con Maionese") tipo_panino = ProductType(name="panino") tipo_bibita = ProductType(name="bibita") with Session(engine) as session: session.add(tag_offerta) session.add(tag_maionese) session.add(tipo_panino) session.add(tipo_bibita) session.commit() print("After committing the session") print("Tag 1:", tag_offerta) # No refresh, no print print("Product Type 1:", tipo_panino) # Refresh automatica print("Product Type 1:", tipo_panino.name) # Refresh esplicita session.refresh(tipo_bibita) session.refresh(tag_maionese) print("Product Type 2:", tipo_bibita) print("After the session closes") print("Tag 2:", tag_maionese) def select_product_types(): with Session(engine) as session: statement = select(ProductType) results = session.exec(statement) for product_type in results: print("product_type:", product_type) def select_product_type_panino(): with Session(engine) as session: statement = select(ProductType).where(ProductType.name == 'panino') results = session.exec(statement) for product_type in results: print("panino:", product_type) def select_first_row_tag(): with Session(engine) as session: statement = select(Tag).where(Tag.name == 'Offerta') results = session.exec(statement) tag = results.first() print("first:", tag) def select_all_tags(): with Session(engine) as session: statement = select(Tag) results = session.exec(statement) tags = results.all() print(tags) def select_four_tags(): with Session(engine) as session: statement = select(Tag).limit(4) results = session.exec(statement) tags = results.all() print(tags) def select_next_four_tags(): with Session(engine) as session: statement =
select(Tag)
sqlmodel.select
from datetime import datetime from os import getenv from typing import Optional from fastapi import FastAPI import strawberry from strawberry.asgi import GraphQL from sqlmodel import create_engine, SQLModel from api.models import PostQL from api.crud import create_post, get_posts ENGINE = create_engine(getenv("DATABASE_URL")) @strawberry.type class Query: @strawberry.field def post(self, slug: Optional[str] = None) -> list[PostQL]: return get_posts(ENGINE, slug) @strawberry.type class Mutation: @strawberry.field def add_post(self, slug: str, title: str, content: str, published: bool) -> PostQL: return create_post( ENGINE, PostQL( slug=slug, title=title, content=content, published=published, published_at=datetime.now(), ), ) schema = strawberry.Schema(query=Query, mutation=Mutation)
SQLModel.metadata.create_all(ENGINE)
sqlmodel.SQLModel.metadata.create_all
from typing import List, Dict from fastapi import APIRouter, Depends, HTTPException, Query from sqlmodel import Session, select from app import models from app.api import deps router = APIRouter() @router.post("/", response_model=models.TeamRead) def create_team( *, session: Session = Depends(deps.get_session), team: models.TeamCreate ) -> models.Team: db_team = models.Team.from_orm(team) session.add(db_team) session.commit() session.refresh(db_team) return db_team @router.get("/", response_model=List[models.TeamRead]) def read_teams( *, session: Session = Depends(deps.get_session), offset: int = 0, limit: int = Query(default=100, lte=100), ) -> List[models.Team]: teams = session.exec(
select(models.Team)
sqlmodel.select
from datetime import datetime from typing import Optional from fastapi import APIRouter from sqlmodel import Field, SQLModel router = APIRouter() class Disease(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from datetime import datetime from typing import Optional from fastapi import APIRouter from sqlmodel import Field, SQLModel router = APIRouter() class Disease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroup(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from datetime import datetime from typing import Optional from fastapi import APIRouter from sqlmodel import Field, SQLModel router = APIRouter() class Disease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroup(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroupMap(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from datetime import datetime from typing import Optional from fastapi import APIRouter from sqlmodel import Field, SQLModel router = APIRouter() class Disease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroup(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroupMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) disease_group_id: int disease_id: int class PatientDisease(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from datetime import datetime from typing import Optional from fastapi import APIRouter from sqlmodel import Field, SQLModel router = APIRouter() class Disease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroup(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroupMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) disease_group_id: int disease_id: int class PatientDisease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_id: int doctor_id: Optional[int] = None cleft: bool craniofacial: bool syndronic: bool non: bool comorbidity: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseList(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from datetime import datetime from typing import Optional from fastapi import APIRouter from sqlmodel import Field, SQLModel router = APIRouter() class Disease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroup(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroupMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) disease_group_id: int disease_id: int class PatientDisease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_id: int doctor_id: Optional[int] = None cleft: bool craniofacial: bool syndronic: bool non: bool comorbidity: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseList(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_disease_id: int disease_id: int detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseCleft(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from datetime import datetime from typing import Optional from fastapi import APIRouter from sqlmodel import Field, SQLModel router = APIRouter() class Disease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroup(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroupMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) disease_group_id: int disease_id: int class PatientDisease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_id: int doctor_id: Optional[int] = None cleft: bool craniofacial: bool syndronic: bool non: bool comorbidity: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseList(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_disease_id: int disease_id: int detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseCleft(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_disease_id: int cleft_type: str cleft_lateral: str cleft_side: str cleft_complete: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseCraniofacial(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from datetime import datetime from typing import Optional from fastapi import APIRouter from sqlmodel import Field, SQLModel router = APIRouter() class Disease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroup(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str class DiseaseGroupMap(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) disease_group_id: int disease_id: int class PatientDisease(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_id: int doctor_id: Optional[int] = None cleft: bool craniofacial: bool syndronic: bool non: bool comorbidity: bool created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseList(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_disease_id: int disease_id: int detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseCleft(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_disease_id: int cleft_type: str cleft_lateral: str cleft_side: str cleft_complete: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseCraniofacial(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) patient_disease_id: int micrognathia_detail: str craniofacial_cleft_right: int craniofacial_cleft_medial: int craniofacial_cleft_left: int feem_nasofrontal: bool feem_nasofrontal_side: str feem_nasoethmoidal: bool feem_nasoethmoidal_side: str feem_mix: bool feem_mix_side: str feem_mix_detail: str craniofacial_microsomia_side: str craniofacial_microsomia_detail: str microtia_side: str microtia_detail: str craniosynostosis_detail: str frontonasal_dysplasia_detail: str created_at: datetime updated_at: datetime created_by: int updated_by: Optional[int] = None class PatientDiseaseOther(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from worker import writer, scanTemplates from utils.manager import TrainManager import time from db import engine from sqlmodel import Session from models import Logrun,Usefuel, Template import cachetool import inspect from disclog import postLog,postGeneric def filler(posrr,posm) -> str: start=time.time() manager = TrainManager(posrr=posrr, posm=posm) run = True postGeneric([("info","API init success! Logger started.")],"Startup") while run: try: manager.fetch() if len(manager.out) > 0: writer.delay(manager.out,"action") manager.out = [] except Exception as e: postLog(e,"error",f"{inspect.stack()[0][3]}:{inspect.stack()[0][2]}") time.sleep(30) return f"{(time.time()-start)} total time" if __name__ == "__main__": startup = True while startup: try: with
Session(engine)
sqlmodel.Session
from typing import Optional import strawberry from sqlmodel import ( SQLModel, Field, create_engine, select, Session ) engine =
create_engine('sqlite:///database.db')
sqlmodel.create_engine
from typing import Optional import strawberry from sqlmodel import ( SQLModel, Field, create_engine, select, Session ) engine = create_engine('sqlite:///database.db') class Person(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) nome: str idade: int
SQLModel.metadata.create_all(engine)
sqlmodel.SQLModel.metadata.create_all
from typing import Optional import strawberry from sqlmodel import ( SQLModel, Field, create_engine, select, Session ) engine = create_engine('sqlite:///database.db') class Person(SQLModel, table=True): id: Optional[int] =
Field(default=None, primary_key=True)
sqlmodel.Field
from typing import Optional import strawberry from sqlmodel import ( SQLModel, Field, create_engine, select, Session ) engine = create_engine('sqlite:///database.db') class Person(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) nome: str idade: int SQLModel.metadata.create_all(engine) def create_app(nome: str, idade:int): person = Person(nome=nome, idade=idade) with
Session(engine)
sqlmodel.Session
from typing import Optional import strawberry from sqlmodel import ( SQLModel, Field, create_engine, select, Session ) engine = create_engine('sqlite:///database.db') class Person(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) nome: str idade: int SQLModel.metadata.create_all(engine) def create_app(nome: str, idade:int): person = Person(nome=nome, idade=idade) with Session(engine) as session: session.add(person) session.commit() session.refresh(person) return person @strawberry.type class Pessoa: id: Optional[int] nome: str idade: int @strawberry.type class Query: @strawberry.field def all_pessoa(self) -> list[Pessoa]: query =
select(Person)
sqlmodel.select
from typing import Optional import strawberry from sqlmodel import ( SQLModel, Field, create_engine, select, Session ) engine = create_engine('sqlite:///database.db') class Person(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) nome: str idade: int SQLModel.metadata.create_all(engine) def create_app(nome: str, idade:int): person = Person(nome=nome, idade=idade) with Session(engine) as session: session.add(person) session.commit() session.refresh(person) return person @strawberry.type class Pessoa: id: Optional[int] nome: str idade: int @strawberry.type class Query: @strawberry.field def all_pessoa(self) -> list[Pessoa]: query = select(Person) with
Session(engine)
sqlmodel.Session
from fastapi.exceptions import HTTPException from sfm.models import Project, WorkItem from sqlmodel import Session, select from opencensus.ext.azure.log_exporter import AzureLogHandler from sfm.config import get_settings from sfm.logger import create_logger from sfm.utils import ( create_project_auth_token, hash_project_auth_token, verify_admin_key, ) app_settings = get_settings() logger = create_logger(__name__) def get_all(db: Session, skip: int = None, limit: int = None): """Get all the projects and return them.""" projects = db.exec( select(Project).order_by(Project.id).offset(skip).limit(limit) ).all() if not projects: logger.debug("Projects not found") raise HTTPException(status_code=404, detail="Projects not found") return projects def get_by_id(db: Session, project_id: int): """Get the project with corresponding id and return it.""" project = db.get(Project, project_id) if not project: logger.debug("Projects not found") raise HTTPException(status_code=404, detail="Project not found") return project def create_project(db: Session, project_data, admin_key): """Take data from request and create a new project in the database.""" project_name_repeat = db.exec( select(Project).where(Project.name == project_data.name) ).first() if project_name_repeat is not None: logger.debug("Database entry already exists") raise HTTPException(status_code=409, detail="Database entry already exists") verified_admin = verify_admin_key(admin_key) if verified_admin: project_temp = project_data.dict() token = create_project_auth_token() hashed_token = hash_project_auth_token(token) project_temp.update({"project_auth_token_hashed": hashed_token}) project_db = Project(**project_temp) db.add(project_db) db.commit() else: logger.warning("Attempted to verify as an admin with incorrect credentials") raise HTTPException(status_code=401, detail="Credentials are incorrect") # Check the new record db.refresh(project_db) new_project = db.get(Project, project_db.id) if new_project.name == project_data.name: return [new_project, token] # successfully created record else: logger.error("Project did not store correctly in database") return False # didn't store correctly def delete_project(db: Session, project_id, admin_key): """Take a project_name and remove the row from the database.""" verified_admin = verify_admin_key(admin_key) if verified_admin: project = db.get(Project, project_id) if not project: logger.debug("Project not found") raise HTTPException(status_code=404, detail="Project not found") for item in project.work_items: db.delete(item) db.delete(project) db.commit() else: logger.warning("Attempted to verify as admin with incorrect credentials") raise HTTPException(status_code=401, detail="Credentials are incorrect") # Check our work row = db.get(Project, project_id) if row: logger.error("Project did not delete correctly") return False # Row didn't successfully delete or another one exists else: return True # Successful deletion def refresh_project_key(db: Session, project_id, admin_key): verified_admin = verify_admin_key(admin_key) if verified_admin: project_db = db.get(Project, project_id) if not project_db: logger.debug("Project with matching id not found") raise HTTPException( status_code=404, detail="Project with matching id not found" ) new_token = create_project_auth_token() hashed_token = hash_project_auth_token(new_token) project_db.project_auth_token_hashed = hashed_token db.add(project_db) db.commit() else: logger.warning("Attempted to verify as admin with incorrect credentials") raise HTTPException(status_code=401, detail="Credentials are incorrect") check = db.exec(
select(Project)
sqlmodel.select
from fastapi.exceptions import HTTPException from sfm.models import Project, WorkItem from sqlmodel import Session, select from opencensus.ext.azure.log_exporter import AzureLogHandler from sfm.config import get_settings from sfm.logger import create_logger from sfm.utils import ( create_project_auth_token, hash_project_auth_token, verify_admin_key, ) app_settings = get_settings() logger = create_logger(__name__) def get_all(db: Session, skip: int = None, limit: int = None): """Get all the projects and return them.""" projects = db.exec( select(Project).order_by(Project.id).offset(skip).limit(limit) ).all() if not projects: logger.debug("Projects not found") raise HTTPException(status_code=404, detail="Projects not found") return projects def get_by_id(db: Session, project_id: int): """Get the project with corresponding id and return it.""" project = db.get(Project, project_id) if not project: logger.debug("Projects not found") raise HTTPException(status_code=404, detail="Project not found") return project def create_project(db: Session, project_data, admin_key): """Take data from request and create a new project in the database.""" project_name_repeat = db.exec(
select(Project)
sqlmodel.select
from fastapi.exceptions import HTTPException from sfm.models import Project, WorkItem from sqlmodel import Session, select from opencensus.ext.azure.log_exporter import AzureLogHandler from sfm.config import get_settings from sfm.logger import create_logger from sfm.utils import ( create_project_auth_token, hash_project_auth_token, verify_admin_key, ) app_settings = get_settings() logger = create_logger(__name__) def get_all(db: Session, skip: int = None, limit: int = None): """Get all the projects and return them.""" projects = db.exec(
select(Project)
sqlmodel.select
from sqlmodel import Session, select from sqlalchemy.orm import joinedload from .models import Pessoa, Livro, engine def create_livros(titulo: str, pessoa_id: int): livro = Livro(titulo=titulo, pessoa_id=pessoa_id) with Session(engine) as session: session.add(livro) session.commit() session.refresh(livro) return livro def get_livros(): query = select(Livro).options(joinedload('*')) with Session(engine) as session: result = session.execute(query).scalars().unique().all() return result def create_pessoas(idade: int, nome: str): person = Pessoa(nome=nome, idade=idade) with Session(engine) as session: session.add(person) session.commit() session.refresh(person) return person def get_pessoas( id: int = None, idade: int = None, limit: int = 5, ): query =
select(Pessoa)
sqlmodel.select
from sqlmodel import Session, select from sqlalchemy.orm import joinedload from .models import Pessoa, Livro, engine def create_livros(titulo: str, pessoa_id: int): livro = Livro(titulo=titulo, pessoa_id=pessoa_id) with
Session(engine)
sqlmodel.Session
from sqlmodel import Session, select from sqlalchemy.orm import joinedload from .models import Pessoa, Livro, engine def create_livros(titulo: str, pessoa_id: int): livro = Livro(titulo=titulo, pessoa_id=pessoa_id) with Session(engine) as session: session.add(livro) session.commit() session.refresh(livro) return livro def get_livros(): query = select(Livro).options(joinedload('*')) with
Session(engine)
sqlmodel.Session
from sqlmodel import Session, select from sqlalchemy.orm import joinedload from .models import Pessoa, Livro, engine def create_livros(titulo: str, pessoa_id: int): livro = Livro(titulo=titulo, pessoa_id=pessoa_id) with Session(engine) as session: session.add(livro) session.commit() session.refresh(livro) return livro def get_livros(): query = select(Livro).options(joinedload('*')) with Session(engine) as session: result = session.execute(query).scalars().unique().all() return result def create_pessoas(idade: int, nome: str): person = Pessoa(nome=nome, idade=idade) with
Session(engine)
sqlmodel.Session
from sqlmodel import Session, select from sqlalchemy.orm import joinedload from .models import Pessoa, Livro, engine def create_livros(titulo: str, pessoa_id: int): livro = Livro(titulo=titulo, pessoa_id=pessoa_id) with Session(engine) as session: session.add(livro) session.commit() session.refresh(livro) return livro def get_livros(): query = select(Livro).options(joinedload('*')) with Session(engine) as session: result = session.execute(query).scalars().unique().all() return result def create_pessoas(idade: int, nome: str): person = Pessoa(nome=nome, idade=idade) with Session(engine) as session: session.add(person) session.commit() session.refresh(person) return person def get_pessoas( id: int = None, idade: int = None, limit: int = 5, ): query = select(Pessoa) if id: query = query.where(Pessoa.id == id) if idade: query = query.where(Pessoa.idade == idade) if limit: query = query.limit(limit) with
Session(engine)
sqlmodel.Session
from sqlmodel import Session, select from sqlalchemy.orm import joinedload from .models import Pessoa, Livro, engine def create_livros(titulo: str, pessoa_id: int): livro = Livro(titulo=titulo, pessoa_id=pessoa_id) with Session(engine) as session: session.add(livro) session.commit() session.refresh(livro) return livro def get_livros(): query =
select(Livro)
sqlmodel.select
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] = Field(default=None) collection: Optional[str] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] = Field(default=None) collection: Optional[str] = Field(default=None) # dates when: int release_date: Optional[date] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] = Field(default=None) collection: Optional[str] = Field(default=None) # dates when: int release_date: Optional[date] = Field(default=None) # urls image_url: Optional[str] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] = Field(default=None) collection: Optional[str] = Field(default=None) # dates when: int release_date: Optional[date] = Field(default=None) # urls image_url: Optional[str] = Field(default=None) url: Optional[str] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] = Field(default=None) collection: Optional[str] = Field(default=None) # dates when: int release_date: Optional[date] = Field(default=None) # urls image_url: Optional[str] = Field(default=None) url: Optional[str] = Field(default=None) # feedbase, with an ID/table class FeedModel(FeedBase, table=True): # type: ignore id: int =
Field(index=True, primary_key=True)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] = Field(default=None) collection: Optional[str] = Field(default=None) # dates when: int release_date: Optional[date] = Field(default=None) # urls image_url: Optional[str] = Field(default=None) url: Optional[str] = Field(default=None) # feedbase, with an ID/table class FeedModel(FeedBase, table=True): # type: ignore id: int = Field(index=True, primary_key=True) # store JSON as strings, these are only used on the frontend anyways tags: str = Field(default=r"[]") # List[str] data: Optional[bytes] =
Field(default=None)
sqlmodel.Field
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] = Field(default=None) collection: Optional[str] = Field(default=None) # dates when: int release_date: Optional[date] = Field(default=None) # urls image_url: Optional[str] = Field(default=None) url: Optional[str] = Field(default=None) # feedbase, with an ID/table class FeedModel(FeedBase, table=True): # type: ignore id: int = Field(index=True, primary_key=True) # store JSON as strings, these are only used on the frontend anyways tags: str = Field(default=r"[]") # List[str] data: Optional[bytes] = Field(default=None) # Dict[str, Any] feed_engine = create_engine( settings.SQLITE_DB_PATH, echo=settings.SQL_ECHO, ) def init_db() -> None: logger.info("Creating tables...")
SQLModel.metadata.create_all(feed_engine)
sqlmodel.SQLModel.metadata.create_all
from datetime import date from typing import Optional, Iterator from sqlmodel import SQLModel, Field, create_engine, Session # type: ignore[import] from my_feed.log import logger from app.settings import settings # base non-table sql model class FeedBase(SQLModel): # type: ignore[misc] model_id: str ftype: str # feed item type title: str score: Optional[float] = Field(default=None) # more metadata subtitle: Optional[str] = Field(default=None) creator: Optional[str] = Field(default=None) part: Optional[int] = Field(default=None) subpart: Optional[int] = Field(default=None) collection: Optional[str] = Field(default=None) # dates when: int release_date: Optional[date] = Field(default=None) # urls image_url: Optional[str] = Field(default=None) url: Optional[str] = Field(default=None) # feedbase, with an ID/table class FeedModel(FeedBase, table=True): # type: ignore id: int = Field(index=True, primary_key=True) # store JSON as strings, these are only used on the frontend anyways tags: str = Field(default=r"[]") # List[str] data: Optional[bytes] = Field(default=None) # Dict[str, Any] feed_engine = create_engine( settings.SQLITE_DB_PATH, echo=settings.SQL_ECHO, ) def init_db() -> None: logger.info("Creating tables...") SQLModel.metadata.create_all(feed_engine) def get_db() -> Iterator[Session]: with
Session(feed_engine)
sqlmodel.Session
""" Utility functions. """ import logging import os from functools import lru_cache from pathlib import Path from typing import Iterator, List, Optional from dotenv import load_dotenv from rich.logging import RichHandler from sqlalchemy.engine import Engine from sqlmodel import Session, SQLModel, create_engine from yarl import URL from datajunction.config import Settings from datajunction.typing import ColumnType def setup_logging(loglevel: str) -> None: """ Setup basic logging. """ level = getattr(logging, loglevel.upper(), None) if not isinstance(level, int): raise ValueError(f"Invalid log level: {loglevel}") logformat = "[%(asctime)s] %(levelname)s: %(name)s: %(message)s" logging.basicConfig( level=level, format=logformat, datefmt="[%X]", handlers=[RichHandler(rich_tracebacks=True)], force=True, ) def get_project_repository() -> Path: """ Return the project repository. This is used for unit tests. """ return Path(__file__).parent.parent.parent @lru_cache def get_settings() -> Settings: """ Return a cached settings object. """ dotenv_file = os.environ.get("DOTENV_FILE", ".env") load_dotenv(dotenv_file) return Settings() def get_engine() -> Engine: """ Create the metadata engine. """ settings = get_settings() engine =
create_engine(settings.index)
sqlmodel.create_engine
""" Utility functions. """ import logging import os from functools import lru_cache from pathlib import Path from typing import Iterator, List, Optional from dotenv import load_dotenv from rich.logging import RichHandler from sqlalchemy.engine import Engine from sqlmodel import Session, SQLModel, create_engine from yarl import URL from datajunction.config import Settings from datajunction.typing import ColumnType def setup_logging(loglevel: str) -> None: """ Setup basic logging. """ level = getattr(logging, loglevel.upper(), None) if not isinstance(level, int): raise ValueError(f"Invalid log level: {loglevel}") logformat = "[%(asctime)s] %(levelname)s: %(name)s: %(message)s" logging.basicConfig( level=level, format=logformat, datefmt="[%X]", handlers=[RichHandler(rich_tracebacks=True)], force=True, ) def get_project_repository() -> Path: """ Return the project repository. This is used for unit tests. """ return Path(__file__).parent.parent.parent @lru_cache def get_settings() -> Settings: """ Return a cached settings object. """ dotenv_file = os.environ.get("DOTENV_FILE", ".env") load_dotenv(dotenv_file) return Settings() def get_engine() -> Engine: """ Create the metadata engine. """ settings = get_settings() engine = create_engine(settings.index) return engine def create_db_and_tables() -> None: """ Create the database and tables. """ engine = get_engine()
SQLModel.metadata.create_all(engine)
sqlmodel.SQLModel.metadata.create_all
""" Utility functions. """ import logging import os from functools import lru_cache from pathlib import Path from typing import Iterator, List, Optional from dotenv import load_dotenv from rich.logging import RichHandler from sqlalchemy.engine import Engine from sqlmodel import Session, SQLModel, create_engine from yarl import URL from datajunction.config import Settings from datajunction.typing import ColumnType def setup_logging(loglevel: str) -> None: """ Setup basic logging. """ level = getattr(logging, loglevel.upper(), None) if not isinstance(level, int): raise ValueError(f"Invalid log level: {loglevel}") logformat = "[%(asctime)s] %(levelname)s: %(name)s: %(message)s" logging.basicConfig( level=level, format=logformat, datefmt="[%X]", handlers=[RichHandler(rich_tracebacks=True)], force=True, ) def get_project_repository() -> Path: """ Return the project repository. This is used for unit tests. """ return Path(__file__).parent.parent.parent @lru_cache def get_settings() -> Settings: """ Return a cached settings object. """ dotenv_file = os.environ.get("DOTENV_FILE", ".env") load_dotenv(dotenv_file) return Settings() def get_engine() -> Engine: """ Create the metadata engine. """ settings = get_settings() engine = create_engine(settings.index) return engine def create_db_and_tables() -> None: """ Create the database and tables. """ engine = get_engine() SQLModel.metadata.create_all(engine) def get_session() -> Iterator[Session]: """ Per-request session. """ engine = get_engine() with
Session(engine, autoflush=False)
sqlmodel.Session
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] =
Field(primary_key=True, default=None)
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str =
Field()
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int =
Field()
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] =
Field(primary_key=True, default=None)
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str =
Field()
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" =
Relationship(back_populates="manager")
sqlmodel.Relationship
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] =
Field(primary_key=True, default=None)
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str =
Field(index=True)
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] =
Field(default=None)
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] = Field(default=None) manager_id: int =
Field(nullable=False, foreign_key="manager.id")
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] = Field(default=None) manager_id: int = Field(nullable=False, foreign_key="manager.id") manager: Manager =
Relationship(back_populates="managed_team")
sqlmodel.Relationship
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] = Field(default=None) manager_id: int = Field(nullable=False, foreign_key="manager.id") manager: Manager = Relationship(back_populates="managed_team") heroes: List["Hero"] =
Relationship(back_populates="team")
sqlmodel.Relationship
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] = Field(default=None) manager_id: int = Field(nullable=False, foreign_key="manager.id") manager: Manager = Relationship(back_populates="managed_team") heroes: List["Hero"] = Relationship(back_populates="team") class Hero(SQLModel, table=True): id: Optional[int] =
Field(primary_key=True, default=None)
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] = Field(default=None) manager_id: int = Field(nullable=False, foreign_key="manager.id") manager: Manager = Relationship(back_populates="managed_team") heroes: List["Hero"] = Relationship(back_populates="team") class Hero(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str =
Field(index=True)
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] = Field(default=None) manager_id: int = Field(nullable=False, foreign_key="manager.id") manager: Manager = Relationship(back_populates="managed_team") heroes: List["Hero"] = Relationship(back_populates="team") class Hero(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) secret_name: str age: Optional[int] =
Field(default=None, index=True)
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] = Field(default=None) manager_id: int = Field(nullable=False, foreign_key="manager.id") manager: Manager = Relationship(back_populates="managed_team") heroes: List["Hero"] = Relationship(back_populates="team") class Hero(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) secret_name: str age: Optional[int] = Field(default=None, index=True) team_id: Optional[int] =
Field(default=None, foreign_key="team.id")
sqlmodel.Field
import textwrap from typing import List, Optional import pytest from sqlmodel import Field, Relationship, SQLModel import strawberry class City(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() population: int = Field() class Manager(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field() managed_team: "Team" = Relationship(back_populates="manager") class Team(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) headquarters: Optional[str] = Field(default=None) manager_id: int = Field(nullable=False, foreign_key="manager.id") manager: Manager = Relationship(back_populates="managed_team") heroes: List["Hero"] = Relationship(back_populates="team") class Hero(SQLModel, table=True): id: Optional[int] = Field(primary_key=True, default=None) name: str = Field(index=True) secret_name: str age: Optional[int] = Field(default=None, index=True) team_id: Optional[int] = Field(default=None, foreign_key="team.id") team: Optional[Team] =
Relationship(back_populates="heroes")
sqlmodel.Relationship
"""Initial Revision ID: d63ccd5484d7 Revises: Create Date: 2021-11-14 00:28:55.123695 """ from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = '<KEY>' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('facilities', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name',
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial Revision ID: d63ccd5484d7 Revises: Create Date: 2021-11-14 00:28:55.123695 """ from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = '<KEY>' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('facilities', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('category',
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial Revision ID: d63ccd5484d7 Revises: Create Date: 2021-11-14 00:28:55.123695 """ from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = '<KEY>' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('facilities', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('category', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('notes',
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial Revision ID: d63ccd5484d7 Revises: Create Date: 2021-11-14 00:28:55.123695 """ from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = '<KEY>' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('facilities', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('category', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_facilities_category'), 'facilities', ['category'], unique=False) op.create_index(op.f('ix_facilities_created_at'), 'facilities', ['created_at'], unique=False) op.create_index(op.f('ix_facilities_id'), 'facilities', ['id'], unique=False) op.create_index(op.f('ix_facilities_name'), 'facilities', ['name'], unique=False) op.create_index(op.f('ix_facilities_notes'), 'facilities', ['notes'], unique=False) op.create_index(op.f('ix_facilities_updated_at'), 'facilities', ['updated_at'], unique=False) op.create_table('increment', sa.Column('id', sa.Integer(), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_increment_id'), 'increment', ['id'], unique=False) op.create_table('listings', sa.Column('id', sa.Integer(), nullable=False), sa.Column('is_active', sa.Boolean(), nullable=False), sa.Column('title',
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial Revision ID: d63ccd5484d7 Revises: Create Date: 2021-11-14 00:28:55.123695 """ from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = '<KEY>' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('facilities', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('category', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_facilities_category'), 'facilities', ['category'], unique=False) op.create_index(op.f('ix_facilities_created_at'), 'facilities', ['created_at'], unique=False) op.create_index(op.f('ix_facilities_id'), 'facilities', ['id'], unique=False) op.create_index(op.f('ix_facilities_name'), 'facilities', ['name'], unique=False) op.create_index(op.f('ix_facilities_notes'), 'facilities', ['notes'], unique=False) op.create_index(op.f('ix_facilities_updated_at'), 'facilities', ['updated_at'], unique=False) op.create_table('increment', sa.Column('id', sa.Integer(), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_increment_id'), 'increment', ['id'], unique=False) op.create_table('listings', sa.Column('id', sa.Integer(), nullable=False), sa.Column('is_active', sa.Boolean(), nullable=False), sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('description',
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial Revision ID: d63ccd5484d7 Revises: Create Date: 2021-11-14 00:28:55.123695 """ from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = '<KEY>' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('facilities', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('category', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_facilities_category'), 'facilities', ['category'], unique=False) op.create_index(op.f('ix_facilities_created_at'), 'facilities', ['created_at'], unique=False) op.create_index(op.f('ix_facilities_id'), 'facilities', ['id'], unique=False) op.create_index(op.f('ix_facilities_name'), 'facilities', ['name'], unique=False) op.create_index(op.f('ix_facilities_notes'), 'facilities', ['notes'], unique=False) op.create_index(op.f('ix_facilities_updated_at'), 'facilities', ['updated_at'], unique=False) op.create_table('increment', sa.Column('id', sa.Integer(), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_increment_id'), 'increment', ['id'], unique=False) op.create_table('listings', sa.Column('id', sa.Integer(), nullable=False), sa.Column('is_active', sa.Boolean(), nullable=False), sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('url',
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial Revision ID: d63ccd5484d7 Revises: Create Date: 2021-11-14 00:28:55.123695 """ from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = '<KEY>' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('facilities', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('category', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_facilities_category'), 'facilities', ['category'], unique=False) op.create_index(op.f('ix_facilities_created_at'), 'facilities', ['created_at'], unique=False) op.create_index(op.f('ix_facilities_id'), 'facilities', ['id'], unique=False) op.create_index(op.f('ix_facilities_name'), 'facilities', ['name'], unique=False) op.create_index(op.f('ix_facilities_notes'), 'facilities', ['notes'], unique=False) op.create_index(op.f('ix_facilities_updated_at'), 'facilities', ['updated_at'], unique=False) op.create_table('increment', sa.Column('id', sa.Integer(), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_increment_id'), 'increment', ['id'], unique=False) op.create_table('listings', sa.Column('id', sa.Integer(), nullable=False), sa.Column('is_active', sa.Boolean(), nullable=False), sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('url', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('source',
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString
"""Initial Revision ID: d63ccd5484d7 Revises: Create Date: 2021-11-14 00:28:55.123695 """ from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = '<KEY>' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('facilities', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('category', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_facilities_category'), 'facilities', ['category'], unique=False) op.create_index(op.f('ix_facilities_created_at'), 'facilities', ['created_at'], unique=False) op.create_index(op.f('ix_facilities_id'), 'facilities', ['id'], unique=False) op.create_index(op.f('ix_facilities_name'), 'facilities', ['name'], unique=False) op.create_index(op.f('ix_facilities_notes'), 'facilities', ['notes'], unique=False) op.create_index(op.f('ix_facilities_updated_at'), 'facilities', ['updated_at'], unique=False) op.create_table('increment', sa.Column('id', sa.Integer(), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_increment_id'), 'increment', ['id'], unique=False) op.create_table('listings', sa.Column('id', sa.Integer(), nullable=False), sa.Column('is_active', sa.Boolean(), nullable=False), sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column('url', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('source', sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column('source_id',
sqlmodel.sql.sqltypes.AutoString()
sqlmodel.sql.sqltypes.AutoString