當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。