当前位置: 首页>>代码示例>>Python>>正文


Python sql.InsertQuery方法代码示例

本文整理汇总了Python中django.db.models.sql.InsertQuery方法的典型用法代码示例。如果您正苦于以下问题:Python sql.InsertQuery方法的具体用法?Python sql.InsertQuery怎么用?Python sql.InsertQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.sql的用法示例。


在下文中一共展示了sql.InsertQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _insert

# 需要导入模块: from django.db.models import sql [as 别名]
# 或者: from django.db.models.sql import InsertQuery [as 别名]
def _insert(self, objs, fields, return_id=False, raw=False, using=None):
        """
        Inserts a new record for the given model. This provides an interface to
        the InsertQuery class and is how Model.save() is implemented.
        """
        self._for_write = True
        if using is None:
            using = self.db
        query = sql.InsertQuery(self.model)
        query.insert_values(fields, objs, raw=raw)
        return query.get_compiler(using=using).execute_sql(return_id) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:query.py

示例2: _insert

# 需要导入模块: from django.db.models import sql [as 别名]
# 或者: from django.db.models.sql import InsertQuery [as 别名]
def _insert(self, objs, fields, return_id=False, raw=False, using=None):
        """
        Insert a new record for the given model. This provides an interface to
        the InsertQuery class and is how Model.save() is implemented.
        """
        self._for_write = True
        if using is None:
            using = self.db
        query = sql.InsertQuery(self.model)
        query.insert_values(fields, objs, raw=raw)
        return query.get_compiler(using=using).execute_sql(return_id) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:query.py

示例3: insert_query

# 需要导入模块: from django.db.models import sql [as 别名]
# 或者: from django.db.models.sql import InsertQuery [as 别名]
def insert_query(model, objs, fields, return_id=False, raw=False, using=None):
    """
    Inserts a new record for the given model. This provides an interface to
    the InsertQuery class and is how Model.save() is implemented. It is not
    part of the public API.
    """
    query = sql.InsertQuery(model)
    query.insert_values(fields, objs, raw=raw)
    return query.get_compiler(using=using).execute_sql(return_id) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:11,代码来源:query.py

示例4: test_insert_uuid_field

# 需要导入模块: from django.db.models import sql [as 别名]
# 或者: from django.db.models.sql import InsertQuery [as 别名]
def test_insert_uuid_field(self):
        import uuid
        from django.db.models import sql
        from testapp.models import TestModel
        obj = TestModel(uuid=uuid.uuid4())
        q = sql.InsertQuery(obj)
        q.insert_values(obj._meta.local_fields, [obj])
        statements = q.get_compiler('default').as_sql()
        # uuid is the last field of TestModel
        uuid_insert_value = statements[0][1][-1]
        # the Python value for insertion must be a string whose length is 32
        self.assertEqual(type(uuid_insert_value), str)
        self.assertEqual(len(uuid_insert_value), 32) 
开发者ID:jazzband,项目名称:django-redshift-backend,代码行数:15,代码来源:test_redshift_backend.py

示例5: test_sql_insert_compiler_return_id_attribute

# 需要导入模块: from django.db.models import sql [as 别名]
# 或者: from django.db.models.sql import InsertQuery [as 别名]
def test_sql_insert_compiler_return_id_attribute(self):
        """
        Regression test for #14019: SQLInsertCompiler.as_sql() failure
        """
        db = router.db_for_write(Party)
        query = InsertQuery(Party)
        query.insert_values([Party._meta.fields[0]], [], raw=False)
        # this line will raise an AttributeError without the accompanying fix
        query.get_compiler(using=db).as_sql() 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:tests.py

示例6: chain

# 需要导入模块: from django.db.models import sql [as 别名]
# 或者: from django.db.models.sql import InsertQuery [as 别名]
def chain(self, klass=None):
        """Chains this query to another.

        We override this so that we can make sure our subclassed query
        classes are used.
        """

        if klass == sql.UpdateQuery:
            return super().chain(PostgresUpdateQuery)

        if klass == sql.InsertQuery:
            return super().chain(PostgresInsertQuery)

        return super().chain(klass) 
开发者ID:SectorLabs,项目名称:django-postgres-extra,代码行数:16,代码来源:sql.py


注:本文中的django.db.models.sql.InsertQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。