initial api
This commit is contained in:
1 parent
899d78fba5
commit
e87c41f496
16 files changed
+458
-2
No files matched your search
@@ -0,0 +1,22 @@
|
||||
from sqlalchemy import create_engine, text
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
class HassDatabase:
|
||||
def __init__(self, db_url: str) -> None:
|
||||
self.url = urlparse(db_url)
|
||||
self.entities = None
|
||||
try:
|
||||
self.engine = create_engine(db_url)
|
||||
except Exception as exc:
|
||||
if isinstance(exc, ImportError):
|
||||
raise RuntimeError(
|
||||
"The right dependency to connect to your database is "
|
||||
"missing. Please make sure that it is installed."
|
||||
) from exc
|
||||
|
||||
raise
|
||||
|
||||
@property
|
||||
def db_type(self):
|
||||
return self.url.scheme.split("+")[0]
|
||||
Reference in new issue
Block a user