aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/DBIx/Class/SQLMaker/Pg/ServerCursor.pm
blob: dc1be419e8aba1401464a813c19e5c6fd66d374c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package DBIx::Class::SQLMaker::Pg::ServerCursor;
use strict;
use warnings;
use base 'DBIx::Class::SQLMaker';
use mro 'c3';

# SQLMaker to return the SQL which creates a server-side cursor on Postgres if
# _as_cursor is passed with the name of the cursor to create.
sub select {
    my $self = shift;
    my ($table, $fields, $where, $rs_attrs, $limit, $offset) = @_;
    my ($sql, @all_bind) = $self->next::method(@_);

    if( my $cursor_name = $rs_attrs->{_as_cursor} ) {
        $sql = "DECLARE $cursor_name CURSOR WITH HOLD FOR $sql";
    }

    return wantarray ? ($sql, @all_bind) : $sql;
}

1