Extension Point : IDatabaseConnector
Interface | IDatabaseConnector | Since | 0.10 |
Module | trac.db | Source | api.py |
The IDatabaseConnector allows supporting different 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 TracDev/ComponentArchitecture and of course 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 database connection string selects the appropriate implementation to be used.
Primarily, the implementation then provides 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
Additional Information and References
- epydoc
- API Reference
- DatabaseBackend
- Tickets relating to:
- sql
- database
- db
- 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:
- alternative ideas
- with Django: #6339
- with SqlAlchemy: old plan, retired branch