DBIx::Class Primer How to do common day-to-day tasks.
Creating Rows: create() Get a resultset and call: $rs->create(\%vals). Effectively a shortcut for: $rs->new_result(\%vals)->insert(). my $campaign = $campaigns-> create (   { campaign_name => ‘Test’ } );
Updating Rows: update() $campaign-> update (   { campaign_name => ‘Test Test’ } ); # Is the same as... $campaign->campaign_name( ‘Test Test’ ); $campaign-> update ();
Deleting Rows # Delete all campaigns! $campaigns-> delete (); # Or just delete one row. $campaign-> delete ();
Find Rows: find() Returns a single row. Argument is the value of the primary key. Multiple values may be passed in the case of a multiple column primary key. If passing multiple values then use named arguments. my $campaign = $campaigns-> find ( $cid ); my $translation = $translations-> find ( {   message_code  => $message_code,   language_code => $language_code,   accounting_division_id => 0, } );
find_or_create() my $campaign = $campaigns-> find_or_create (   { campaign_name => ‘Test Test’ } ); # Is the same as... my $campaign = $campaigns-> find (   { campaign_name => ‘Test Test’ } ); $campaign ||= $campaigns-> create (   { campaign_name => ‘Test Test’ } );
update_or_create() my $campaign = $campaigns-> update_or_create (   { campaign_name => ‘Test Test’, status => 0 } ); # Is the same as... my $campaign = $campaigns-> find (   { campaign_name => ‘Test Test’ } ); if ($campaign) {   $campaign-> update ({ status=>0 }); } else {   $campaign = $campaigns-> create (   { campaign_name=>‘Test Test’, status=>0 }   ); }
Relationships DBIC supports one-to-many, many-to-one, many-to-many, and one-to-one relationships. Using these relationships is straightforward. # A one-to-many (has_many) relationship: my $campaigns = $advertiser->campaigns(); # A many-to-one (belongs_to) relationship: my $advertiser = $campaign->advertiser(); # A one-to-one (has_one) relationship: my $money = $campaign->money(); # A many-to-many (many_to_many) relationship: my $users = $role->users();
Resources DBIx::Class Manual @ CPAN http://search.cpan.org/~jrobinson/DBIx-Class-0.08009/lib/DBIx/Class/Manual.pod DBIx::Class Tutorial (under development) http://desert-island.me.uk:8888/perldoc/dbic-tutorial/lib/DBIx/Class/Tutorial/

More Related Content

PPT
DBIC 2 - Resultsets
TXT
Array operators
PDF
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
PDF
Flask 소수전공 강의자료 - 4차시
PDF
Flask 소수전공 강의자료 - 3차시
PDF
2017-08-22 Python×Djangoで作るHR Techサービスのメリット・デメリット
PPTX
PHP Lecture 4 - Working with form, GET and Post Methods
PPTX
CodeIgniter Class Reference
DBIC 2 - Resultsets
Array operators
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 3차시
2017-08-22 Python×Djangoで作るHR Techサービスのメリット・デメリット
PHP Lecture 4 - Working with form, GET and Post Methods
CodeIgniter Class Reference

What's hot (18)

PDF
Systemtabledetailsquery
PDF
Developing applications for performance
PDF
PDF
画像Hacks
PPTX
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
PDF
The Art of Transduction
PDF
Jina Bolton
PDF
Ruby Classes
PPT
Power shell object
DOCX
Miniproject on Employee Management using Perl/Database.
PPT
Chris Mc Glothen Sql Portfolio
PDF
1.4 data cleaning and manipulation in r and excel
PPT
Introduction to perl_lists
PDF
Everything About PowerShell
PPTX
MS SQL Database basic
TXT
PDF
次世代版 PowerCMS 開発プロジェクトのご紹介
PDF
PowerCMS X
Systemtabledetailsquery
Developing applications for performance
画像Hacks
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
The Art of Transduction
Jina Bolton
Ruby Classes
Power shell object
Miniproject on Employee Management using Perl/Database.
Chris Mc Glothen Sql Portfolio
1.4 data cleaning and manipulation in r and excel
Introduction to perl_lists
Everything About PowerShell
MS SQL Database basic
次世代版 PowerCMS 開発プロジェクトのご紹介
PowerCMS X
Ad

Similar to DBIC 3 - Primer (20)

PPT
PHP Unit Testing
PPTX
Tidy Up Your Code
KEY
Unit testing zend framework apps
PDF
Unit testing with zend framework tek11
PDF
Why is crud a bad idea - focus on real scenarios
PDF
Bag Of Tricks From Iusethis
PDF
Value objects
PPTX
Wp query
KEY
Unit testing with zend framework PHPBenelux
ODP
Best Practice Testing with Lime 2
KEY
Data::FormValidator Simplified
PPTX
Database performance 101
ODP
Clean code for WordPress
PPTX
Using of TDD practices for Magento
PDF
Mocking Demystified
PPT
Oracle PL/SQL - Creative Conditional Compilation
PDF
Object Oriented Programming with PHP 5 - More OOP
KEY
Building Better Applications with Data::Manager
PPTX
Drupal7 dbtng
PDF
Symfony2 - extending the console component
PHP Unit Testing
Tidy Up Your Code
Unit testing zend framework apps
Unit testing with zend framework tek11
Why is crud a bad idea - focus on real scenarios
Bag Of Tricks From Iusethis
Value objects
Wp query
Unit testing with zend framework PHPBenelux
Best Practice Testing with Lime 2
Data::FormValidator Simplified
Database performance 101
Clean code for WordPress
Using of TDD practices for Magento
Mocking Demystified
Oracle PL/SQL - Creative Conditional Compilation
Object Oriented Programming with PHP 5 - More OOP
Building Better Applications with Data::Manager
Drupal7 dbtng
Symfony2 - extending the console component
Ad

Recently uploaded (20)

PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
Unlock new opportunities with location data.pdf
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPT
Geologic Time for studying geology for geologist
PPTX
The various Industrial Revolutions .pptx
PPT
What is a Computer? Input Devices /output devices
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Architecture types and enterprise applications.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
STKI Israel Market Study 2025 version august
DOCX
search engine optimization ppt fir known well about this
observCloud-Native Containerability and monitoring.pptx
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Getting Started with Data Integration: FME Form 101
Unlock new opportunities with location data.pdf
O2C Customer Invoices to Receipt V15A.pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Developing a website for English-speaking practice to English as a foreign la...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Hybrid model detection and classification of lung cancer
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Geologic Time for studying geology for geologist
The various Industrial Revolutions .pptx
What is a Computer? Input Devices /output devices
Benefits of Physical activity for teenagers.pptx
Architecture types and enterprise applications.pdf
Zenith AI: Advanced Artificial Intelligence
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
Taming the Chaos: How to Turn Unstructured Data into Decisions
STKI Israel Market Study 2025 version august
search engine optimization ppt fir known well about this

DBIC 3 - Primer

  • 1. DBIx::Class Primer How to do common day-to-day tasks.
  • 2. Creating Rows: create() Get a resultset and call: $rs->create(\%vals). Effectively a shortcut for: $rs->new_result(\%vals)->insert(). my $campaign = $campaigns-> create ( { campaign_name => ‘Test’ } );
  • 3. Updating Rows: update() $campaign-> update ( { campaign_name => ‘Test Test’ } ); # Is the same as... $campaign->campaign_name( ‘Test Test’ ); $campaign-> update ();
  • 4. Deleting Rows # Delete all campaigns! $campaigns-> delete (); # Or just delete one row. $campaign-> delete ();
  • 5. Find Rows: find() Returns a single row. Argument is the value of the primary key. Multiple values may be passed in the case of a multiple column primary key. If passing multiple values then use named arguments. my $campaign = $campaigns-> find ( $cid ); my $translation = $translations-> find ( { message_code => $message_code, language_code => $language_code, accounting_division_id => 0, } );
  • 6. find_or_create() my $campaign = $campaigns-> find_or_create ( { campaign_name => ‘Test Test’ } ); # Is the same as... my $campaign = $campaigns-> find ( { campaign_name => ‘Test Test’ } ); $campaign ||= $campaigns-> create ( { campaign_name => ‘Test Test’ } );
  • 7. update_or_create() my $campaign = $campaigns-> update_or_create ( { campaign_name => ‘Test Test’, status => 0 } ); # Is the same as... my $campaign = $campaigns-> find ( { campaign_name => ‘Test Test’ } ); if ($campaign) { $campaign-> update ({ status=>0 }); } else { $campaign = $campaigns-> create ( { campaign_name=>‘Test Test’, status=>0 } ); }
  • 8. Relationships DBIC supports one-to-many, many-to-one, many-to-many, and one-to-one relationships. Using these relationships is straightforward. # A one-to-many (has_many) relationship: my $campaigns = $advertiser->campaigns(); # A many-to-one (belongs_to) relationship: my $advertiser = $campaign->advertiser(); # A one-to-one (has_one) relationship: my $money = $campaign->money(); # A many-to-many (many_to_many) relationship: my $users = $role->users();
  • 9. Resources DBIx::Class Manual @ CPAN http://search.cpan.org/~jrobinson/DBIx-Class-0.08009/lib/DBIx/Class/Manual.pod DBIx::Class Tutorial (under development) http://desert-island.me.uk:8888/perldoc/dbic-tutorial/lib/DBIx/Class/Tutorial/