rudimentary class for database interactions (download db from switchdrive: https://drive.switch.ch/index.php/apps/files/?dir=/Consultancy&fileid=7499599646#).

refactor-to-mono
Giò Diani 2024-10-26 17:21:52 +02:00
parent 7b979997ad
commit 094f51b3b4
4 changed files with 51 additions and 0 deletions

26
.gitignore vendored
View File

@ -37,6 +37,32 @@ nbdist/
nbactions.xml nbactions.xml
nb-configuration.xml nb-configuration.xml
# Sublime
*.sublime-*
# OS # OS
.DS_Store .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

5
src/data/__init__.py Normal file
View File

@ -0,0 +1,5 @@
from data import database
def load():
return database.Database()

15
src/data/database.py Normal file
View File

@ -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()

5
src/gio/test_duckdb.py Normal file
View File

@ -0,0 +1,5 @@
import data
inst = data.load()
inst.seeds()
inst.properties_growth()