rudimentary class for database interactions (download db from switchdrive: https://drive.switch.ch/index.php/apps/files/?dir=/Consultancy&fileid=7499599646#).
parent
7b979997ad
commit
094f51b3b4
|
@ -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
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
from data import database
|
||||
|
||||
|
||||
def load():
|
||||
return database.Database()
|
|
@ -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()
|
|
@ -0,0 +1,5 @@
|
|||
import data
|
||||
|
||||
inst = data.load()
|
||||
inst.seeds()
|
||||
inst.properties_growth()
|
Loading…
Reference in New Issue