Zing::Store::Pg

Postgres Storage

Postgres Storage Abstraction

method: drop method: encode method: keys method: decode method: lpull method: lpush method: recv method: rpull method: rpush method: send method: size method: slot method: test

use Test::DB::Postgres;
use Zing::Encoder::Dump;
use Zing::Store::Pg;

my $testdb = Test::DB::Postgres->new;
my $store = Zing::Store::Pg->new(
  client => $testdb->create->dbh,
  encoder => Zing::Encoder::Dump->new
);

# $store->drop;

Zing::Types

client: ro, opt, InstanceOf["DBI::db"]

Zing::Store

This package provides a Postgres-specific storage adapter for use with data persistence abstractions. The "client" attribute accepts a DBI object configured to connect to a DBD::Pg backend. The ZING_DBNAME environment variable can be used to specify the database name (defaults to "zing"). The ZING_DBHOST environment variable can be used to specify the database host (defaults to "localhost"). The ZING_DBPORT environment variable can be used to specify the database port (defaults to "5432"). The ZING_DBUSER environment variable can be used to specify the database username (defaults to "postgres"). The ZING_DBPASS environment variable can be used to specify the database password. The ZING_DBZONE environment variable can be used to specify the database table name (defaults to "entities").

The drop method removes (drops) the item from the datastore.

drop(Str $key) : Int

=example-1 drop

# given: synopsis

$store->drop('zing:main:global:model:temp');

The encode method encodes and returns the data provided as JSON.

encode(HashRef $data) : Str

=example-1 encode

# given: synopsis

$store->encode({ status => 'ok' });

The keys method returns a list of keys under the namespace of the datastore or provided key.

keys(Str @keys) : ArrayRef[Str]

=example-1 keys

# given: synopsis

my $keys = $store->keys('zing:main:global:model:temp');

=example-2 keys

# given: synopsis

$store->send('zing:main:global:model:temp', { status => 'ok' });

my $keys = $store->keys('zing:main:global:model:temp');

The rpull method pops data off of the bottom of a list in the datastore.

rpull(Str $key) : Maybe[HashRef]

=example-1 rpull

# given: synopsis

$store->rpull('zing:main:global:model:items');

=example-2 rpull

# given: synopsis

$store->rpush('zing:main:global:model:items', { status => 1 });
$store->rpush('zing:main:global:model:items', { status => 2 });

$store->rpull('zing:main:global:model:items');

The lpull method pops data off of the top of a list in the datastore.

lpull(Str $key) : Maybe[HashRef]

=example-1 lpull

# given: synopsis

$store->lpull('zing:main:global:model:items');

=example-2 lpull

# given: synopsis

$store->rpush('zing:main:global:model:items', { status => 'ok' });

$store->lpull('zing:main:global:model:items');

The rpush method pushed data onto the bottom of a list in the datastore.

rpush(Str $key, HashRef $val) : Int

=example-1 rpush

# given: synopsis

$store->rpush('zing:main:global:model:items', { status => 'ok' });

=example-2 rpush

# given: synopsis

$store->rpush('zing:main:global:model:items', { status => 'ok' });

$store->rpush('zing:main:global:model:items', { status => 'ok' });

The decode method decodes the JSON data provided and returns the data as a hashref.

decode(Str $data) : HashRef

=example-1 decode

# given: synopsis

$store->decode('{"status"=>"ok"}');

The recv method fetches and returns data from the datastore by its key.

recv(Str $key) : Maybe[HashRef]

=example-1 recv

# given: synopsis

$store->recv('zing:main:global:model:temp');

=example-2 recv

# given: synopsis

$store->send('zing:main:global:model:temp', { status => 'ok' });

$store->recv('zing:main:global:model:temp');

The send method commits data to the datastore with its key and returns truthy.

send(Str $key, HashRef $val) : Str

=example-1 send

# given: synopsis

$store->send('zing:main:global:model:temp', { status => 'ok' });

The size method returns the size of a list in the datastore.

size(Str $key) : Int

=example-1 size

# given: synopsis

my $size = $store->size('zing:main:global:model:items');

=example-2 size

# given: synopsis

$store->rpush('zing:main:global:model:items', { status => 'ok' });

my $size = $store->size('zing:main:global:model:items');

The slot method returns the data from a list in the datastore by its index.

slot(Str $key, Int $pos) : Maybe[HashRef]

=example-1 slot

# given: synopsis

my $model = $store->slot('zing:main:global:model:items', 0);

=example-2 slot

# given: synopsis

$store->rpush('zing:main:global:model:items', { status => 'ok' });

my $model = $store->slot('zing:main:global:model:items', 0);

The test method returns truthy if the specific key (or datastore) exists.

test(Str $key) : Int

=example-1 test

# given: synopsis

$store->rpush('zing:main:global:model:items', { status => 'ok' });

$store->test('zing:main:global:model:items');

=example-2 test

# given: synopsis

$store->drop('zing:main:global:model:items');

$store->test('zing:main:global:model:items');

The lpush method pushed data onto the top of a list in the datastore.

lpush(Str $key, HashRef $val) : Int

=example-1 lpush

# given: synopsis

$store->lpush('zing:main:global:model:items', { status => '1' });

=example-2 lpush

# given: synopsis

$store->lpush('zing:main:global:model:items', { status => '0' });

$store->lpush('zing:main:global:model:items', { status => '0' });

35 POD Errors

The following errors were encountered while parsing the POD:

Around line 14:

Unknown directive: =name

Around line 20:

Unknown directive: =tagline

Around line 26:

Unknown directive: =abstract

Around line 32:

Unknown directive: =includes

Around line 50:

Unknown directive: =synopsis

Around line 66:

Unknown directive: =libraries

Around line 72:

Unknown directive: =attributes

Around line 78:

Unknown directive: =inherits

Around line 84:

Unknown directive: =description

Around line 100:

Unknown directive: =method

Around line 104:

Unknown directive: =signature

Around line 116:

Unknown directive: =method

Around line 120:

Unknown directive: =signature

Around line 132:

Unknown directive: =method

Around line 137:

Unknown directive: =signature

Around line 157:

Unknown directive: =method

Around line 161:

Unknown directive: =signature

Around line 182:

Unknown directive: =method

Around line 186:

Unknown directive: =signature

Around line 206:

Unknown directive: =method

Around line 210:

Unknown directive: =signature

Around line 230:

Unknown directive: =method

Around line 234:

Unknown directive: =signature

Around line 246:

Unknown directive: =method

Around line 250:

Unknown directive: =signature

Around line 270:

Unknown directive: =method

Around line 274:

Unknown directive: =signature

Around line 286:

Unknown directive: =method

Around line 290:

Unknown directive: =signature

Around line 310:

Unknown directive: =method

Around line 314:

Unknown directive: =signature

Around line 334:

Unknown directive: =method

Around line 338:

Unknown directive: =signature

Around line 360:

Unknown directive: =method

Around line 364:

Unknown directive: =signature