Skip to content

Database

Turbulette doesn't add much on top of GINO, what is does is basically set up the Gino instance at startup and extend the base Model class to automatically generate __tablename__ attribute. The rest is pure GINO.

Model

Base model for GINO models.

It's close to the base GINO Model class, the main difference is that __tablename__ class attribute (the table name) is automatically generated based on the Turbulette app name and the model name, in camel case format.

If the following model leaves in a Turbulette app named vehicle :

Example

from turbulette.db import Model

class SuperCar(Model):
    pass

Then the resulting generated __tablename__ attribute will be vehicle_super_car

Integrates GINO by subclassing the base model class.

get_tablename(package, name)

Generate a camel case table name.

Parameters:

Name Type Description Default
package str

Model's package

required
name str

Model name (usually the class name)

required

Returns:

Type Description
str

The table name

Source code in turbulette/db/database.py
def get_tablename(package: str, name: str) -> str:
    """Generate a camel case table name.

    Args:
        package (str): Model's package
        name (str): Model name (usually the class name)

    Returns:
        The table name
    """
    return (
        f"{registry.get_app_by_package(package).label}"
        f"_{convert_camel_case_to_snake(name)}"
    )

Last update: 2021-02-18