Skip to content

Commit 054d380

Browse files
committed
Property Date/DateNano: added py_type arg for underlying python type / updated examples/tests #29
1 parent dfbf011 commit 054d380

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

example/tasks/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class Task:
66
id = Id(id=1, uid=1001)
77
text = String(id=2, uid=1002)
88

9-
date_created = Date(id=3, uid=1003)
10-
date_finished = Date(id=4, uid=1004)
9+
date_created = Date(py_type=int, id=3, uid=1003)
10+
date_finished = Date(py_type=int, id=4, uid=1004)
1111

1212

1313
def get_objectbox_model():

objectbox/model/properties.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ def __init__(self, id : int = 0, uid : int = 0, **kwargs):
302302

303303
# Date Properties
304304
class Date(_NumericProperty):
305-
def __init__(self, id : int = 0, uid : int = 0, **kwargs):
306-
super(Date, self).__init__(int, type=PropertyType.date, id=id, uid=uid, **kwargs)
305+
def __init__(self, py_type = datetime, id : int = 0, uid : int = 0, **kwargs):
306+
super(Date, self).__init__(py_type, type=PropertyType.date, id=id, uid=uid, **kwargs)
307307

308308
class DateNano(_NumericProperty):
309-
def __init__(self, id : int = 0, uid : int = 0, **kwargs):
310-
super(DateNano, self).__init__(int, type=PropertyType.dateNano, id=id, uid=uid, **kwargs)
309+
def __init__(self, py_type = datetime, id : int = 0, uid : int = 0, **kwargs):
310+
super(DateNano, self).__init__(py_type, type=PropertyType.dateNano, id=id, uid=uid, **kwargs)
311311

312312
# Flex Property
313313
class Flex(Property):

tests/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ class TestEntity:
3131
longs_list = Int64List(id=22, uid=1022)
3232
floats_list = Float32List(id=23, uid=1023)
3333
doubles_list = Float64List(id=24, uid=1024)
34-
date = Date(id=25, uid=1025)
35-
date_nano = DateNano(id=26, uid=1026)
34+
date = Date(py_type=int, id=25, uid=1025)
35+
date_nano = DateNano(py_type=int, id=26, uid=1026)
3636
flex = Flex(id=27, uid=1027)
3737
transient = "" # not "Property" so it's not stored
3838

3939

4040
@Entity(id=2, uid=2)
4141
class TestEntityDatetime:
4242
id = Id(id=1, uid=2001)
43-
date = Property(datetime, type=PropertyType.date, id=2, uid=2002)
44-
date_nano = Property(datetime, type=PropertyType.dateNano, id=3, uid=2003)
43+
date = Date(id=2, uid=2002)
44+
date_nano = DateNano(id=3, uid=2003)
4545

4646

4747
@Entity(id=3, uid=3)

0 commit comments

Comments
 (0)