| 1 | use strict; | ||
| 2 | use 5.010; | ||
| 3 | |||
| 4 | package FusqlFS::Backend::PgSQL::Queries; | ||
| 5 | use FusqlFS::Version; | ||
| 6 | our $VERSION = $FusqlFS::Version::VERSION; | ||
| 7 | use parent 'FusqlFS::Artifact'; | ||
| 8 | |||
| 9 | =begin testing get | ||
| 10 | |||
| 11 | is $_tobj->get('query'), undef; | ||
| 12 | |||
| 13 | =end testing | ||
| 14 | =cut | ||
| 15 | sub get | ||
| 16 | { | ||
| 17 | my $self = shift; | ||
| 18 | my ($name) = @_; | ||
| 19 | return $self->{$name}||undef; | ||
| 20 | } | ||
| 21 | |||
| 22 | =begin testing list | ||
| 23 | |||
| 24 | cmp_set $_tobj->list(), []; | ||
| 25 | |||
| 26 | =end testing | ||
| 27 | =cut | ||
| 28 | sub list | ||
| 29 | { | ||
| 30 | my $self = shift; | ||
| 31 | return [ keys %$self ]; | ||
| 32 | } | ||
| 33 | |||
| 34 | =begin testing create after get list | ||
| 35 | |||
| 36 | isnt $_tobj->create('query'), undef; | ||
| 37 | isa_ok $_tobj->get('query'), 'CODE'; | ||
| 38 | is_deeply $_tobj->list(), [ 'query' ]; | ||
| 39 | |||
| 40 | =end testing | ||
| 41 | =cut | ||
| 42 | sub create | ||
| 43 | { | ||
| 44 | my $self = shift; | ||
| 45 | my ($name) = @_; | ||
| 46 | $self->{$name} = sub () { | ||
| 47 | my $query = shift; | ||
| 48 | return '' unless $query; | ||
| 49 | return $self->dump($self->all_row($query)); | ||
| 50 | }; | ||
| 51 | } | ||
| 52 | |||
| 53 | =begin testing drop after rename | ||
| 54 | |||
| 55 | isnt $_tobj->drop('new_query'), undef; | ||
| 56 | is $_tobj->get('new_query'), undef; | ||
| 57 | is_deeply $_tobj->list(), []; | ||
| 58 | |||
| 59 | =end testing | ||
| 60 | =cut | ||
| 61 | sub drop | ||
| 62 | { | ||
| 63 | my $self = shift; | ||
| 64 | my ($name) = @_; | ||
| 65 | delete $self->{$name}; | ||
| 66 | } | ||
| 67 | |||
| 68 | =begin testing rename after create | ||
| 69 | |||
| 70 | my $oldquery = $_tobj->get('query'); | ||
| 71 | isnt $_tobj->rename('query', 'new_query'), undef; | ||
| 72 | is $_tobj->get('query'), undef; | ||
| 73 | is $_tobj->get('new_query'), $oldquery; | ||
| 74 | is_deeply $_tobj->list(), [ 'new_query' ]; | ||
| 75 | |||
| 76 | =end testing | ||
| 77 | =cut | ||
| 78 | sub rename | ||
| 79 | { | ||
| 80 | my $self = shift; | ||
| 81 | my ($name, $newname) = @_; | ||
| 82 | return unless exists $self->{$name}; | ||
| 83 | $self->{$newname} = $self->{$name}; | ||
| 84 | delete $self->{$name}; | ||
| 85 | } | ||
| 86 | |||
| 87 | 1; | ||
| 88 | |||
| 89 | __END__ |