diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-04-29 14:11:54 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-04-29 14:11:54 +0100 |
commit | 19088df5efeb30ba3855893fc5080c5125a85152 (patch) | |
tree | ac7c5dcc4f5d9879085f5fb526d68f5791cd2cd5 /perllib/DBIx/Class/SQLMaker/Pg/ServerCursor.pm | |
parent | 6eed68ab198cc1b9fdb683928886f6abff4f7434 (diff) | |
parent | e1605415077d30c1d5f86017486e74ebc498063a (diff) |
Merge branch 'server-side-cursor-dashboard-export'
Diffstat (limited to 'perllib/DBIx/Class/SQLMaker/Pg/ServerCursor.pm')
-rw-r--r-- | perllib/DBIx/Class/SQLMaker/Pg/ServerCursor.pm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/perllib/DBIx/Class/SQLMaker/Pg/ServerCursor.pm b/perllib/DBIx/Class/SQLMaker/Pg/ServerCursor.pm new file mode 100644 index 000000000..dc1be419e --- /dev/null +++ b/perllib/DBIx/Class/SQLMaker/Pg/ServerCursor.pm @@ -0,0 +1,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 |