Class::DBI::UUID - Provide Globally Unique Column Values


Class-DBI-UUID documentation  | view source Contained in the Class-DBI-UUID distribution.

Index


NAME

Top

Class::DBI::UUID - Provide Globally Unique Column Values

SYNOPSIS

Top

  package MyApp::User;
  use base qw[Class::DBI];

  __PACKAGE__->connection('dbi:SQLite:dbfile', '', '');
  __PACKAGE__->table(q[users]);
  __PACKAGE__->columns(Primary => 'id');
  __PACKAGE__->columns(Essential => qw[username password]);

  use Class::DBI::UUID;
  __PACKAGE__->uuid_columns('id');

  # Elsewhere..
  my $user = MyApp::User->create({
      username => 'user',
      password => 'pass',
  });

  print $user->id; # A UUID string.

DESCRIPTION

Top

This module implements globally unique columns values. When an object is created, the columns specified are given unique IDs. This is particularly helpful when running in an environment where auto incremented primary keys won't work, such as multi-master replication.

uuid_columns

  MyApp::User->uuid_columns(MyApp::User->columns('Primary'));

A before_create trigger will be set up to set the values of each column listed as input to a Data::UUID string. Change the type of string output using the uuid_columns_type class method.

uuid_columns_type

  MyApp::User->uuid_columns_type('bin'); # keep it small

By default the type will be str. It's the largest, but its also the safest for general use. Possible values are bin, str, hex, and b64. Basically, anything that you can append to create_ and still get a valid method name from Data::UUID. Also returns the type to be used.

Do not change this value on a whim. If you do change it, change it before your call to uuid_columns, or, call uuid_columns again after it is changed (therefore calling it before uuid_columns, but also adding extra triggers without need).

EXPORTS

Top

This module is implemented as a mixin and therefore exports the functions uuid_columns, and uuid_columns_type into the caller's namespace. If you don't want these to be exported, then load this module using require.

SEE ALSO

Top

Class::DBI, Data::UUID, perl.

AUTHOR

Top

Casey West, <casey@geeknest.com>.

COPYRIGHT

Top


Class-DBI-UUID documentation  | view source Contained in the Class-DBI-UUID distribution.