NAME
Acrux::DBI::Dump - Working with SQL dumps
SYNOPSIS
use Acrux::DBI::Dump;
my $dump = Acrux::DBI::Dump->new(
dbi => $dbi
);
$dump->from_file('/tmp/test.sql')->poke;
DESCRIPTION
This class is used by Acrux::DBI to allow database schemas import. A dump file is just a collection of sql blocks, with one or more statements, separated by comments of the form -- #NAME
or -- # NAME
-- #foo
CREATE TABLE `pets` (`pet` TEXT);
INSERT INTO `pets` VALUES ('cat');
INSERT INTO `pets` VALUES ('dog');
delimiter //
CREATE PROCEDURE `test`()
BEGIN
SELECT `pet` FROM `pets`;
END
//
-- #bar
DROP TABLE `pets`;
DROP PROCEDURE `test`;
-- #baz (...you can comment freely here...)
-- ...and here...
CREATE TABLE `stuff` (`whatever` INT);
-- #main
DROP TABLE `stuff`;
This idea is to let you import SQL dumps step by step by its names
ATTRIBUTES
This class implements the following attributes
dbi
$dump = $dump->dbi($dbi);
my $dbi = $dump->dbi;
The object these processing belong to
name
my $name = $dump->name;
$dump = $dump->name('foo');
Name for this dump, defaults to schema
METHODS
This class implements all methods from Mojo::Base and implements the following new ones
from_data
$dump = $dump->from_data;
$dump = $dump->from_data('main');
$dump = $dump->from_data('main', 'file_name');
Extract dump data from a file in the DATA section of a class with "data_section" in Mojo::Loader, defaults to using the caller class and "name".
__DATA__
@@ schema
-- # up
CREATE TABLE `pets` (`pet` TEXT);
INSERT INTO `pets` VALUES ('cat');
INSERT INTO `pets` VALUES ('dog');
-- # down
DROP TABLE `pets`
from_file
$dump = $dump->from_file('/tmp/schema.sql');
Read dump data from a file
from_string
$dump = $dump->from_string('
-- # up
CREATE TABLE `pets` (`pet` TEXT);
-- # down
DROP TABLE `pets`
');
Read dump data from string
peek
my $sqls = $dump->peek; # 'main'
my $sqls = $dump->peek('foo');
my @sqls = $dump->peek('foo');
This method returns an array/arrayref of SQL statements stored at a specified dump location by tag-name. By default will be used the main
tag
poke
$dump = $dump->poke; # 'main'
$dump = $dump->poke('foo');
Import named data-block of SQL dump to database by tag-name. By default will be used the main
tag
HISTORY
See Changes
file
TO DO
See TODO
file
SEE ALSO
Acrux::DBI, Mojo::mysql, Mojo::Pg
AUTHOR
Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>
COPYRIGHT
Copyright (C) 1998-2024 D&D Corporation. All Rights Reserved
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See LICENSE
file and https://dev.perl.org/licenses/