本文整理匯總了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)
示例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)
示例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)
示例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)
示例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()
示例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)