當前位置: 首頁>>代碼示例>>Python>>正文


Python sqltypes.DateTime方法代碼示例

本文整理匯總了Python中sqlalchemy.sql.sqltypes.DateTime方法的典型用法代碼示例。如果您正苦於以下問題:Python sqltypes.DateTime方法的具體用法?Python sqltypes.DateTime怎麽用?Python sqltypes.DateTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.sql.sqltypes的用法示例。


在下文中一共展示了sqltypes.DateTime方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_notna_dtype

# 需要導入模塊: from sqlalchemy.sql import sqltypes [as 別名]
# 或者: from sqlalchemy.sql.sqltypes import DateTime [as 別名]
def test_notna_dtype(self):
        cols = {'Bool': Series([True, None]),
                'Date': Series([datetime(2012, 5, 1), None]),
                'Int': Series([1, None], dtype='object'),
                'Float': Series([1.1, None])
                }
        df = DataFrame(cols)

        tbl = 'notna_dtype_test'
        df.to_sql(tbl, self.conn)
        returned_df = sql.read_sql_table(tbl, self.conn)  # noqa
        meta = sqlalchemy.schema.MetaData(bind=self.conn)
        meta.reflect()
        if self.flavor == 'mysql':
            my_type = sqltypes.Integer
        else:
            my_type = sqltypes.Boolean

        col_dict = meta.tables[tbl].columns

        assert isinstance(col_dict['Bool'].type, my_type)
        assert isinstance(col_dict['Date'].type, sqltypes.DateTime)
        assert isinstance(col_dict['Int'].type, sqltypes.Integer)
        assert isinstance(col_dict['Float'].type, sqltypes.Float) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:test_sql.py

示例2: test_datatype

# 需要導入模塊: from sqlalchemy.sql import sqltypes [as 別名]
# 或者: from sqlalchemy.sql.sqltypes import DateTime [as 別名]
def test_datatype(self, table, column):
        """Tests that database column datatype matches the one defined in the
        models.
        """
        database_column = self.find_database_column(table, column)

        if isinstance(column.type, sqltypes.String):
            expected_type = sqltypes.VARCHAR
        elif isinstance(column.type, sqltypes.Integer):
            expected_type = sqltypes.INTEGER
        elif isinstance(column.type, sqltypes.Boolean):
            expected_type = sqltypes.BOOLEAN
        elif isinstance(column.type, sqltypes.DateTime):
            expected_type = sqltypes.DATETIME

        if not isinstance(database_column['type'], expected_type):
            self.errors.append(
                DatatypeMismatch(table, database_column, expected_type,
                                 parent=self)
            ) 
開發者ID:Hamuko,項目名稱:cum,代碼行數:22,代碼來源:sanity.py

示例3: test_sqlalchemy_type_mapping

# 需要導入模塊: from sqlalchemy.sql import sqltypes [as 別名]
# 或者: from sqlalchemy.sql.sqltypes import DateTime [as 別名]
def test_sqlalchemy_type_mapping(self):

        # Test Timestamp objects (no datetime64 because of timezone) (GH9085)
        df = DataFrame({'time': to_datetime(['201412120154', '201412110254'],
                                            utc=True)})
        db = sql.SQLDatabase(self.conn)
        table = sql.SQLTable("test_type", db, frame=df)
        assert isinstance(table.table.c['time'].type, sqltypes.DateTime) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:10,代碼來源:test_sql.py

示例4: parse_operator

# 需要導入模塊: from sqlalchemy.sql import sqltypes [as 別名]
# 或者: from sqlalchemy.sql.sqltypes import DateTime [as 別名]
def parse_operator(cls, filter_name_dict):
    """ 用來返回sqlalchemy query對象filter使用的表達式
    Args:
        filter_name_dict (dict): 過濾條件dict
        {
            'last_name': {'eq': 'wang'},    # 如果是dic使用key作為操作符
            'age': {'>': 12}
        }
    Returns:
        binary_expression_list (lambda list)
    """

    def _change_type(cls, field, value):
        """ 有些表字段比如DateTime類型比較的時候需要轉換類型,
        前端傳過來的都是字符串,Date等類型沒法直接相比較,需要轉成Date類型
        Args:
            cls (class): Model class
            field (str): Model class field
            value (str): value need to compare
        """
        field_type = getattr(cls, field).type
        if isinstance(field_type, Date):
            return date_str_to_obj(value)
        elif isinstance(field_type, DateTime):
            return datetime_str_to_obj(value)
        else:
            return value

    binary_expression_list = []
    for field, op_dict in list(filter_name_dict.items()):
        for op, op_val in list(op_dict.items()):
            op_val = _change_type(cls, field, op_val)
            if op in OPERATOR_FUNC_DICT:
                binary_expression_list.append(
                        OPERATOR_FUNC_DICT[op](cls, field, op_val)
                )
    return binary_expression_list 
開發者ID:meolu,項目名稱:walle-web,代碼行數:39,代碼來源:database.py


注:本文中的sqlalchemy.sql.sqltypes.DateTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。