diff --git a/.gitignore b/.gitignore index 0485192..e7714e2 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,32 @@ nbdist/ nbactions.xml nb-configuration.xml +# Sublime +*.sublime-* + # OS .DS_Store +# Python +.Python +.python-version +__pycache__/ +.pytest_cache +*.py[cod] +.env/ +.env* +.~env/ +.venv +env3.6/ +venv/ +env3.*/ +.dev +.denv +.pypyenv +.pytest_cache/ +.mypy_cache/ +.hypothesis/ + +# duckdb +*.duckdb + diff --git a/src/data/__init__.py b/src/data/__init__.py new file mode 100644 index 0000000..9368496 --- /dev/null +++ b/src/data/__init__.py @@ -0,0 +1,5 @@ +from data import database + + +def load(): + return database.Database() \ No newline at end of file diff --git a/src/data/database.py b/src/data/database.py new file mode 100644 index 0000000..5b9c82f --- /dev/null +++ b/src/data/database.py @@ -0,0 +1,15 @@ +import duckdb + + +class Database: + def __init__(self): + self.connection = duckdb.connect(database = '../data/consultancy.duckdb', read_only = True) + + def db_overview(self): + return self.connection.sql("DESCRIBE;").show() + + def seeds(self): + return self.connection.sql("SELECT regions.name, seeds.uri FROM consultancy_d.regions LEFT JOIN consultancy_d.seeds ON regions.id = seeds.region_id;").show() + + def properties_growth(self): + return self.connection.sql("SELECT strftime(created_at, '%Y-%m-%d') AS date, COUNT(*) as properties_count FROM consultancy_d.properties GROUP BY date;").show() \ No newline at end of file diff --git a/src/gio/test_duckdb.py b/src/gio/test_duckdb.py new file mode 100644 index 0000000..aac68b5 --- /dev/null +++ b/src/gio/test_duckdb.py @@ -0,0 +1,5 @@ +import data + +inst = data.load() +inst.seeds() +inst.properties_growth()