1"""Type guards for database backend narrowing. 2 3These type guards allow type checkers to narrow BaseDatabaseWrapper types to 4vendor-specific implementations based on runtime checks. 5""" 6 7from__future__importannotations 8 9fromtypingimportTYPE_CHECKING,TypeIs1011ifTYPE_CHECKING:12fromplain.models.backends.base.baseimportBaseDatabaseWrapper13fromplain.models.backends.mysql.baseimportMySQLDatabaseWrapper14fromplain.models.backends.postgresql.baseimportPostgreSQLDatabaseWrapper15fromplain.models.backends.sqlite3.baseimportSQLiteDatabaseWrapper161718defis_sqlite_connection(19connection:BaseDatabaseWrapper,20)->TypeIs[SQLiteDatabaseWrapper]:21"""Type guard to narrow BaseDatabaseWrapper to SQLiteDatabaseWrapper.2223 Args:24 connection: A database connection instance.2526 Returns:27 True if the connection is a SQLite connection.2829 Example:30 >>> if is_sqlite_connection(connection):31 >>> # connection is now SQLiteDatabaseWrapper32 >>> connection.ops.jsonfield_datatype_values33 """34returnconnection.vendor=="sqlite"353637defis_mysql_connection(38connection:BaseDatabaseWrapper,39)->TypeIs[MySQLDatabaseWrapper]:40"""Type guard to narrow BaseDatabaseWrapper to MySQLDatabaseWrapper.4142 Args:43 connection: A database connection instance.4445 Returns:46 True if the connection is a MySQL/MariaDB connection.47 """48returnconnection.vendor=="mysql"495051defis_postgresql_connection(52connection:BaseDatabaseWrapper,53)->TypeIs[PostgreSQLDatabaseWrapper]:54"""Type guard to narrow BaseDatabaseWrapper to PostgreSQLDatabaseWrapper.5556 Args:57 connection: A database connection instance.5859 Returns:60 True if the connection is a PostgreSQL connection.61 """62returnconnection.vendor=="postgresql"