Created
September 29, 2022 10:57
-
-
Save fastjack/8b8d4c3dbbd11a45770c890fb4d951e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""This is a driver for storing metrics into specific databases""" | |
class DriverBase: | |
"""Abstract database driver""" | |
_registry = {} | |
_driver_options = {} | |
drivername = None | |
@classmethod | |
def __init_subclass__(cls): | |
DriverBase._registry[cls.drivername] = cls | |
def __init__(self, driver_options): | |
"""Initialize the driver""" | |
self._driver_options = driver_options | |
@property | |
def driver_options(self): | |
"""Return the driver options""" | |
return self._driver_options | |
def create_db_driver(drivername, driver_options): | |
"""Create a new database driver""" | |
return DriverBase._registry[drivername](driver_options) | |
class InfluxDbDriver(DriverBase): | |
"""Driver for InfluxDB 1.x""" | |
drivername = 'influxdb' | |
class InfluxDb2Driver(DriverBase): | |
"""Driver for InfluxDB 2.x""" | |
drivername = "influxdb2" | |
class MysqlDriver(DriverBase): | |
"""Driver for MySQL""" | |
drivername = "mysql" | |
class PostgresqlDriver(DriverBase): | |
"""Driver for PostgreSQL""" | |
drivername = "postgres" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment