Database
lightapi.database
Attributes
SQLALCHEMY_DATABASE_URL
module-attribute
SessionLocal
module-attribute
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Classes
Base
Custom SQLAlchemy base class that provides automatic __tablename__
generation
and a method to convert model instances to dictionaries.
Attributes:
Name | Type | Description |
---|---|---|
id |
Column
|
Primary key column automatically added to all derived models. |
Methods:
Name | Description |
---|---|
__tablename__ |
Automatically generates the table name from the class name, converted to lowercase. |
as_dict |
Converts the model instance into a dictionary where keys are the column names and values are the corresponding data. |
Source code in lightapi/database.py
Attributes
pk
class-attribute
instance-attribute
Functions
__tablename__
Generates the table name based on the class name.
The table name is derived by converting the class name to lowercase.
Returns:
Name | Type | Description |
---|---|---|
str |
The generated table name. |
Source code in lightapi/database.py
serialize
Converts the model instance into a dictionary representation.
Each key in the dictionary corresponds to a column name, and the value is the data stored in that column.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary representation of the model instance. |