Gantry::Plugins::AutoCRUDHelper::DBIxClass - the actual CRUD for DBIx::Class AutoCRUD


Gantry documentation Contained in the Gantry distribution.

Index


Code Index:

NAME

Top

Gantry::Plugins::AutoCRUDHelper::DBIxClass - the actual CRUD for DBIx::Class AutoCRUD

SYNOPSIS

Top

This module is required for you by Gantry::Plugins::AutoCRUD, when your controller's get_orm_helper module returns 'Gantry::Plugins::AutoCRUDHelper::DBIxClass'. It supports models which inherit from DBIx::Class.

DESCRIPTION

Top

Inside Gantry::Plugins::AutoCRUD, whenever actual database work needs to be done, your model is asked to supply a helper by calling get_orm_helper. If your models use DBIx::Class, you need to implement that method and have it return 'Gantry::Plugins::AutoCRUDHelper::DBIxClass'.

METHODS

Top

The methods of this module are documented in Gantry::Plugins::AutoCRUD, but here is a list to keep POD testers happy:

insert
retrieve
update
delete

SEE ALSO

Top

    Gantry::Plugins::AutoCRUDHelper
    Gantry::Plugins::AutoCRUDHelper::CDBI

AUTHOR

Top

Phil Crow <philcrow2000@yahoo.com>

COPYRIGHT and LICENSE

Top


Gantry documentation Contained in the Gantry distribution.

package Gantry::Plugins::AutoCRUDHelper::DBIxClass;
use strict;

sub insert {
    my $class       = shift;
    my $gantry_site = shift;
    my $params      = shift;
    my $schema      = $gantry_site->get_schema();
    my $table_name  = $gantry_site->get_model_name->table_name();

    $schema->txn_begin();
    my $new_row     = $schema->resultset( $table_name )->create( $params );
    $schema->txn_commit();

    return $new_row;
}

sub retrieve {
    my $class       = shift;
    my $gantry_site = shift;
    my $id          = shift;

    my $schema      = $gantry_site->get_schema();
    my $table_name  = $gantry_site->get_model_name->table_name();

    my $retrow      = $schema->resultset( $table_name )->find( $id );

    return $retrow;
}

sub update {
    my $class       = shift;
    my $gantry_site = shift;
    my $row         = shift;
    my $params      = shift;

    my $schema      = $gantry_site->get_schema();

    $schema->txn_begin();
    $row->update( $params );
    $row->discard_changes();
    $schema->txn_commit();
}

sub delete {
    my $class       = shift;
    my $gantry_site = shift;
    my $row         = shift;

    my $schema      = $gantry_site->get_schema();
    $schema->txn_begin();
    $row->delete;
    $schema->txn_commit();
}

1;