.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "UR 3pm" .TH UR 3pm "2016-10-31" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" UR \- rich declarative transactional objects .SH "VERSION" .IX Header "VERSION" This document describes \s-1UR\s0 version 0.45 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use UR; \& \& ## no database \& \& class Foo { is => \*(AqBar\*(Aq, has => [qw/prop1 prop2 prop3/] }; \& \& $o1 = Foo\->create(prop1 => 111, prop2 => 222, prop3 => 333); \& \& @o = Foo\->get(prop2 => 222, prop1 => [101,111,121], \*(Aqprop3 between\*(Aq => [200, 400]); \& # returns one object \& \& $o1\->delete; \& \& @o = Foo\->get(prop2 => 222, prop1 => [101,111,121], \*(Aqprop3 between\*(Aq => [200, 400]); \& # returns zero objects \& \& @o = Foo\->get(prop2 => 222, prop1 => [101,111,121], \*(Aqprop3 between\*(Aq => [200, 400]); \& # returns one object again \& \& ## database \& \& class Animal { \& has => [ \& favorite_food => { is => \*(AqText\*(Aq, doc => "what\*(Aqs yummy?" }, \& ], \& data_source => \*(AqMyDB1\*(Aq, \& table_name => \*(AqAnimal\*(Aq \& }; \& \& class Cat { \& is => \*(AqAnimal\*(Aq, \& has => [ \& feet => { is => \*(AqNumber\*(Aq, default_value => 4 }, \& fur => { is => \*(AqText\*(Aq, valid_values => [qw/fluffy scruffy/] }, \& ], \& data_source => \*(AqMyDB1\*(Aq, \& table_name => \*(AqCat\*(Aq \& }; \& \& Cat\->create(feet => 4, fur => \*(Aqfluffy\*(Aq, favorite_food => \*(Aqtaters\*(Aq); \& \& @cats = Cat\->get(favorite_food => [\*(Aqtaters\*(Aq,\*(Aqsea bass\*(Aq]); \& \& $c = $cats[0]; \& \& print $c\->feet,"\en"; \& \& $c\->fur(\*(Aqscruffy\*(Aq); \& \& UR::Context\->commit(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\s-1UR\s0 is a class framework and object/relational mapper for Perl. It starts with the familiar Perl meme of the blessed hash reference as the basis for object instances, and extends its capabilities with \s-1ORM \s0(object-relational mapping) capabilities, object cache, in-memory transactions, more formal class definitions, metadata, documentation system, iterators, command line tools, etc. .PP \&\s-1UR\s0 can handle multiple column primary and foreign keys, \s-1SQL\s0 joins involving class inheritance and relationships, and does its best to avoid querying the database unless the requested data has not been loaded before. It has support for SQLite, Oracle, Mysql and Postgres databases, and the ability to use a text file as a table. .PP \&\s-1UR\s0 uses the same syntax to define non-persistent objects, and supports in-memory transactions for both. .SH "DOCUMENTATION" .IX Header "DOCUMENTATION" .SS "Manuals" .IX Subsection "Manuals" ur \- command line interface .PP UR::Manual::Overview \- \s-1UR\s0 from Ten Thousand Feet .PP UR::Manual::Tutorial \- Getting started with \s-1UR\s0 .PP UR::Manual::Presentation \- Slides for a presentation on \s-1UR\s0 .PP UR::Manual::Cookbook \- Recepies for getting stuff working .PP UR::Manual::Metadata \- \s-1UR\s0's metadata system .PP UR::Object::Type::Initializer \- Defining classes .SS "Basic Entities" .IX Subsection "Basic Entities" UR::Object \- Pretty much everything is-a UR::Object .PP UR::Object::Type \- Metadata class for Classes .PP UR::Object::Property \- Metadata class for Properties .PP UR::Namespace \- Manage packages and classes .PP UR::Context \- Software transactions and More! .PP UR::DataSource \- How and where to get data .SH "QUICK TUTORIAL" .IX Header "QUICK TUTORIAL" First create a Namespace class for your application, Music.pm: .PP .Vb 2 \& package Music; \& use UR; \& \& class Music { \& is => \*(AqUR::Namespace\*(Aq \& }; \& \& 1; .Ve .PP Next, define a data source representing your database, Music/DataSource/DB1.pm .PP .Vb 2 \& package Music::DataSource::DB1; \& use Music; \& \& class Music::DataSource::DB1 { \& is => [\*(AqUR::DataSource::MySQL\*(Aq, \*(AqUR::Singleton\*(Aq], \& has_constant => [ \& server => { value => \*(Aqdatabase=music\*(Aq }, \& owner => { value => \*(Aqmusic\*(Aq }, \& login => { value => \*(Aqmysqluser\*(Aq }, \& auth => { value => \*(Aqmysqlpasswd\*(Aq }, \& ] \& }; \& \& or to get something going quickly, SQLite has smart defaults... \& \& class Music::DataSource::DB1 { \& is => [\*(AqUR::DataSource::SQLite\*(Aq, \*(AqUR::Singleton\*(Aq], \& }; .Ve .PP Create a class to represent artists, who have many CDs, in Music/Artist.pm .PP .Vb 2 \& package Music::Artist; \& use Music; \& \& class Music::Artist { \& id_by => \*(Aqartist_id\*(Aq, \& has => [ \& name => { is => \*(AqText\*(Aq }, \& cds => { is => \*(AqMusic::Cd\*(Aq, is_many => 1, reverse_as => \*(Aqartist\*(Aq } \& ], \& data_source => \*(AqMusic::DataSource::DB1\*(Aq, \& table_name => \*(AqARTIST\*(Aq, \& }; .Ve .PP Create a class to represent CDs, in Music/Cd.pm .PP .Vb 2 \& package Music::Cd; \& use Music; \& \& class Music::Cd { \& id_by => \*(Aqcd_id\*(Aq, \& has => [ \& artist => { is => \*(AqMusic::Artist\*(Aq, id_by => \*(Aqartist_id\*(Aq }, \& title => { is => \*(AqText\*(Aq }, \& year => { is => \*(AqInteger\*(Aq }, \& artist_name => { via => \*(Aqartist\*(Aq, to => \*(Aqname\*(Aq }, \& ], \& data_source => \*(AqMusic::DataSource::DB1\*(Aq, \& table_name => \*(AqCD\*(Aq, \& }; .Ve .PP If the database does not exist, you can run this to generate the tables and columns from the classes you've written (very experimental): .PP .Vb 2 \& $ cd Music \& $ ur update schema .Ve .PP If the database existed already, you could have done this to get it to write the last 2 classes for you: .PP .Vb 2 \& $ cd Music; \& $ ur update classes .Ve .PP Regardless, if the classes and database tables are present, you can then use these classes in your application code: .PP .Vb 2 \& # Using the namespace enables auto\-loading of modules upon first attempt to call a method \& use Music; \& \& # This would get back all Artist objects: \& my @all_artists = Music::Artist\->get(); \& \& # After the above, further requests would be cached \& # if that set were large though, you might want to iterate gradually: \& my $artist_iter = Music::Artist\->create_iterator(); \& \& # Get the first object off of the iterator \& my $first_artist = $artist_iter\->next(); \& \& # Get all the CDs published in 2007 for the first artist \& my @cds_2007 = Music::Cd\->get(year => 2007, artist => $first_artist); \& \& # Use non\-equality operators: \& my @some_cds = Music::Cd\->get( \& \*(Aqyear between\*(Aq => [\*(Aq2004\*(Aq,\*(Aq2009\*(Aq] \& ); \& \& # This will use a JOIN with the ARTISTS table internally to filter \& # the data in the database. @some_cds will contain Music::Cd objects. \& # As a side effect, related Artist objects will be loaded into the cache \& @some_cds = Music::Cd\->get( \& year => \*(Aq2007\*(Aq, \& \*(Aqartist_name like\*(Aq => \*(AqBob%\*(Aq \& ); \& \& # These values would be cached... \& my @artists_for_some_cds = map { $_\->artist } @some_cds; \& \& # This will use a join to prefetch Artist objects related to the \& # objects that match the filter \& my @other_cds = Music::Cd\->get( \& \*(Aqtitle like\*(Aq => \*(Aq%White%\*(Aq, \& \-hints => [\*(Aqartist\*(Aq] \& ); \& my $other_artist_0 = $other_cds[0]\->artist; # already loaded so no query \& \& # create() instantiates a new object in the current "context", but does not save \& # it in the database. It will autogenerate its own cd_id: \& my $new_cd = Music::Cd\->create( \& title => \*(AqCool Album\*(Aq, \& year => 2009 \& ); \& \& # Assign it to an artist; fills in the artist_id field of $new_cd \& $first_artist\->add_cd($new_cd); \& \& # Save all changes in the current transaction back to the database(s) \& # which are behind the changed objects. \& UR::Context\->current\->commit; .Ve .SH "Environment Variables" .IX Header "Environment Variables" \&\s-1UR\s0 uses several environment variables to do things like run with database commits disabled, watching \s-1SQL\s0 queries run, examine query plans, and control cache size, etc. .PP These make development and debugging fast and easy. .PP See UR::Env for details. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" Class::Autouse Cwd Data::Dumper Date::Format \&\s-1DBI\s0 File::Basename FindBin FreezeThaw Path::Class Scalar::Util Sub::Installer Sub::Name Sys::Hostname Text::Diff Time::HiRes XML::Simple .SH "AUTHORS" .IX Header "AUTHORS" \&\s-1UR\s0 was built by the software development team at the McDonnell Genome Institute at the Washington University School of Medicine (Richard K. Wilson, \s-1PI\s0). .PP Incarnations of it run laboratory automation and analysis systems for high-throughput genomics. .PP .Vb 10 \& Anthony Brummett brummett@cpan.org \& Nathan Nutter \& Josh McMichael \& Eric Clark \& Ben Oberkfell \& Eddie Belter \& Feiyu Du \& Adam Dukes \& Brian Derickson \& Craig Pohl \& Gabe Sanderson \& Todd Hepler \& Jason Walker \& James Weible \& Indraniel Das \& Shin Leong \& Ken Swanson \& Scott Abbott \& Alice Diec \& William Schroeder \& Shawn Leonard \& Lynn Carmichael \& Amy Hawkins \& Michael Kiwala \& Kevin Crouse \& Mark Johnson \& Kyung Kim \& Jon Schindler \& Justin Lolofie \& Jerome Peirick \& Ryan Richt \& John Osborne \& Chris Harris \& Philip Kimmey \& Robert Long \& Travis Abbott \& Matthew Callaway \& James Eldred \& Scott Smith sakoht@cpan.org \& David Dooling .Ve .SH "LICENCE AND COPYRIGHT" .IX Header "LICENCE AND COPYRIGHT" Copyright (C) 2002\-2016 Washington University in St. Louis, \s-1MO.\s0 .PP This software is licensed under the same terms as Perl itself. See the \s-1LICENSE\s0 file in this distribution.