ORM::Auto - is module for auto create all nedded ORM classes


ORM documentation  | view source Contained in the ORM distribution.

Index


NAME

Top

    ORM::Auto - is module for auto create all nedded ORM classes
    for connected to database.

SYNOPSIS

Top

    use ORM::Auto;
    use ORM::Error;
    use ORM::Db::DBI::SQLite;

    my $error = ORM::Error->new;

    orm->_init(
        prefer_lazy_load     => 0,
        emulate_foreign_keys => 1,
        default_cache_size   => 200,
        error	=> $error,
        db => ORM::Db::DBI::SQLite->new
            (database    => 'data/main.db')
    );
    die $error->text if $error->any;

    unless (orm->sessions(table => 't_sessions')->find_id(id => 1) {
        print "Created new session with id: ".orm->sessions->new->id;
    }

    OR for multi connected

    #Backup books
    use ORM::Auto;
    use ORM::Error;
    use ORM::Db::DBI::SQLite;
    use ORM::Db::DBI::MySQL;

    my $error = ORM::Error->new;

    # Connect to original base
	orm->_init(
        error	=> $error,
        db => ORM::Db::DBI::MySQL->new(
            host        => 'localhost',
            port        => '3306',
            database    => 'books',
            user        => 'book_man',
            password    => 'super_password'
        	)
    );
    die $error->text if $error->any;

    # create the backup base as one file
	orm('new_base')->_init(
        error	=> $error,
        db => ORM::Db::DBI::SQLite->new
            (database    => 'backup_'.time.'.db')
    );
    die $error->text if $error->any;

    # Select the books with setting interested
	my $orm_books = orm->book(table => 'book')->find(
		filter => (orm->book->M->interested == 1),
		error => $error,
		return_res => 1 );

	# Write intersted books in backup base
	while (my $orm = $orm_books->next) {
		orm('new_base')->book(table => 'books')->new(prop => {
					author     => $orm->author,
					title      => $orm->title,
					isbn       => $orm->isbn,
					published  => $orm->date_of_publish
				}
			)
		}
	}




DESCRIPTION

Top

	This module allowed not created on disk, modules for each table in base
	Also and main module for base is not need. All created on fly :)




	return the primary class for connected to database
	config_name - any allowed perl identifier for different connection to bases.
	as default <caller_name> + '_ORM'.

	Example:
		package MyApp::books;
		use ORM::Auto;

		print orm; # printing MyApp::books_ORM

    However, if module config_name is exists, connected with it.

    return the table class for access to data
    parameters allowed only once, in first use. In future is not need.

SEE ALSO

Top

ORM

ORM::Tutorial

ORM::Error

ORM::ResultSet

ORM::Broken

ORM::Db

ORM::Order

ORM::Metaprop

ORM::DbLog

http://perlorm.sourceforge.net/

AUTHOR

Top

Nickolay A. Briginetc

COPYRIGHT AND LICENSE

Top


ORM documentation  | view source Contained in the ORM distribution.