Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for timescaledb #16

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions agnostic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ def askpass(user, db):
raise
return PostgresBackend(host, port, user, password, database, schema)

elif db_type == 'timescale':
if user is None or database is None:
raise RuntimeError('TimescaleDB requires user and database '
'arguments.')
host = host or 'localhost'
password = password or askpass(user, database)
try:
from agnostic.timescale import TimescaleBackend
except ImportError as ie: # pragma: no cover
if ie.name == 'pg8000':
raise RuntimeError('The `pg8000` module is required for '
' TimescaleDB.')
else:
raise
return TimescaleBackend(host, port, user, password, database, schema)

elif db_type == 'sqlite':
if (host is not None or port is not None or user is not None or
password is not None or schema is not None):
Expand Down
2 changes: 1 addition & 1 deletion agnostic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
envvar='AGNOSTIC_TYPE',
metavar='<type>',
required=True,
type=click.Choice(['mysql', 'postgres', 'sqlite']),
type=click.Choice(['mysql', 'postgres', 'sqlite', 'timescale']),
help='Type of database.'
)
@click.option(
Expand Down
20 changes: 20 additions & 0 deletions agnostic/timescale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import subprocess

import pg8000

from agnostic.postgres import PostgresBackend


class TimescaleBackend(PostgresBackend):

def clear_db(self, cursor):

''' Remove timescale extension. '''

# Drop extension
cursor.execute('''
DROP EXTENSION IF EXISTS timescaledb CASCADE;
''')

return super().clear_db(cursor)