NAME

MojoX::Mysql - Mojolicious ♥ Mysql

SYNOPSIS

use MojoX::Mysql;

my %config = (
  user=>'root',
  password=>undef,
  server=>[
      {dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', type=>'master'},
      {dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', type=>'slave'},
      {dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>1, type=>'master'},
      {dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>1, type=>'slave'},
      {dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>2, type=>'master'},
      {dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>2, type=>'slave'},
  ]
);

my $mysql = MojoX::Mysql->new(%config);

DESCRIPTION

MojoX::Mysql is a tiny wrapper around DBD::mysql that makes Mysql a lot of fun to use with the Mojolicious real-time web framework.

ATTRIBUTES

MojoX::Mysql - Attributes.

id

$mysql->id(1); # choice id server

slave

$mysql->slave(1); # query only slave server

async

$mysql->async(1); # query async mode

METHODS

do

my ($insertid,$counter) = $mysql->do('INSERT INTO `names` (`id`,`name`) VALUES(1,?)', 'Lilu Kazerogova');

do (choice server)

my ($insertid,$counter) = $mysql->id(1)->do('INSERT INTO `names` (`id`,`name`) VALUES(1,?)', 'Lilu Kazerogova');

query

my $collection_object = $mysql->query('SELECT * FROM `names` WHERE id = ?', 1);

# or

my ($collection,$counter,$sth,$dbh) = $mysql->query('SELECT * FROM `names` WHERE id = ?', 1);

Return Mojo::Collection object.

query (choice server)

my $collection_object = $mysql->id(1)->query('SELECT * FROM `names` WHERE id = ?', 1);

# or

my ($collection,$counter,$sth,$dbh) = $mysql->id(1)->query('SELECT * FROM `names` WHERE id = ?', 1);

query (async)

my ($sth1,$dbh1) = $mysql->id(1)->async(1)->query('SELECT SLEEP(?) as `sleep`', 1); # Automatically new connection
my ($sth2,$dbh2) = $mysql->id(1)->async(1)->query('SELECT SLEEP(?) as `sleep`', 1); # Automatically new connection

my $collection_object1 = $mysql->result->async($sth1,$dbh1); # Automatically executed methods finish, commit, disconnect
my $collection_object2 = $mysql->result->async($sth2,$dbh2); # Automatically executed methods finish, commit, disconnect

Return Mojo::Collection object.

query (slave server)

my $collection_object = $mysql->id(1)->slave(1)->query('SELECT * FROM `names` WHERE id = ?', 1);

# or

my ($collection,$counter,$sth,$dbh) = $mysql->id(1)->slave(1)->query('SELECT * FROM `names` WHERE id = ?', 1);

commit, rollback, disconnect

$mysql->db->commit;
$mysql->db->rollback;
$mysql->db->disconnect;

quote

$mysql->util->quote("test'test");

id

$mysql->util->id;

Return id servers in Mojo::Collection object.