aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/DBIx/Class/SQLMaker/Pg
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-04-28 10:42:05 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-04-28 15:38:23 +0100
commit63a9b3c81a58ced0c63fa7c02a45535cde91acae (patch)
tree8f85653640d478f6c1cfab5ce3757729cee19f1e /perllib/DBIx/Class/SQLMaker/Pg
parent4edf5a8a9b46311b3889a5382dfd05f7caf1d792 (diff)
Add dbic-pg-server-cursors library, set as default
Found at https://github.com/mzealey/dbic-pg-server-cursors, not on CPAN.
Diffstat (limited to 'perllib/DBIx/Class/SQLMaker/Pg')
-rw-r--r--perllib/DBIx/Class/SQLMaker/Pg/ServerCursor.pm21
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