NAME
XAS::Model::DBM - Defines helper functions to DBIx::Class methods
SYNOPSIS
use XAS::Model::DBM;
DESCRIPTION
This module is not usually included directly by user level code. It's primiary purpose is to be used as a mixin to a model. This module provides several shortcut methods that make database queries easier. To learn how they work, please consult the DBIx::Class documentation.
You can use this methods in the following fashion.
use XAS::Model::Database 'Tablename';
my $schema = XAS::Model::Database->opendb();
... DBIx::Class version
my @rows = $schema->resultset('Tablename')->search();
... as compared to
my @rows = Tablename->search($schema);
The shortcut require less typing and is slightly more intuitive. Neither approach is "more correct" then the other and sometimes they can be intermixed, especially when searching in related tables.
METHODS
create($class, $schema, ...)
This method is a shortcut for creating records. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the DBIx::Class create() method.
find($class, $schema, ...)
This method is a shortcut for finding a single record. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the DBIx::Class find() method.
search($class, $schena, ...)
This method is a shortcut for record searches. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the DBIx::Class search() method.
search_like($class, $schema, ...)
This method is a shortcut for record searches. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the DBIx::Class search_like() method.
count($class, $schema)
This method is returns count of the record in a table. It takes two parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
find_or_create($class, $schema, ...)
This method is a shortcut to find or create a record. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the DBIx::Class find_or_create() method.
update_or_create($class, $schema, ...)
This method is a shortcut for updating or creating a new record. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the DBIx::Class update_or_create() method.
populate($class, $schena, ...)
This method will load a hash of records into a table. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the DBIx::Class populate() method.
load_records($class, $schema, ...)
This method will load records into an array of hashes based on passed criteria. Any data conversion is done automatically. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the search() method.
delete_records($class, $schema, ...)
This method will delete records based on the passed criteria. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the search() method.
read_record($class, $schema, ...)
This method will find a single record which is returned as a hash with any data conversion already done. It takes two or more parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- ...
-
Other parameters that are passed directly to the find() method.
create_record($class, $schema, $record)
This method will create a single record from a hash. This is done within a transaction and any data conversion is done automatically. Only hash items that match actual fields within the table are stored. It returns a hash of the inserted fields. It takes three parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- $record
-
The record used to create the table entry.
delete_record($class, $schema, $record)
This method will delete a single record from the database. This is done within a transaction. It returns a hash of the record deleted. It takes three parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- $record
-
The record used to delete the table entry.
update_record($class, $schema, $record)
This method will update a single record in the database. This is done within a transaction. Only hash items that match actual fields within the table are updated. It returns a hash of the updated fields. It takes three parameters:
- $class
-
The DBIx::Class model name. Usually a constant defined within XAS::Model::Database.
- $schema
-
The DBIx::Class schema handle returned from opendb() in XAS::Model::Database.
- $record
-
The record used to update the table entry.
SEE ALSO
- XAS::Model
- XAS
- <https://metacpan.org/pod/DBIx::Class|DBIx::Class>
AUTHOR
Kevin L. Esteb, <kevin@kesteb.us>
COPYRIGHT AND LICENSE
Copyright (c) 2012-2015 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.