13 810
правок
Изменения
Funq
,→Примеры запросов
== Примеры запросов ==
=== Пример 1: Сложный запрос ===
Вот, например, запрос из начала статьи на Perl:
<source lang="perl">$query = $dbhfunq
->query(album2album => "t1")->where("t1.parent=? and t1.pid=?pid")
->join($dbhfunq->query(albums => "t0")->where("t0.id=t1.child and t0.?t0where"))->leftjoin($dbhfunq->query(album2album => "t3")->where("t3.parent=t1.parent and t3.pid=?pid"))->join($dbhfunq->query(album2album => "t4")->where("t4.parent=t3.child and t4.child=t1.child and t4.pid=?pid"))->select("t0.*", "(t3.parent is null) as t1._direct")->hint({calc-found-rows => 1}'calc_found_rows')
->group("t0.id")
->where("t1._direct=1")
<source lang="perl">
$rows = $query->stmt->hasharray({
parent => $parent,
pid => $pid,
</source>
Запрос попроще:
->limit("?offset", "?limit")
</source>
=== Пример 3: Очень простой ===
Или совсем простой:
$dbh->query("exif")->where("file=?")
</source>
=== Пример 4: Подзапрос ===
А вот подзапрос:
)
</source>
=== Пример 5: Вложенный подзапрос ===
Или даже два вложенных подзапроса:
)
</source>
=== Пример 6: Запрос из DBIx::Class::Cookbook ===
SQL-запрос: