== Extension Point : ''IDatabaseConnector'' == ||'''Interface'''||''IDatabaseConnector''||'''Since'''||[wiki:TracDev/ReleaseNotes/0.10#Improvedmodularity 0.10]|| ||'''Module'''||''trac.db''||'''Source'''||[source:trunk/trac/db/api.py api.py]|| The ''IDatabaseConnector'' allows supporting different [DatabaseBackend database backends]. == Purpose == Trac provides generic database abstraction layer, allowing extensible support for different database backends. This allows Trac to be used with either SQLite, MySQL, PostgreSQL or any other database for which a connector is available. == Usage == Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment]. Typically, an implementation checks if any required binding libraries are available when loaded. On failure, an error can be indicated when Trac queries the supported ''schemes''. The schema of the [wiki:TracEnvironment#DatabaseConnectionStrings database connection string] selects the appropriate implementation to be used. Primarily, the implementation then provides [pep:0249 Python DB API 2.0] ''connection'' and ''cursor'' objects for that connection string. Typically a `ConnectionWrapper` is used to wrap the connection object of the specific db library. Implementations also initialize and backup a database, and generate implementation specific DDL and SQL for poorly standardized features (like type casting, string concatenation, pattern matching, accessing the last row id). == Examples == Due to the complexity of implementing a full database backend, no simple example can be provided here. == Available Implementations == * Official Trac connectors * SQLite: [source:trunk/trac/db/sqlite_backend.py trac.db.sqlite_backend.SQLiteConnector] * PostgreSQL: [source:trunk/trac/db/postgres_backend.py trac.db.postgres_backend.PostgreSQLConnector] * MySQL: [source:trunk/trac/db/mysql_backend.py trac.db.mysql_backend.MySQLConnector] == Additional Information and References == * [http://www.edgewall.org/docs/trac-trunk/epydoc/trac.db.api.IDatabaseConnector-class.html epydoc] * [http://www.edgewall.org/docs/trac-trunk/html/api/trac_db.html#trac.db.IDatabaseConnector API Reference] * DatabaseBackend * Tickets relating to: * [query:status=!closed&keywords=~sql sql] * [query:status=!closed&keywords=~database database] * [query:status=!closed&keywords=~db db] * [query:status=!closed&component=database+backend database backend] component * About connectors for other databases * Oracle: #1874, th:ticket:5487 * Ingres: #6235 * Microsoft SQL Server: #329 * Generic ODBC: comment:21:ticket:329, th:ticket:2277 * About replacing the DB abstraction layer: * [DatabaseBackend#AlternativeIdeasforDatabaseIndependence alternative ideas] * with Django: #6339 * with SqlAlchemy: [TracSqlAlchemy old plan], [browser:sandbox/Attic/sqlalchemy-ng retired branch]