Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
IanRFerguson committed Mar 23, 2024
1 parent f7afbe9 commit 329908e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
21 changes: 17 additions & 4 deletions klondike/base/generic_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@

import petl
from polars import DataFrame
from contextlib import contextmanager

##########


class PolarBareDB:
class KlondikeDB:
"""
Abstract class with shared utilities across all database instances
"""

def __init__(self):
def __init__(self, **kwargs):
vars(self).update(kwargs=kwargs)

self.dialect = None
self.__tempfiles = []

@contextmanager
def connection(self):
"""Placeholder function"""
return

def query(
self, sql: str, parameters: Optional[list] = None, batch_size: int = 250_000
self,
sql: str,
parameters: Optional[list] = None,
batch_size: int = 250_000,
return_values: bool = True,
) -> Optional[DataFrame]:
"""
Leverages internal connection to query against Postgres instance
Expand All @@ -36,7 +49,7 @@ def query(
cursor.execute(query=sql, params=parameters)

# If no results, return without raising exeption
if not cursor.description:
if not cursor.description or not return_values:
return None

###
Expand Down
4 changes: 2 additions & 2 deletions klondike/bigquery/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from google.cloud import bigquery
from google.cloud.bigquery import dbapi

from klondike.base.generic_db import PolarBareDB
from klondike.base.generic_db import KlondikeDB
import json
import os
import tempfile
Expand All @@ -20,7 +20,7 @@
)


class PolarBigQuery(PolarBareDB):
class PolarBigQuery(KlondikeDB):
"""
Establish and authenticate a connection to a BigQuery warehouse
"""
Expand Down
4 changes: 2 additions & 2 deletions klondike/postgres/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import psycopg

from klondike.base.generic_db import PolarBareDB
from klondike.base.generic_db import KlondikeDB

##########


class PolarPostgres(PolarBareDB):
class PolarPostgres(KlondikeDB):
"""
Establish and authenticate a connection to a Postgres instance.
Expand Down

0 comments on commit 329908e

Please sign in to comment.