MToken::Store - MToken store class
Version 1.00
use MToken::Store; my $store = MToken::Store->new( file => "/tmp/test.db", attributes => "RaiseError=0; PrintError=0; sqlite_unicode=1", do_init => 1, # Need to try initialize the db ); my $store = MToken::Store->new( dsn => "DBI:mysql:database=MToken;host=mysql.example.com", user => "username", password => "password", set => [ "RaiseError 0", "PrintError 0", "mysql_enable_utf8 1", ], ); die($store->error) unless $store->status;
This module provides store methods.
CREATE TABLE "mtoken" ( "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, "file" CHAR(256) NOT NULL UNIQUE, "size" INTEGER NOT NULL, "mtime" INTEGER NOT NULL, "checksum" CHAR(64) DEFAULT NULL, "tags" CHAR(256) DEFAULT NULL, "subject" CHAR(1024) DEFAULT NULL, "content" TEXT DEFAULT NULL );
CREATE DATABASE `mtoken` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; CREATE TABLE IF NOT EXISTS `mtoken` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `file` VARCHAR(256) COLLATE utf8_bin NOT NULL, -- File name `size` INT(11) NOT NULL, -- File size `mtime` INT(11) NOT NULL, -- Unixtime value of modified time (mtime) `checksum` VARCHAR(64) NOT NULL, -- Checksum (MD5/SHA1/SHA256) `tags` VARCHAR(256) DEFAULT NULL, -- Tags `subject` VARCHAR(1024) DEFAULT NULL, -- Subject `content` TEXT COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `file` (`file`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE IF NOT EXISTS `mtoken` ( `id` INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, `file` CHAR(256) COLLATE utf8_bin NOT NULL UNIQUE, `size` INTEGER NOT NULL, `mtime` INTEGER NOT NULL, `checksum` CHAR(64) DEFAULT NULL, `tags` CHAR(256) DEFAULT NULL, `subject` CHAR(1024) DEFAULT NULL, `content` TEXT COLLATE utf8_bin DEFAULT NULL );
my $store = MToken::Store->new( file => "/tmp/test.db", attributes => "RaiseError=0; PrintError=0; sqlite_unicode=1", do_init => 1, # Need to try initialize the db ); # ... or MySQL: my $store = MToken::Store->new( dsn => "DBI:mysql:database=mtoken;host=mysql.example.com", user => "username", password => "password", set => [ "RaiseError 0", "PrintError 0", "mysql_enable_utf8 1", ], );
Creates DBI object
$store->add( file => "test.txt", size => 1024, mtime => 1590000000, checksum => "1a6f4a41ae8eec2da84dbfa48636e02e33575dbd", tags => "test, example", subject => "Test file for example", content => "...Content of the file...", ) or die($store->error);
Add new recored
print $store->count();
Returns count of records
$store->del("test.txt") or die($store->error);
Delete record by filename
$store->del(1) or die($store->error);
Delete record by record id
my $dsn = $store->dsn;
Returns DSN string of current database connection
my $error = $store->error;
Returns error message
my $status = $store->error( "Error message" );
Sets error message if argument is provided. This method in "set" context returns status of the operation as status() method.
my $file = $store->file;
Returns the file of SQLite database
my %data = $store->get("test.txt");
Returns data from database by filename
my %data = $store->get(1);
Returns data from database by record id
my @table = $store->getall(); my @table_100 = $store->getall(100); # row_count my @table_100 = $store->getall(100, 100); # offset, row_count
Returns data from database with limit supporting
print $store->is_sqlite ? "Is SQLite" : "Is NOT SQLite"
Returns true if type of current database is SQLite
$store->ping ? 'OK' : 'Database session is expired';
Checks the connection to database
$store->set( file => "test.txt", size => 1024, mtime => 1590000000, checksum => "1a6f4a41ae8eec2da84dbfa48636e02e33575dbd", tags => "test, example", subject => "Test file for example", content => "...New content of the file...", ) or die($store->error);
Update recored by document number
$store->set( id => 1, file => "test.txt", size => 1024, mtime => 1590000000, checksum => "1a6f4a41ae8eec2da84dbfa48636e02e33575dbd", tags => "test, example", subject => "Test file for example", content => "...New content of the file...", ) or die($store->error);
Update recored by record id
my $status = $store->status; my $status = $store->status( 1 ); # Sets the status value and returns it
Get/set BOOL status of the operation
$store->truncate or die($store->error);
Delete all records
See Changes file
Changes
See TODO file
TODO
* none noted
CTK::DBI, MToken
Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>
Copyright (C) 1998-2021 D&D Corporation. All Rights Reserved
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/
LICENSE
To install MToken, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MToken
CPAN shell
perl -MCPAN -e shell install MToken
For more information on module installation, please visit the detailed CPAN module installation guide.