Skip to content

Instantly share code, notes, and snippets.

@fastjack
Created September 29, 2022 10:57
Show Gist options
  • Save fastjack/8b8d4c3dbbd11a45770c890fb4d951e3 to your computer and use it in GitHub Desktop.
Save fastjack/8b8d4c3dbbd11a45770c890fb4d951e3 to your computer and use it in GitHub Desktop.
"""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