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

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 

Recently uploaded (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 

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