mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-20 11:48:31 -06:00
server connection. The BaseDriver and BaseConnection are two abstract classes, which allows us to replace the existing driver with the currently used. The current implementation supports to connect the PostgreSQL and Postgres Plus Advanced Server using the psycopg2 driver.
34 lines
745 B
Python
34 lines
745 B
Python
from flask import current_app
|
|
from .registry import DriverRegistry
|
|
|
|
|
|
def get_driver(type):
|
|
drivers = getattr(current_app, '_pgadmin_server_drivers', None)
|
|
|
|
if drivers is None or not isinstance(drivers, dict):
|
|
drivers = dict()
|
|
|
|
if type in drivers:
|
|
return drivers[type]
|
|
|
|
driver = DriverRegistry.create(type)
|
|
|
|
if driver is not None:
|
|
drivers[type] = driver
|
|
setattr(current_app, '_pgadmin_server_drivers', drivers)
|
|
|
|
return driver
|
|
|
|
def init_app(app):
|
|
drivers = dict()
|
|
|
|
setattr(app, '_pgadmin_server_drivers', drivers)
|
|
DriverRegistry.load_drivers()
|
|
|
|
|
|
def ping():
|
|
drivers = getattr(current_app, '_pgadmin_server_drivers', None)
|
|
|
|
for type in drivers:
|
|
drivers[type].gc()
|