The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::RPi::EnvUI::DB - Database manager for App::RPi::EnvUI environment control sysytem

SYNOPSIS use App::RPi::EnvUI::DB;

    my $db = App::RPi::EnvUI::DB->new;

    $db->method(@args);

DESCRIPTION

This is the database abstraction class for App::RPi::EnvUI. It abstracts away the database work from the API and the webapp itself.

METHODS

new(%args)

Returns a new App::RPi::EnvUI::DB object. All parameters are sent in as a hash structure.

Parameters:

    testing

Optional, Bool. 1 to enable testing mode, 0 to disable.

Default: 0 (off)

aux($aux_id)

Fetches and returns a hash reference containing the details of an auxillary channel.

Parameters:

    $aux_id

Mandatory, String. The string name of the auxillary channel (eg: aux1)

Return: Hash reference (see above)

auxs

Fetches and returns a hash reference of hash references. The keys of the top-level hash is a list of all the auxillary channel names, and each key has a value of another hash reference, containing the details of that specific aux channel. Takes no parameters.

begin

Start a transaction for bulk database writes. Used only in scopes that use update_bulk() and update_bulk_all().

commit

Commit a transaction for bulk database writes. Used only in scopes that use update_bulk() and update_bulk_all().

config_control($want)

Fetches and returns the value of a specific control configuration variable.

Parameters:

    $want

Mandatory, String. The name of the configuration variable to fetch the value for.

Return: The value of the specified variable.

config_core($want)

Fetches and returns the value of a specific core configuration variable.

Parameters:

    $want

Mandatory, String. The name of the configuration variable to fetch the value for.

Return: The value of the specified variable.

config_light($want)

Fetches and returns either a specific light configuration variable value, or the entire light configuration section.

Parameters:

    $want

Optional, String. If specified, we'll fetch only the value of this specific configuration variable.

Return: Single scalar value if $want is sent in, or a hash reference of the entire configuration section where the keys are the variable names, and the values are the configuration values.

db

Returns the actual database instance after it has been created in <new()>. Takes no parameters.

delete($table)

Deletes all data from the specified table.

Parameters:

    $table

Mandatory, String. The name of the table to delete all the data from.

env

Fetches and returns as a hash reference the last database entry of the stats (environment) database table. This hash contains the latest temperature/humidity update, along with a timestamp and row ID. Takes no parameters.

graph_data

Fetches and approximately 24 hours worth of rows starting from the last insert and going backwards.

Returns an array reference that contain an array reference for each row found.

insert_env($temp, $humidity)

Inserts into the stats database table a new row containing a row ID, timestamp, and the values sent in with the parameters.

Parameters:

    $temp

Mandatory, Integer: The temperature.

    $humidity

Mandatory, Integer: The humidity.

last_id

Returns the ID of the last row entered into the stats database table.

update($table, $column, $value, $where_col, $where_val)

Performs an update action on a given database table.

Parameters:

    $table

Mandatory, String: The name of the database table to act upon.

    $column

Mandatory, String: The column of the specified table to operate on.

    $value

Mandatory, depends: The value you want the column set to.

    $where_col

Optional, String: The name of the column to perform a WHERE clause on. If this is not sent in, we'll operate on all rows.

    $where_val

Optional, depends: The value of the column we're looking for in a WHERE clause. This value is ignored if $where_col is not specified.

NOTE: If $where_col is not sent in, we will operate on all rows in the specified table.

update_bulk($table, $col, $where_col, $data)

Bulk updates to the database consolidating statements for efficiency. Used primarily in the initialization phases.

Before you set this call up, you must make a call to config(), and after you're done, make a call to commit.

The parameters are the same as update(), less:

    $data

Mandatory, array ref of array refs. Each inner array reference that contains the value to update to, and the where clause value.

update_bulk_all($table, $col, $data)

Same as update_bulk() except operates on all table rows (there's no where clause).

user($user)

Fetches a user's information as found in the 'auth' database table.

Parameters:

    $user

Mandatory, String. The name of the user to fetch the password for.

Return: A hash reference containing the user's details.

AUTHOR

Steve Bertrand, <steveb@cpan.org<gt>

LICENSE AND COPYRIGHT

Copyright 2017 Steve Bertrand.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.