NAME

WWW::Suffit::Model - This library provides methods for access to WWW::Suffit models

SYNOPSIS

use WWW::Suffit::Model;

my $model = WWW::Suffit::Model->new(
    ds => "sqlite:///tmp/test.db?sqlite_unicode=1"
);

$model = $model->connect_cached->init;

DESCRIPTION

A lightweight and extensible model layer that streamlines database interaction within the WWW::Suffit framework, providing a clean foundation for building consistent, reusable data models

METHODS

This class inherits all methods from Acrux::DBI and implements the following new ones

init

$model = $model->connect->init($package, $schema, $prefix);
$model = $model->connect->init(__PACKAGE__, 'public', 'schema');
$model = $model->connect_cached->init;

This method initializes the database schema prior to using the connection.

$package

Specifies the package that holds the __DATA__ section containing the DDL blocks

Default: your package name of the class inheriting from this one, __PACKAGE__

$schema

Specifies schema name. Default: 'public'

$prefix

Specifies preffix of the DDL section name. Default: 'schema'

For eg., if you specify "test" as the prefix, you will need to declare your DDL blocks in your class as follows:

__DATA__

@@ test_sqlite

... your DDL for sqlite here ...

@@ test_mysql

... your DDL for mysql here ...

@@ test_postgresql

... your DDL for postgresql here ...

is_mariadb

print $model->is_mariadb ? "Is MariaDB" : "Is NOT MariaDB";

Returns true if type of current database is MariaDB

is_mysql

print $model->is_mysql ? "Is MySQL" : "Is NOT MySQL";

Returns true if type of current database is MySQL

is_oracle

print $model->is_oracle ? "Is Oracle" : "Is NOT Oracle";

Returns true if type of current database is Oracle

is_postgresql

print $model->is_postgresql ? "Is PostgreSQL" : "Is NOT PostgreSQL";

Returns true if type of current database is PostgreSQL

is_sqlite

print $model->is_sqlite ? "Is SQLite" : "Is NOT SQLite";

Returns true if type of current database is SQLite

is_initialized

print $model->is_initialized ? "Initialized" : "Is NOT initialized";

This method returns the initialization status of the model. It returns true if the model is initialized, and false otherwise.

initiator

print $model->initiator; # MyModel

This method returns the name of the class that called the init method

schema

print $model->schema; # public

This method returns the schema name

EXAMPLE

Add the following block describing the schemas to the end of your class in the "__DATA__" section:

@@ schema_sqlite

-- # main
CREATE TABLE IF NOT EXISTS "test" (
  "id"          INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
  "comment"     TEXT DEFAULT NULL -- Comment
);

@@ schema_mysql

-- # main
CREATE DATABASE IF NOT EXISTS `test-db` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
USE `test-db`;
CREATE TABLE IF NOT EXISTS `test` (
  `id`          INT NOT NULL AUTO_INCREMENT,
  `comment`     LONGTEXT DEFAULT NULL, -- Comment
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

@@ schema_postgresql

-- # main
CREATE TABLE IF NOT EXISTS "test" (
  "id"          INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  "comment"     TEXT DEFAULT NULL -- Comment
);

See also eg/MyModel.pm for an example of how to use this class correctly

HISTORY

See Changes file

TO DO

See TODO file

SEE ALSO

Acrux::DBI, WWW::Suffit, eg/MyModel.pm

AUTHOR

Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2025 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/