Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add db type as attribute #52

Closed
robmarkcole opened this issue Dec 16, 2018 · 3 comments
Closed

Add db type as attribute #52

robmarkcole opened this issue Dec 16, 2018 · 3 comments
Assignees

Comments

@robmarkcole
Copy link
Owner

As pointed out by @balloob 'Most DBAPIs have built in support for the datetime module, with the noted exception of SQLite. In the case of SQLite, date and time types are stored as strings which are then converted back to datetime objects when rows are returned.' Detective should have the db type as an attribute, allowing for db type specific behaviour if required.

@balloob
Copy link
Collaborator

balloob commented Dec 17, 2018

The problem is that SQLAlchemy only sees the DB schema stored in the DB. In Home Assistant we have SQLAlchemy objects describing the data, and we can tell it to see a column as datetime. SQLLite has no datetime type, so returns that column as a string because SQLAlchemy doesn't know any better.

@robmarkcole
Copy link
Owner Author

I think the best approach is just to detect if a string has been returened where a datetime is expected, then parse appropriately. I think SQLAlchemy & ORM is overkill for the timebeing, and we have the HA rest API for complex interactions with entities

@balloob
Copy link
Collaborator

balloob commented Dec 17, 2018

I agree with it being overkill, it will add too much overhead.

Where would you want to do the detection ? We can extract the type from the DB url.

from urllib.parse import urlparse
type = urlparse(db_url).scheme

@robmarkcole robmarkcole self-assigned this Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants