++ed by:

1 non-PAUSE user.

PJ-DSI-DEVOPS
and 2 contributors

NAME

App::AutoCRUD::DataSource -

DESCRIPTION

This class encapsulates all information needed by the AutoCRUD application for communicating with one particular datasource. The information comes partly from the configuration file, and partly from the requests made to the database schema.

ATTRIBUTES

app

Weak reference to the application that hosts this datasource.

name

Unique name identifying this datasource within the AutoCRUD application. This name will be part of URLs addressing this datasource.

config

Copy of the configuration tree (see App::AutoCRUD::ConfigDomain) for this specific datasource.

dbh

DBI database handle, which encapsulates the connection to the database. The dbh is created on demand, from connection parameters or from a coderef specified in the configuration tree (see "dbh" in App::AutoCRUD::ConfigDomain); alternatively, it can also be supplied from the calling program, or grabbed from the schema. Once created, the dbh is readonly and cannot be changed (even if the schema itself was bound to another dbh by a remote module -- the dbh will be forced again before processing the HTTP request).

schema

An instance or a subclass of DBIx::DataModel::Schema. Usually this is loaded from parameters specified in the configuration tree; if such parameters are absent, the fallback behavior is to generate a class on the fly, using DBIx::DataModel::Schema::Generator.

query_parser

An instance of SQL::Abstract::FromQuery, for parsing the content of search forms.

tablegroups

Information about tables in that datasource. This is an ordered list of tablegroups, where each tablegroup is a hashref with a name, a descr (description), and an ordered list of tables. Each table in that list contains information as returned by the "table_info" in DBI method, plus an additional descr field.

The tablegroups structure comes from the configuration data. If tables are found in the database, but not mentioned in the configuration, they are automatically inserted into a group called "Unclassified".

METHODS

config

  my $data = $datasource->config(@path);

Returns the config subtree at location @path under this datasource.

descr

Returns the description string for this datasource, as specified in config.

prepare_for_request

  $datasource->prepare_for_request($req);

Called from "call" in App::AutoCRUD before serving a request. This is a hook for subclasses to provide application-specific behaviour if needed (like for example resetting the database connection or supplying user credentials from the HTTP request). The argument $req is an instance of Plack::Request.

primary_key

Proxy method to "primary_key" in DBIx::DataModel::Meta::Source.

colgroups

  my $colgroups = $datasource->colgroups($table_name);

Returns an arrayref of column groups, as specified in config (or guessed from the database meta-information, if the config says nothing).

Each column group is a hashref with keys name (containing a string) and columns (containing an arrayref of columns).

Each column is a hashref as returned from "column_info" in DBI, i.e. containing keys TABLE_NAME, COLUMN_NAME, DATA_TYPE, COLUMN_SIZE, etc. In addition, some other keys are inserted into this hashref :

is_pkey

Boolean indicating that this column is part of the primary key

paths

An arrayref of paths to other tables. Each path is a hashref with keys name (name of this path), to_table (name of the associated table), foreign_key (name of the associated column in the remote table).