Skip to content

Dummy Database

Dummy database for testing and development purposes.

Schema

schema

Attributes

Base = declarative_base() module-attribute

Classes

Owners

Bases: Base

Source code in diracx-db/src/diracx/db/sql/dummy/schema.py
class Owners(Base):
    __tablename__ = "Owners"
    owner_id = Column("OwnerID", Integer, primary_key=True, autoincrement=True)
    creation_time = DateNowColumn("CreationTime")
    name = Column("Name", String(255))
Attributes
owner_id = Column('OwnerID', Integer, primary_key=True, autoincrement=True) class-attribute instance-attribute
creation_time = DateNowColumn('CreationTime') class-attribute instance-attribute
name = Column('Name', String(255)) class-attribute instance-attribute

Cars

Bases: Base

Source code in diracx-db/src/diracx/db/sql/dummy/schema.py
class Cars(Base):
    __tablename__ = "Cars"
    license_plate = Column("LicensePlate", Uuid(), primary_key=True)
    model = Column("Model", String(255))
    owner_id = Column("OwnerID", Integer, ForeignKey(Owners.owner_id))
Attributes
license_plate = Column('LicensePlate', Uuid(), primary_key=True) class-attribute instance-attribute
model = Column('Model', String(255)) class-attribute instance-attribute
owner_id = Column('OwnerID', Integer, ForeignKey(Owners.owner_id)) class-attribute instance-attribute

Database Access

db

Attributes

Classes

DummyDB

Bases: BaseSQLDB

This DummyDB is just to illustrate some important aspect of writing DB classes in DiracX.

It is mostly pure SQLAlchemy, with a few convention

Document the secrets

Source code in diracx-db/src/diracx/db/sql/dummy/db.py
class DummyDB(BaseSQLDB):
    """This DummyDB is just to illustrate some important aspect of writing
    DB classes in DiracX.

    It is mostly pure SQLAlchemy, with a few convention

    Document the secrets
    """

    # This needs to be here for the BaseSQLDB to create the engine
    metadata = DummyDBBase.metadata

    async def summary(self, group_by, search) -> list[dict[str, str | int]]:
        return await self._summary(Cars, group_by, search)

    async def insert_owner(self, name: str) -> int:
        stmt = insert(Owners).values(name=name)
        result = await self.conn.execute(stmt)
        # await self.engine.commit()
        return result.lastrowid

    async def insert_car(self, license_plate: UUID, model: str, owner_id: int) -> int:
        stmt = insert(Cars).values(
            license_plate=license_plate, model=model, owner_id=owner_id
        )

        result = await self.conn.execute(stmt)
        # await self.engine.commit()
        return result.lastrowid
Attributes
metadata = DummyDBBase.metadata class-attribute instance-attribute
Functions
summary(group_by, search) async
Source code in diracx-db/src/diracx/db/sql/dummy/db.py
async def summary(self, group_by, search) -> list[dict[str, str | int]]:
    return await self._summary(Cars, group_by, search)
insert_owner(name) async
Source code in diracx-db/src/diracx/db/sql/dummy/db.py
async def insert_owner(self, name: str) -> int:
    stmt = insert(Owners).values(name=name)
    result = await self.conn.execute(stmt)
    # await self.engine.commit()
    return result.lastrowid
insert_car(license_plate, model, owner_id) async
Source code in diracx-db/src/diracx/db/sql/dummy/db.py
async def insert_car(self, license_plate: UUID, model: str, owner_id: int) -> int:
    stmt = insert(Cars).values(
        license_plate=license_plate, model=model, owner_id=owner_id
    )

    result = await self.conn.execute(stmt)
    # await self.engine.commit()
    return result.lastrowid