Class-DBI-mysql-1.00 > Class::DBI::mysql

名前

Class::DBI::mysql - Extensions to Class::DBI for MySQL

Class::DBI::mysql - MySQL用のClass::DBI拡張

概要

  package Film;
  use base 'Class::DBI::mysql';
  __PACKAGE__->set_db('Main', 'dbi:mysql:dbname', 'user', 'password');
  __PACKAGE__->set_up_table("film");

  __PACKAGE__->autoinflate(dates => 'Time::Piece');

  # Somewhere else ...

  my $type = $class->column_type('column_name');
  my @allowed = $class->enum_vals('column_name');

  my $tonights_viewing  = Film->retrieve_random;

説明

This is an extension to Class::DBI, containing several functions and optimisations for the MySQL database. Instead of setting Class::DBI as your base class, use this instead.

これはMySQLデータベースの為に幾つかの機能と最適化を含んだ Class::DBIの拡張です。 Class::DBIに代わってこのクラスをベースクラスとして設定して下さい。

メソッド

set_up_table

        __PACKAGE__->set_up_table("table_name");

Traditionally, to use Class::DBI, you have to set up the columns:

伝統的に、Class::DBIを使用する際、あなたはカラムをセットしなければなりません:

        __PACKAGE__->columns(All => qw/list of columns/);
        __PACKAGE__->columns(Primary => 'column_name');

Whilst this allows for more flexibility if you're going to arrange your columns into a variety of groupings, sometimes you just want to create the 'all columns' list. Well, this information is really simple to extract from MySQL itself, so why not just use that?

もしあなたがカラムを様々な組み合わせでアレンジしたい場合 より柔軟にこれを考慮しますが、 時折、あなたは'全てのカラム'のリストを作成することを望んでいます。

さて、この情報はMySQL自身から実に簡単に抽出することができますが、 なぜこれを使用しないのですか?

This call will extract the list of all the columns, and the primary key and set them up for you. It will die horribly if the table contains no primary key, or has a composite primary key.

この呼び出しは全てのカラム、プライマリキーのリストを抽出し、 セットアップします。 テーブルにプライマリキーもしくは複合プライマリキーを含んでいない場合 それはおそらくdieするでしょう。

autoinflate

  __PACKAGE__->autoinflate(column_type => 'Inflation::Class');

  __PACKAGE__->autoinflate(timestamp => 'Time::Piece');
  __PACKAGE__->autoinflate(dates => 'Time::Piece');

This will automatically set up has_a() relationships for all columns of the specified type to the given class.

これは指定されたタイプに関する全てのカラムの為に、 自動的に与えられたクラスにhas_a()をセットアップするでしょう。

We currently assume that all classess passed will be able to inflate and deflate without needing extra has_a arguments, with the example of Time::Piece objects, which we deal with using Time::Piece::mysql (which you'll have to have installed!).

我々は、Time::Piece::mysqlを使用することで対処できるTime::Pieceオブジェクトの例で 特別なhas_aの引数を必要無しに全てのクラスがパスすることを仮定している。 (あなたはインストールしなければならなくなるでしょう!)

The special type 'dates' will autoinflate all columns of type date, datetime or timestamp.

特別なタイプである'dates'はカラムタイプの date、datetime、またはtimestampがautoinflateされるでしょう。

create_table

        $class->create_table(q{
                name    VARCHAR(40)     NOT NULL PRIMARY KEY,
                rank    VARCHAR(20)     NOT NULL DEFAULT 'Private',
                serial  INTEGER         NOT NULL
        });

This creates the table for the class, with the given schema. If the table already exists we do nothing.

これはクラスのために与えられたスキーマでテーブルを作成します。 もしテーブルが既に存在する場合、我々は何もしません。

A typical use would be:

典型的な使い方:

        Music::CD->table('cd');
        Music::CD->create_table(q{
          cdid   MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
          artist MEDIUMINT UNSIGNED NOT NULL,
                title  VARCHAR(255),
                year   YEAR,
                INDEX (artist),
                INDEX (title)
        });
        Music::CD->set_up_table;

drop_table

        $class->drop_table;

Drops the table for this class, if it exists.

もしそれが存在している場合は、このクラスによりテーブルをドロップします。

column_type

        my $type = $class->column_type('column_name');

This returns the 'type' of this table (VARCHAR(20), BIGINT, etc.)

これは(例えばVARCHAR(20), BIGINT, etc.)などのテーブルの'type'を返す。

enum_vals

        my @allowed = $class->enum_vals('column_name');

This returns a list of the allowable values for an ENUM column.

これはENUMカラムのための許容量のリストを返す。

retrieve_random

        my $film = Film->retrieve_random;

This will select a random row from the database, and return you the relevant object.

これはデータベースからランダムに列を選択肢、そして関連するオブジェクトを 返すでしょう。

(MySQL 3.23 and higher only, at this point)

(現時点でMySQL3.23よりも高いバージョンのものである必要がある)

SEE ALSO

Class::DBI. MySQL (http://www.mysql.com/)

作者

Tony Bowden

BUGS and QUERIES

Please direct all correspondence regarding this module to: bug-Class-DBI-mysql@rt.cpan.org

コピーライト & ライセンス

  Copyright (C) 2001-2005 Tony Bowden.

  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License; either version 2 of the License,
  or (at your option) any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.

翻訳者

 atsushi kobayashi(nekokak@users.sourceforge.jp)