The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::SpamcupNG::Summary::Recorder - class to save Summary to SQLite3

SYNOPSIS

    use App::SpamcupNG::Summary::Recorder;

    # just pretend that $summary is an existing App::SpamcupNG::Summary instance
    my $recorder = App::SpamcupNG::Summary::Recorder->new(
        '/some/path/database_file' );
    $recorder->init;
    $recorder->save($summary);

DESCRIPTION

This class is used to persist App::SpamcupNG::Summary instances to a SQLite3 database.

METHODS

new

Creates a new recorder instance.

Expects as parameter the complete path to a existing (or to create) SQLite 3 file.

init

Initialize the database if it doesn't exist yet. This is idempotent.

save

Persists a App::SpamcupNG::Summary instance to the database.

Returns "true" (in Perl terms) if everything goes fine.

DESTROY

Properly closes the SQLite 3 database file when the recorder instance goes out of scope.

QUERYING RESULTS

This is a sample query to checkout records in the database:

    SELECT A.id,
      A.tracking_id,
      DATETIME(A.created, 'unixepoch') AS CREATED,
      B.name AS CHARSET,
      C.name AS CONTENT_TYPE,
      A.age,
      D.name AS MAILER,
      E.report_id,
      F.email
    FROM summary A outer left join email_charset B on A.charset_id = B.id
    INNER JOIN email_content_type C ON A.content_type_id = C.id
    OUTER LEFT JOIN mailer D ON A.mailer_id = D.id
    INNER JOIN summary_receiver E ON A.id = E.summary_id
    INNER JOIN receiver F ON E.receiver_id = F.id;

SEE ALSO