View on
MetaCPAN
search.cpan.org is shutting down
For details read Perl NOC. After June 25th this page will redirect to MetaCPAN.org
Clinton Wolfe > Class-ReluctantORM-0.52_0 > Class::ReluctantORM::Static

Download:
Class-ReluctantORM-0.52_0.tar.gz

Dependencies

Annotate this POD

Source  

NAME ^

Class::ReluctantORM::Static - ORM base class for type tables

SYNOPSIS ^

  # In your type table class...

  package Pirate::Status;
  use base 'Class::ReluctantORM::Static';
  __PACKAGE__->build_class(
    schema => 'highseas',
    table => 'pirate_status',
    primary_key => 'pirate_status_id',
    order => 'name',   # Optional - provide this if you want to have your fetch_all sorted
    index => ['name'], # Special for static - you always get an index by primary key, FYI
  );

DESCRIPTION ^

Most databases contain tables that are used as enumarations, specifiying one of a liumited number of values. These tables are sometimes called 'validation tables', 'type tables', or 'check tables'. Common examples include status of an order, states in a country, etc.

Splitting the table out is a big win for data integrity, but a big loss for performance, as you have to go to the database every time you need to find a value. This class eases that pain by caching all values from the table at the first query, and the always responding from the cache.

TRADEOFFS ^

First, you're trading space for time. This module will use a lot of memory if there are a lot of rows in the table, but it's a lot faster than running to the database each time.

Don't use this module for tables with "a lot" of rows. "A lot" will vary, but you certainly shouldn't use it for thousands of rows.

We also trade speed for latency. If the table changes, the cache will never know about it. If you're using this in mod_perl, that means you shouold restart the webserver after making a change to a type table.

Static-derived classes cannot themselves participate in relationships, though other TB classes may refer to them in relationships.

Search, fetch_deep, and search_deep are not supported, but fetch and fetch_by_FIELD are.

IN-MEMORY INDEXES ^

If you providing the 'index' argument to build_class, Static will build in-memory indexes of the object list, by the field you specify.

You always get an index by primary key.

If more than one object has the same value for an indexed field, it is indetermined which object will be returned. You've been warned.

NOT PERMITTED METHODS ^

has_one, has_many, has_many_many

Relationships are not supported.

new

It doesn't make sense to make new rows for the type table.

search, search_by_FIELD

As most fetches are performed from memory, there is no way to handle the WHERE clause.

fetch_with_FIELD, fetch_deep

As static classes can't have relations, these methods are not supported.

%hash = $class->fetch_all_hash_by_id();

$hashref = $class->fetch_all_hash_by_id();

Performs a fetch_all (which is likely already cached) and returns a hash or hashref, keyed on the primary key.

%hash = $class->fetch_all_hash_by_name();

$hashref = $class->fetch_all_hash_by_name();

Performs a fetch_all (which is likely already cached) and returns a hash or hashref, keyed on the 'name' field.

Most Static classes have a 'name' field; if yours doesn't this will blow up.

AUTHOR ^

Clinton Wolfe

syntax highlighting: