CellBIS::SQL::Abstract::Test - A part of Unit Testing
use CellBIS::SQL::Abstract::Test; # Initialization for SQLite my $test = CellBIS::SQL::Abstract::Test->new(table => 'users'); unless (-d $test->dir) { mkdir $test->dir } $backend = $test->backend; $db = $backend->db; ok $db->ping, 'connected'; # Initialization for MariaDB my $test = CellBIS::SQL::Abstract::Test->new( table => 'users', via => 'mariadb', dsn => 'mariadb://myuser:mypass@localhost:3306/mydbtest' ); $backend = $test->backend; $db = $backend->db; ok $db->ping, 'connected'; # Initialization for PostgreSQL my $test = CellBIS::SQL::Abstract::Test->new( table => 'users', via => 'pg', dsn => 'posgresql://myuser:mypass@localhost:5432/mydbtest' ); $backend = $test->backend; $db = $backend->db; ok $db->ping, 'connected';
This module is only a test instrument in SQLite, Mariadb, and PostgreSQL
CellBIS::SQL::Abstract::Test implements the following attributes.
my $test = CellBIS::SQL::Abstract::Test->new( ... table => 'users', ... ); $test->table('users'); # to defined table $test->table; # to use get table
Information of table form CellBIS::SQL::Abstract::Test::Table
# initialization for mariadb my $test = CellBIS::SQL::Abstract::Test->new( ... via => 'mariadb', dsn => 'mariadb://myuser:mypass@localhost:3306/mydbtest', ... ); # initialization for postgresql my $test = CellBIS::SQL::Abstract::Test->new( ... via => 'pg', dsn => 'posgresql://myuser:mypass@localhost:3306/mydbtest', ... ); # switch to mariadb $test->dsn('mariadb://myuser:mypass@localhost:3306/mydbtest'); # switch to postgresql $test->dsn('posgresql://myuser:mypass@localhost:5432/mydbtest');
dsn attribute must be defined together with via attribute when initializing mariadb or postgresql. However, when initializing using sqlite, you don't need to use the via and dsn (Data Source Name) attributes.
dsn
via
$test->backend; $test->backend(Mojo::SQLite->new); $test->backend(Mojo::mysq->new); $test->backend(Mojo::Pg->new);
backend attribute only for initializing Mojo::SQLite, Mojo::mysql, and Mojo::Pg.
backend
CellBIS::SQL::Abstract::Test implements the following new ones
This method for change dbms from one to the other. For example from sqlite to mariadb or from mariadb to sqlite and vice versa.
# switch to mariadb $test->dsn('mariadb://myuser:mypass@localhost:3306/mydbtest'); $test->change_dbms('mariadb'); # switch to postgresql $test->dsn('postgresql://myuser:mypass@localhost:5432/mydbtest'); $test->change_dbms('pg'); # switch back to sqlite $test->change_dbms('sqlite'); unless (-d $test->dir) { mkdir $test->dir }
The method here is to query tables, such as check, create, empty, and drop tables.
$test->check_table; $test->create_table; $test->create_table_with_fk; $test->empty_table; $test->drop_table; # if use key hashref 'result' $test->check_table->{result}; $test->create_table->{result}; $test->create_table_with_fk->{result}; $test->empty_table->{result}; $test->drop_table->{result}; # if use key hashref 'code' $test->check_table->{code}; $test->create_table->{code}; $test->create_table_with_fk->{code}; $test->empty_table->{code}; $test->drop_table->{code};
The output of this method is a hashref and contains key result and code.
result
code
Achmad Yusri Afandi, yusrideb@cpan.org
yusrideb@cpan.org
Copyright (C) 2021 by Achmad Yusri Afandi
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
To install CellBIS::SQL::Abstract, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CellBIS::SQL::Abstract
CPAN shell
perl -MCPAN -e shell install CellBIS::SQL::Abstract
For more information on module installation, please visit the detailed CPAN module installation guide.