Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
9886dffd
Kaydet (Commit)
9886dffd
authored
Kas 13, 2018
tarafından
Katie McLaughlin
Kaydeden (comit)
Tim Graham
Kas 13, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29940 -- Recommended using the ORM rather than raw SQL.
üst
db13bca6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
sql.txt
docs/topics/db/sql.txt
+21
-5
No files found.
docs/topics/db/sql.txt
Dosyayı görüntüle @
9886dffd
...
@@ -4,15 +4,28 @@ Performing raw SQL queries
...
@@ -4,15 +4,28 @@ Performing raw SQL queries
.. currentmodule:: django.db.models
.. currentmodule:: django.db.models
When the :doc:`model query APIs </topics/db/queries>` don't go far enough, you
Django gives you two ways of performing raw SQL queries: you can use
can fall back to writing raw SQL. Django gives you two ways of performing raw
:meth:`Manager.raw()` to `perform raw queries and return model instances`__, or
SQL queries: you can use :meth:`Manager.raw()` to `perform raw queries and
you can avoid the model layer entirely and `execute custom SQL directly`__.
return model instances`__, or you can avoid the model layer entirely and
`execute custom SQL directly`__.
__ `performing raw queries`_
__ `performing raw queries`_
__ `executing custom SQL directly`_
__ `executing custom SQL directly`_
.. admonition:: Explore the ORM before using raw SQL!
The Django ORM provides many tools to express queries without writing raw
SQL. For example:
* The :doc:`QuerySet API </ref/models/querysets>` is extensive.
* You can :meth:`annotate <.QuerySet.annotate>` and :doc:`aggregate
</topics/db/aggregation>` using many built-in :doc:`database functions
</ref/models/database-functions>`. Beyond those, you can create
:doc:`custom query expressions </ref/models/expressions/>`.
Before using raw SQL, explore :doc:`the ORM </topics/db/index>`. Ask on
|django-users| or the `#django IRC channel
<irc://irc.freenode.net/django>`_ to see if the ORM supports your use case.
.. warning::
.. warning::
You should be very careful whenever you write raw SQL. Every time you use
You should be very careful whenever you write raw SQL. Every time you use
...
@@ -174,6 +187,9 @@ of people with their ages calculated by the database::
...
@@ -174,6 +187,9 @@ of people with their ages calculated by the database::
Jane is 42.
Jane is 42.
...
...
You can often avoid using raw SQL to compute annotations by instead using a
:ref:`Func() expression <func-expressions>`.
__ https://www.postgresql.org/docs/current/static/functions-datetime.html
__ https://www.postgresql.org/docs/current/static/functions-datetime.html
Passing parameters into ``raw()``
Passing parameters into ``raw()``
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment