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)

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.

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.

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.

config_water($want)

Works exactly the same as config_light() above, but for the feeding configuration.

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.

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.

AUTHOR

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

LICENSE AND COPYRIGHT

Copyright 2016 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.