NAME

Nile::DBI::Table - DBI table class for the Nile framework.

SYNOPSIS

# get table object
my $table = $app->db->table("users");

# or

my $table = $app->db->table;

# set table name
$table->name("users");

# get table name
my $name = $table->name;

$table->delete;
$table->optimize;
$table->empty;
$table->truncate;
my @columns_info = $table->describe;

DESCRIPTION

Nile::DBI::Table - DBI table class for the Nile framework.

This class provides functions for easy managing database tables.

name()

# set table name with constructor
my $table = $app->db->table("users");

# or

# get table object
my $table = $app->db->table;

# then set table name
$table->name("users");

# get table name
my $name = $table->name;

Get and set the table name.

delete() or drop()

my $table = $app->db->table("users");

$table->delete;

# or

$app->db->table("users")->delete;

Drops database table. Method drop() is a shortcut for delete();

rename()

$table->rename("newname");

Rename database table.

optimize()

$table->optimize;

Optimizes database table.

empty()

$table->empty;

Empties a table completely row by row. This method is slow, see truncate() method.

truncate()

$table->truncate;

Empties a table completely and takes care of FOREIGN KEY constraints.

describe()

my @table = $table->describe;
$app->dump(@table);

Provides information about the columns in a table. It is a shortcut for SHOW COLUMNS FROM.

struct()

my $struct = $table->struct;

say "Table name: " . $struct->{"Table"};
say "Table struct: " . $struct->{"Create Table"};

Shows the CREATE TABLE statement that creates the named table. To use this statement, you must have some privilege for the table.

tables()

my @table = $table->tables;

Retuns all the tables in the default database.

backup()

my $file = $app->file->catfile($app->var->get("data_dir"), "table.txt");

# backup data_dir/table.txt
$table->backup($file);

# backup and gzip it to table.gzip
$table->backup($file, compress => "gzip");

# backup to comma-separated values (CSV) format and zip it to table.zip
$table->backup($file, format => "csv", compress => "zip");

Writes tables rows to file. Requires grant file permission.

restore()

my $file = $app->file->catfile($app->var->get("data_dir"), "users.txt");

# restore table 'users' from backup file data_dir/users.txt
$table->restore("users", $file);

# unzip backup file "zip" or "gzip" and restore table from unziped file
my $zipfile = $app->file->catfile($app->var->get("data_dir"), "users.zip");
my $table_file_name = "users.txt";
$table->backup("users", $zipfile, $table_file_name, format =>"csv");

Empties table contents and load data from backup file.

Bugs

This project is available on github at https://github.com/mewsoft/Nile.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Nile.

SOURCE

Source repository is at https://github.com/mewsoft/Nile.

SEE ALSO

See Nile for details about the complete framework.

AUTHOR

Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com

COPYRIGHT AND LICENSE

Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.