| 1 | package DBIO::PostgreSQL::Age::Storage::Async; | ||
| 2 | # ABSTRACT: Floating async storage layer for Apache AGE (cypher_async) | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | our $VERSION = '0.900007'; | ||
| 8 | |||
| 9 | use DBIO::PostgreSQL::Age::Storage (); | ||
| 10 | |||
| 11 | |||
| 12 | sub required_transport_capabilities { qw(on_connect_replay) } | ||
| 13 | |||
| 14 | |||
| 15 | sub cypher_async { | ||
| 16 | my ($self, $graph, $query, $columns, $params, $opts) = @_; | ||
| 17 | |||
| 18 | # Reuse the sync layer's PURE builder by composition: it only needs | ||
| 19 | # $self->throw_exception (resolved through the composed transport MRO) and the | ||
| 20 | # sync file's lexical JSON encoder, so calling it fully-qualified is DRY and | ||
| 21 | # stays in lock-step with sync cypher(). | ||
| 22 | my ($sql, $bind) = DBIO::PostgreSQL::Age::Storage::_cypher_sql_bind( | ||
| 23 | $self, $graph, $query, $columns, $params, | ||
| 24 | ); | ||
| 25 | |||
| 26 | my $decode = $opts && $opts->{auto_decode}; | ||
| 27 | |||
| 28 | # Pass the '?'-placeholder SQL straight to the transport: shaping '?' to the | ||
| 29 | # wire dialect (e.g. DBD::Pg's $N) is the transport's concern, applied inside | ||
| 30 | # its _query_async (core karr #70 / ADR 0032 '?'-seam). The dollar-quoted cypher | ||
| 31 | # body and any '$name' reference are not placeholders and survive untouched. | ||
| 32 | return $self->_query_async($sql, $bind)->then(sub { | ||
| 33 | my @rows = @_; # raw row arrayrefs, in the declared column order | ||
| 34 | |||
| 35 | my @out; | ||
| 36 | for my $raw (@rows) { | ||
| 37 | my %row; | ||
| 38 | # AGE returns columns named exactly as declared in "AS ($col agtype, ...)", | ||
| 39 | # so zipping @$columns reproduces the sync {Slice => {}} hashref shape. | ||
| 40 | @row{ @$columns } = @$raw; | ||
| 41 | |||
| 42 | if ($decode) { | ||
| 43 | $row{$_} = DBIO::PostgreSQL::Age::Storage::decode_agtype($self, $row{$_}) | ||
| 44 | for keys %row; | ||
| 45 | } | ||
| 46 | |||
| 47 | push @out, \%row; | ||
| 48 | } | ||
| 49 | |||
| 50 | # Resolve to the arrayref sync cypher() returns, so cypher_async(...)->get | ||
| 51 | # equals cypher(...). done(\@out) keeps the arrayref intact through ->then. | ||
| 52 | return $self->future_class->done(\@out); | ||
| 53 | }); | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | sub create_graph_async { | ||
| 58 | my ($self, $name) = @_; | ||
| 59 | return $self->_query_async( | ||
| 60 | 'SELECT * FROM ag_catalog.create_graph(?)', [ $name ], | ||
| 61 | ); | ||
| 62 | } | ||
| 63 | |||
| 64 | |||
| 65 | sub drop_graph_async { | ||
| 66 | my ($self, $name, $cascade) = @_; | ||
| 67 | return $self->_query_async( | ||
| 68 | 'SELECT * FROM ag_catalog.drop_graph(?, ?)', [ $name, $cascade ? 1 : 0 ], | ||
| 69 | ); | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | 1; | ||
| 74 | |||
| 75 | __END__ |