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.

Home Page:https://thp.io/2010/minidb/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to work with date type?

benvindo opened this issue · comments

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

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