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

File::Sticker::Database - write info to database

VERSION

version 3.0101

SYNOPSIS

    use File::Sticker::Database;

    my $db = File::Sticker::Database->new(%args);

    $db->write_meta(%args);

DESCRIPTION

This will write meta-data from files in various formats, and standardize it to a common nomenclature.

DEBUGGING

whoami

Used for debugging info

METHODS

new

Create a new object, setting global values for the object.

    my $obj = File::Sticker::Database->new(
        dbname=>$dbname,
        wanted_fields=>\%wanted_fields,
        field_order=>\@field_order,
        primary_table=>$primary_table,
        space_sep=>$space_sep,
    );

do_connect

Connect to the database if not connected already.

create_tables

Create the tables for the database. Give them all prefixes so that multiple setups can use the same database.

If the database is readonly, this does not create tables, but it does set up configuration information, so it should still be called.

do_disconnect

Disconnect from the database

start_transaction

Start a transaction.

commit

Commit a pending transaction.

    $self->commit();

get_file_id

Get the fileid of the given file

    my $fileid = $self->get_file_id($filename);

get_file_meta

Get the meta-data for a single file.

    $meta = $self->get_file_meta($file);

get_all_files

Return a list of all the files in the database.

    my @files = @{$db->get_all_files()};

get_all_tags

Return a list of all the tags from the appropriate "deep*" table.

    my @tags = @{$db->get_all_tags()};

query_by_tags

Use +tag -tag nomenclature for searching the database for matching files. If the *info table exists, uses that, otherwise, it uses the "tagfield" in the primary table.

delete_file_from_db

Delete the record for one file from the database

    $db->delete_file_from_db($filename);

add_meta_to_db

Add the given file info to the database.

    $db->add_meta_to_db($filename, %meta);

Helper Functions

Private interface.

_deep_table_name

Return the name of the given deep_* table.

_table_exists

Checks if a given table exists. This can be relevant with a readonly database where tables are not guaranteed to have been created.

_add_tag_prefixes

Add prefixes to the given array of tags.

    my @pref_tags = $self->_add_tag_prefixes($field, \@values);

_do_one_col_query

Do a SELECT query, and return the first column of results. This is a freeform query, so the caller must be careful to formulate it correctly.

my $results = $self->_do_one_col_query($query);

_prepare

Prepare and cache prepared queries.

    my $sth = $self->_prepare($q);

BUGS

Please report any bugs or feature requests to the author.