thp / minidb

Store Python objects in SQLite 3. Concise, pythonic API. Easy to write, relatively easy to read. A kind of super simple ORM, if you will. Give it a try.
https://thp.io/2010/minidb/
Other
66 stars 15 forks source link

How to work with date type? #7

Closed benvindo closed 6 years ago

benvindo commented 6 years ago

Hi, someone gives me example, how can I use the date type to save and load with minidb?

thp commented 6 years ago

You should be able to use datetime.datetime, datetime.date and datetime.time, as these all have converters already pre-defined.

import datetime

class Something(minidb.Model):
    name = str
    birthday = datetime.date
    favorite_time_of_day = datetime.time
    last_login = datetime.datetime

The definitions are here: https://github.com/thp/minidb/blob/master/minidb.py#L781 https://github.com/thp/minidb/blob/master/minidb.py#L797 https://github.com/thp/minidb/blob/master/minidb.py#L811