File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
tests/apps/migrations/auto/integration Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 2828from piccolo .columns .combination import Where
2929from piccolo .columns .choices import Choice
3030from piccolo .columns .defaults .base import Default
31+ from piccolo .columns .defaults .interval import IntervalCustom
3132from piccolo .columns .reference import LazyTableReference
3233from piccolo .columns .indexes import IndexMethod
3334from piccolo .querystring import QueryString
@@ -545,6 +546,9 @@ def get_sql_value(self, value: t.Any) -> t.Any:
545546 output = f"'{ value .isoformat ()} '"
546547 elif isinstance (value , datetime .time ):
547548 output = f"'{ value .isoformat ()} '"
549+ elif isinstance (value , datetime .timedelta ):
550+ interval = IntervalCustom .from_timedelta (value )
551+ output = getattr (interval , self ._meta .engine_type )
548552 elif isinstance (value , bytes ):
549553 output = f"'{ value .hex ()} '"
550554 elif isinstance (value , uuid .UUID ):
Original file line number Diff line number Diff line change 1414 BigInt ,
1515 Date ,
1616 Integer ,
17+ Interval ,
1718 SmallInt ,
1819 Text ,
1920 Time ,
@@ -59,6 +60,10 @@ def date_default():
5960 return datetime .datetime .now ().date ()
6061
6162
63+ def timedelta_default ():
64+ return datetime .timedelta (days = 1 )
65+
66+
6267@postgres_only
6368class TestMigrations (TestCase ):
6469 def tearDown (self ):
@@ -267,3 +272,19 @@ def test_date_column(self):
267272 ]
268273 ]
269274 )
275+
276+ def test_interval_column (self ):
277+ self ._test_migrations (
278+ table_classes = [
279+ self .table (column )
280+ for column in [
281+ Interval (),
282+ Interval (default = datetime .timedelta (days = 1 )),
283+ Interval (default = timedelta_default ),
284+ Interval (null = True , default = None ),
285+ Interval (null = False ),
286+ Interval (index = True ),
287+ Interval (index = False ),
288+ ]
289+ ]
290+ )
You can’t perform that action at this time.
0 commit comments