From ae2369fd8d423464d0c82c49569280cf08288a27 Mon Sep 17 00:00:00 2001 From: chen Date: Tue, 17 May 2016 15:53:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9Esmartsql=5Futil=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=8F=8A=E9=80=9A=E7=94=A8=E6=97=B6=E9=97=B4=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartsql_util.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 smartsql_util.py diff --git a/smartsql_util.py b/smartsql_util.py new file mode 100644 index 0000000..3d9af65 --- /dev/null +++ b/smartsql_util.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Author: jack +# + +from smartsql import Condition, Field + + +def common_datetime_wheres(f_datetime, start_time=None, end_time=None): + + if not isinstance(f_datetime, Field): + raise TypeError("f_datetime must be a Field instance") + + wheres = Condition('TRUE') + + if start_time is not None: + wheres &= (f_datetime >= start_time) + + if end_time is not None: + wheres &= (f_datetime < end_time) + + return wheres