SlideShare a Scribd company logo
1 of 23
Download to read offline
+ In this presentation I will walk through DBIx::Class
which helps you get started
DBIX::CLASS
WALK THROUGH
~ Sheeju Alex ~
DBI BACKGROUND
+ Perl Database Interface Module
+ High level layer to interact with databases
DBI BACKGROUND
+ Awesome module which can connect to any database you
ask
+ Uniform interface to handle different types of databases
+ Is an ORM (Object Relational Mapper)
+ SQL => Object
DBIX::CLASS
+ Database tables becomes Object
+ Table data and relationships between tables become object
methods
+ Alternatives?
DBIX::CLASS
+ DBIx::Class or Rose::DB::Object (Perl)
+ Hibernate (Java)
+ Yii/Zend (PHP)
+ Founded by Matt S. Trout (mst)
+ Website:
DBIX::CLASS
http://www.dbix-class.org/
+ Benefits?
DBIX::CLASS
+ No more writing SQL
+ Make your coding easier
+ Cross DB: Majority of code should run on all databases
+ SQL statements are executed when it is needed (perfoma)
+ User Role Mangement Example
DBIX EXAMPLE: GENERATE SCHEMA
+ dbicdump
DBIX EXAMPLE: GENERATE SCHEMA
dbicdump -o dump_directory=./lib DBIxTest::Schema
dbi:Pg:dbname=dbix_test sheeju
"{quote_char=>q{"}, quote_field_names=>{0}, name_sep=>{.} }"
+ make_schema_at using simple perl script
DBIX EXAMPLE: GENERATE SCHEMA
#!/usr/bin/env perl
use FindBin;
use Getopt::Std;
use Data::Dumper;
use lib "$FindBin::Bin/../lib";
use DBIx::Class::Schema::Loader 'make_schema_at';
our ($opt_F, $opt_d);
getopts('Fd');
make_schema_at('DBIxTest::Schema',
{
debug => !!($opt_d),
really_erase_my_files => !!($opt_F),
dump_directory=>"$FindBin::Bin/lib",
overwrite_modifications=>1,
preserve_case=>1,
},
['dbi:Pg:dbname=dbix_test','sheeju','sheeju',
{'quote_char' => '"', 'quote_field_names' => '0', 'name
],
);
+ DBIxTest/Schema.pm
DBIX EXAMPLE: GENERATE SCHEMA
use utf8;
package DBIxTest::Schema;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use strict;
use warnings;
use base 'DBIx::Class::Schema';
__PACKAGE__->load_namespaces;
1;
+ Result/User.pm (User Object or User Table)
DBIX EXAMPLE: GENERATE SCHEMA
package DBIxTest::Schema::Result::User;
use base 'DBIx::Class::Core';
__PACKAGE__->table("User");
__PACKAGE__->add_columns(
"Id",
{
accessor => "id", data_type => "integer", is_auto_increment => 1, is_nullable => 0,
sequence => "User_Id_seq",
},
"Name",
{ accessor => "name", data_type => "varchar", is_nullable => 0, size => 255 },
"Email",
{ accessor => "email", data_type => "varchar", is_nullable => 0, size => 255 },
"PasswordSalt",
{ accessor => "password_salt", data_type => "bytea", is_nullable => 0 },
"PasswordHash",
{ accessor => "password_hash", data_type => "bytea", is_nullable => 0 },
"Status",
{ accessor => "status", data_type => "varchar", default_value => "Active", is_nullable => 0, size => 64 },
);
__PACKAGE__->set_primary_key("Id");
__PACKAGE__->add_unique_constraint("User_Email_key", ["Email"]);
__PACKAGE__->has_many(
"user_roles",
"DBIxTest::Schema::Result::UserRole",
{ "foreign.UserId" => "self.Id" },
);
__PACKAGE__->many_to_many("roles", "user_roles", "role");
+ Result/Role.pm
DBIX EXAMPLE: GENERATE SCHEMA
package DBIxTest::Schema::Result::Role;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("Role");
__PACKAGE__->add_columns(
"Id",
{
accessor => "id", data_type => "integer", is_auto_increment => 1, is_nullable => 0,
sequence => "Role_Id_seq",
},
"Name",
{ accessor => "name", data_type => "varchar", is_nullable => 0, size => 255 },
);
__PACKAGE__->set_primary_key("Id");
__PACKAGE__->has_many(
"user_roles",
"DBIxTest::Schema::Result::UserRole",
{ "foreign.RoleId" => "self.Id" },
+ Result/UserRole.pm
DBIX EXAMPLE: GENERATE SCHEMA
package DBIxTest::Schema::Result::UserRole;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("UserRole");
__PACKAGE__->add_columns(
"UserId",
{
accessor => "user_id", data_type => "integer", is_foreign_key => 1, is_nullable
},
"RoleId",
{
accessor => "role_id", data_type => "integer", is_foreign_key => 1, is_nullable
},
);
__PACKAGE__->set_primary_key("UserId", "RoleId");
__PACKAGE__->belongs_to(
"role",
"DBIxTest::Schema::Result::Role",
+ Schema creations
DBIX EXAMPLE: SCHEMA
use DBIxTest::Schema;
my $schema = DBIxTest::Schema->connect( "DBI:Pg:dbname=dbix_test",
"sheeju", "sheeju", { RaiseError => 1, PrintError => 1, 'quote_char' => '"', 'quote
+ C: Create
DBIX EXAMPLE: CRUD
+ Create/Insert Record
my $user_01 = $schema->resultset('User')->create(
{
Name => 'JohnSample',
Email => 'john@sample.com',
PasswordSalt => 'sheeju',
PasswordHash => 'sheeju',
Status => 'Active',
}
);
+ R: Read
DBIX EXAMPLE: CRUD
+ Read All records
my $all_users = $schema->resultset('User')->all;
+ Select/search query
$active_users = $schema->resultset('User')->search({"Status" => "Active"});
+ JOIN and Search query
$active_users = $schema->resultset('User')->search(
{"user_roles.RoleId" => 1},
{"join" => "user_roles"});
+ U: Update
DBIX EXAMPLE: CRUD
+ Update User Email
$user_01->update({Email => 'sheeju@exceleron.com'});
+ Update with Join
$active_users = $schema->resultset('User')->search(
{"user_roles.RoleId" => 1},
{"join" => "user_roles"});
$active_users->update({Status => 'InActive'});
+ D: Delete
DBIX EXAMPLE: CRUD
+ Delete Record
$user_01->delete;
my $user = $schema->resultset('User')->search(
{ Email => 'jeremy@purepwnage.com' }
)->first;
$user->delete if($user);
DBIX EXAMPLE: METHODS YOU LIKE
+ find_or_create
+ update_or_create
+ $schema->deploy
RESULT VS RESULTSET
+ Result = Row
+ ResultSet = Query Plan ($user->active)
Sheeju Alex
THANKS!
Happy Coding :)
Exceleron Inc
Lead Product Developer
sheeju@exceleron.com

More Related Content

What's hot

Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMJonathan Wage
 
Introduction to MarkLogic NoSQL
Introduction to MarkLogic NoSQLIntroduction to MarkLogic NoSQL
Introduction to MarkLogic NoSQLVishal Punjabi
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)Johannes Hoppe
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Groupkchodorow
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applicationsjeromevdl
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPDave Stokes
 
Intro to HTML5 Web Storage
Intro to HTML5 Web StorageIntro to HTML5 Web Storage
Intro to HTML5 Web Storagedylanks
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery FundamentalsGil Fink
 
MooseX::Datamodel - Barcelona Perl Workshop Lightning talk
MooseX::Datamodel - Barcelona Perl Workshop Lightning talkMooseX::Datamodel - Barcelona Perl Workshop Lightning talk
MooseX::Datamodel - Barcelona Perl Workshop Lightning talkJose Luis Martínez
 
Redis the better NoSQL
Redis the better NoSQLRedis the better NoSQL
Redis the better NoSQLOpenFest team
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung MosbachJohannes Hoppe
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 

What's hot (20)

Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
 
jQuery
jQueryjQuery
jQuery
 
Introduction to MarkLogic NoSQL
Introduction to MarkLogic NoSQLIntroduction to MarkLogic NoSQL
Introduction to MarkLogic NoSQL
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Sequelize
SequelizeSequelize
Sequelize
 
NoSQL - Hands on
NoSQL - Hands onNoSQL - Hands on
NoSQL - Hands on
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applications
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
 
Intro to HTML5 Web Storage
Intro to HTML5 Web StorageIntro to HTML5 Web Storage
Intro to HTML5 Web Storage
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
Mysql DBI
Mysql DBIMysql DBI
Mysql DBI
 
MooseX::Datamodel - Barcelona Perl Workshop Lightning talk
MooseX::Datamodel - Barcelona Perl Workshop Lightning talkMooseX::Datamodel - Barcelona Perl Workshop Lightning talk
MooseX::Datamodel - Barcelona Perl Workshop Lightning talk
 
Jquery
JqueryJquery
Jquery
 
Database2
Database2Database2
Database2
 
Redis the better NoSQL
Redis the better NoSQLRedis the better NoSQL
Redis the better NoSQL
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 

Similar to DBIx::Class walkthrough @ bangalore pm

Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioningSource Ministry
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Rabble .
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB AppHenrik Ingo
 
Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Rabble .
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part IIFirdaus Adib
 
Hd insight programming
Hd insight programmingHd insight programming
Hd insight programmingCasear Chu
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology updateDoug Domeny
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Rebecca Grenier
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Third Party Auth in WebObjects
Third Party Auth in WebObjectsThird Party Auth in WebObjects
Third Party Auth in WebObjectsWO Community
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceParashuram N
 

Similar to DBIx::Class walkthrough @ bangalore pm (20)

Php summary
Php summaryPhp summary
Php summary
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
php2.pptx
php2.pptxphp2.pptx
php2.pptx
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
DataMapper
DataMapperDataMapper
DataMapper
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Html indexed db
Html indexed dbHtml indexed db
Html indexed db
 
Hd insight programming
Hd insight programmingHd insight programming
Hd insight programming
 
Python database access
Python database accessPython database access
Python database access
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology update
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Third Party Auth in WebObjects
Third Party Auth in WebObjectsThird Party Auth in WebObjects
Third Party Auth in WebObjects
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

DBIx::Class walkthrough @ bangalore pm

  • 1. + In this presentation I will walk through DBIx::Class which helps you get started DBIX::CLASS WALK THROUGH
  • 3. DBI BACKGROUND + Perl Database Interface Module + High level layer to interact with databases
  • 4. DBI BACKGROUND + Awesome module which can connect to any database you ask + Uniform interface to handle different types of databases
  • 5. + Is an ORM (Object Relational Mapper) + SQL => Object DBIX::CLASS + Database tables becomes Object + Table data and relationships between tables become object methods
  • 6. + Alternatives? DBIX::CLASS + DBIx::Class or Rose::DB::Object (Perl) + Hibernate (Java) + Yii/Zend (PHP)
  • 7. + Founded by Matt S. Trout (mst) + Website: DBIX::CLASS http://www.dbix-class.org/
  • 8. + Benefits? DBIX::CLASS + No more writing SQL + Make your coding easier + Cross DB: Majority of code should run on all databases + SQL statements are executed when it is needed (perfoma)
  • 9. + User Role Mangement Example DBIX EXAMPLE: GENERATE SCHEMA
  • 10. + dbicdump DBIX EXAMPLE: GENERATE SCHEMA dbicdump -o dump_directory=./lib DBIxTest::Schema dbi:Pg:dbname=dbix_test sheeju "{quote_char=>q{"}, quote_field_names=>{0}, name_sep=>{.} }"
  • 11. + make_schema_at using simple perl script DBIX EXAMPLE: GENERATE SCHEMA #!/usr/bin/env perl use FindBin; use Getopt::Std; use Data::Dumper; use lib "$FindBin::Bin/../lib"; use DBIx::Class::Schema::Loader 'make_schema_at'; our ($opt_F, $opt_d); getopts('Fd'); make_schema_at('DBIxTest::Schema', { debug => !!($opt_d), really_erase_my_files => !!($opt_F), dump_directory=>"$FindBin::Bin/lib", overwrite_modifications=>1, preserve_case=>1, }, ['dbi:Pg:dbname=dbix_test','sheeju','sheeju', {'quote_char' => '"', 'quote_field_names' => '0', 'name ], );
  • 12. + DBIxTest/Schema.pm DBIX EXAMPLE: GENERATE SCHEMA use utf8; package DBIxTest::Schema; # Created by DBIx::Class::Schema::Loader # DO NOT MODIFY THE FIRST PART OF THIS FILE use strict; use warnings; use base 'DBIx::Class::Schema'; __PACKAGE__->load_namespaces; 1;
  • 13. + Result/User.pm (User Object or User Table) DBIX EXAMPLE: GENERATE SCHEMA package DBIxTest::Schema::Result::User; use base 'DBIx::Class::Core'; __PACKAGE__->table("User"); __PACKAGE__->add_columns( "Id", { accessor => "id", data_type => "integer", is_auto_increment => 1, is_nullable => 0, sequence => "User_Id_seq", }, "Name", { accessor => "name", data_type => "varchar", is_nullable => 0, size => 255 }, "Email", { accessor => "email", data_type => "varchar", is_nullable => 0, size => 255 }, "PasswordSalt", { accessor => "password_salt", data_type => "bytea", is_nullable => 0 }, "PasswordHash", { accessor => "password_hash", data_type => "bytea", is_nullable => 0 }, "Status", { accessor => "status", data_type => "varchar", default_value => "Active", is_nullable => 0, size => 64 }, ); __PACKAGE__->set_primary_key("Id"); __PACKAGE__->add_unique_constraint("User_Email_key", ["Email"]); __PACKAGE__->has_many( "user_roles", "DBIxTest::Schema::Result::UserRole", { "foreign.UserId" => "self.Id" }, ); __PACKAGE__->many_to_many("roles", "user_roles", "role");
  • 14. + Result/Role.pm DBIX EXAMPLE: GENERATE SCHEMA package DBIxTest::Schema::Result::Role; use strict; use warnings; use base 'DBIx::Class::Core'; __PACKAGE__->table("Role"); __PACKAGE__->add_columns( "Id", { accessor => "id", data_type => "integer", is_auto_increment => 1, is_nullable => 0, sequence => "Role_Id_seq", }, "Name", { accessor => "name", data_type => "varchar", is_nullable => 0, size => 255 }, ); __PACKAGE__->set_primary_key("Id"); __PACKAGE__->has_many( "user_roles", "DBIxTest::Schema::Result::UserRole", { "foreign.RoleId" => "self.Id" },
  • 15. + Result/UserRole.pm DBIX EXAMPLE: GENERATE SCHEMA package DBIxTest::Schema::Result::UserRole; use strict; use warnings; use base 'DBIx::Class::Core'; __PACKAGE__->table("UserRole"); __PACKAGE__->add_columns( "UserId", { accessor => "user_id", data_type => "integer", is_foreign_key => 1, is_nullable }, "RoleId", { accessor => "role_id", data_type => "integer", is_foreign_key => 1, is_nullable }, ); __PACKAGE__->set_primary_key("UserId", "RoleId"); __PACKAGE__->belongs_to( "role", "DBIxTest::Schema::Result::Role",
  • 16. + Schema creations DBIX EXAMPLE: SCHEMA use DBIxTest::Schema; my $schema = DBIxTest::Schema->connect( "DBI:Pg:dbname=dbix_test", "sheeju", "sheeju", { RaiseError => 1, PrintError => 1, 'quote_char' => '"', 'quote
  • 17. + C: Create DBIX EXAMPLE: CRUD + Create/Insert Record my $user_01 = $schema->resultset('User')->create( { Name => 'JohnSample', Email => 'john@sample.com', PasswordSalt => 'sheeju', PasswordHash => 'sheeju', Status => 'Active', } );
  • 18. + R: Read DBIX EXAMPLE: CRUD + Read All records my $all_users = $schema->resultset('User')->all; + Select/search query $active_users = $schema->resultset('User')->search({"Status" => "Active"}); + JOIN and Search query $active_users = $schema->resultset('User')->search( {"user_roles.RoleId" => 1}, {"join" => "user_roles"});
  • 19. + U: Update DBIX EXAMPLE: CRUD + Update User Email $user_01->update({Email => 'sheeju@exceleron.com'}); + Update with Join $active_users = $schema->resultset('User')->search( {"user_roles.RoleId" => 1}, {"join" => "user_roles"}); $active_users->update({Status => 'InActive'});
  • 20. + D: Delete DBIX EXAMPLE: CRUD + Delete Record $user_01->delete; my $user = $schema->resultset('User')->search( { Email => 'jeremy@purepwnage.com' } )->first; $user->delete if($user);
  • 21. DBIX EXAMPLE: METHODS YOU LIKE + find_or_create + update_or_create + $schema->deploy
  • 22. RESULT VS RESULTSET + Result = Row + ResultSet = Query Plan ($user->active)
  • 23. Sheeju Alex THANKS! Happy Coding :) Exceleron Inc Lead Product Developer sheeju@exceleron.com