Libraries to connect to

Sqlite is supported by the python standard library.

For AnyDB and AsyncAnyDB, the connection library is set by the end user and he is responsible for installing it.

External libraries are used for Mysql, AsyncMysql, and AsyncSqlite. The default libraries (PyMySQL, aiomysql, and aiosqlite) are installed in the db_full and adb_full groups

Replacing libraries

To replace the library (one item to choose from):

  • change the _library field of the class

    from pydantic_extra.db import MySQL
    
    MySQL._library = "other_library"
    
  • change the library instance field

    from pydantic_extra.db import MySQL
    
    db = MySQL.model_validate(...)
    db.library = "other_library"
    
  • create a subclass by specifying the default_library parameter

    from pydantic_extra.db import AnyDB, Mysql as _Mysql, SQLite
    
    
    class Mysql(_Mysql, default_library="other_library"):
        pass
    
    
    T_DB = SQLite | Mysql | AnyDB