NAME

App::MonM::Notifier::Store - monotifier store class

VERSION

Version 1.01

SYNOPSIS

use App::MonM::Notifier::Store;

my $store = new App::MonM::Notifier::Store(
    dsn => "DBI:mysql:database=monotifier;host=mysql.example.com",
    user => "username",
    password => "password",
    set => [
        "RaiseError        0",
        "PrintError        0",
        "mysql_enable_utf8 1",
    ],
);

die($store->error) unless $store->status;

DESCRIPTION

This module provides store methods.

CREATE TABLE IF NOT EXISTS `monotifier` (
  `id` int(11) NOT NULL COMMENT 'ID',
  `to` char(255) DEFAULT NULL COMMENT 'Recipient name',
  `channel` char(255) DEFAULT NULL COMMENT 'Recipient channel',
  `subject` text COMMENT 'Message subject',
  `message` text COMMENT 'Message content',
  `pubdate` int(11) DEFAULT NULL COMMENT 'Date (unixtime) of the publication',
  `expires` int(11) DEFAULT NULL COMMENT 'Date (unixtime) of the expire',
  `status` char(32) DEFAULT NULL COMMENT 'Status of transaction',
  `comment` char(255) DEFAULT NULL COMMENT 'Comment',
  `errcode` int(11) DEFAULT NULL COMMENT 'Error code',
  `errmsg` text COMMENT 'Error message',
  PRIMARY KEY (`id`),
  KEY `I_ID` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

new

my $store = new App::MonM::Notifier::Store(
    dsn => "DBI:mysql:database=monotifier;host=mysql.example.com",
    user => "username",
    password => "password",
    set => [
        "RaiseError        0",
        "PrintError        0",
        "mysql_enable_utf8 1",
    ],
);

Creates DBI object

add

$store->add(
    to      => $user,
    channel => $ch_name,
    subject => $subject,
    message => $message,
) or die($store->error);

Adds new recored

clean

$store->clean or die($store->error);

Delete incorrect records (that are expired, skipped or failed)

del

$store->del($id) or die($store->error);

Delete record by id

dsn

my $dsn = $store->dsn;

Returns DSN string of current database connection

error

my $error = $store->error;

Returns error message

my $status = $store->error( "Error message" );

Sets error message if argument is provided. This method in "set" context returns status of the operation as status() method.

get

my %data = $store->get($id);

Returns data from database by id

getall

my @table = $store->getall();
my @table_100 = $store->getall(100);

Returns data from database with limit supporting

getByName

my %data = $store->getByName($username, $ch_name);

Returns data from database by username and channel name

is_sqlite

print $store->is_sqlite ? "Is SQLite" : "Is not SQLite"

Returns true if type of current database is SQLite

ping

$store->ping ? 'OK' : 'Database session is expired';

Checks the connection to database

setError

$store->setError($id, 102, "Error string")
    or die($store->error);

Sets error code and error message by id. See App::MonM::Notifier::Const

setStatus

$store->setStatus($id, JOB_EXPIRED, "Comment")
    or die($store->error);

Sets new status by id. See App::MonM::Notifier::Const

status

my $status = $store->status;
my $status = $store->status( 1 ); # Sets the status value and returns it

Get/set BOOL status of the operation

truncate

$store->truncate or die($store->error);

Delete all records

HISTORY

See Changes file

TO DO

See TODO file

BUGS

* none noted

SEE ALSO

CTK::DBI, App::MonM, App::MonM::Notifier

AUTHOR

Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See LICENSE file and https://dev.perl.org/licenses/