Skip to content

Database

Driver

Bases: str, Enum

Enum representing database drivers.

Attributes:

Name Type Description
MYSQL str

MySQL driver.

POSTGRES str

PostgreSQL driver.

SQLITE str

SQLite driver.

MARIADB str

MariaDB driver.

CUSTOM str

Custom driver.

DatabaseAdapter

Dialect

Bases: Protocol

Protocol representing a database dialect.

Attributes:

Name Type Description
default_port int

The default port for the database dialect.

driver Driver

The driver associated with the dialect.

dialect_name str

The name of the database dialect.

async_driver str

The asynchronous driver name.

sync_driver str

The synchronous driver name.

only_host bool

Indicates if the dialect supports only host connections.

DialectInfo

Represents information about a database dialect.

Attributes:

Name Type Description
default_port int

The default port for the database dialect.

driver Driver

The driver associated with the dialect.

dialect_name str

The name of the database dialect.

async_driver str

The asynchronous driver name.

sync_driver str

The synchronous driver name.

only_host bool

Indicates if the dialect supports only host connections.

resolve_driver(driver)

Resolve a driver to its associated DialectInfo.

Parameters:

Name Type Description Default
driver Driver

The database driver.

required

Returns:

Name Type Description
Dialect Dialect

The DialectInfo associated with the provided driver.

Source code in gyver/database/drivers/utils.py
def resolve_driver(driver: Driver) -> Dialect:
    """Resolve a driver to its associated DialectInfo.

    Args:
        driver (Driver): The database driver.

    Returns:
        Dialect: The DialectInfo associated with the provided driver.
    """
    _table: dict[Driver, Dialect] = {
        Driver.MYSQL: DialectInfo(
            default_port=3306,
            driver=Driver.MYSQL,
            dialect_name="mysql",
            async_driver="aiomysql",
            sync_driver="pymysql",
            only_host=False,
        ),
        Driver.POSTGRES: DialectInfo(
            default_port=5432,
            driver=Driver.POSTGRES,
            dialect_name="postgresql",
            async_driver="asyncpg",
            sync_driver="psycopg2",
            only_host=False,
        ),
        Driver.SQLITE: DialectInfo(
            default_port=0,
            driver=Driver.SQLITE,
            dialect_name="sqlite",
            async_driver="aiosqlite",
            sync_driver="",
            only_host=True,
        ),
        Driver.MARIADB: DialectInfo(
            default_port=3306,
            driver=Driver.MARIADB,
            dialect_name="mariadb",
            async_driver="aiomysql",
            sync_driver="pymysql",
            only_host=False,
        ),
    }
    return _table[driver]