The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

FusqlFS::Artifact - basic abstract class to represent database artifact in FusqlFS

SYNOPSIS

    package FusqlFS::Backend::PgSQL::Tables;
    use parent 'FusqlFS::Artifact';

    sub new
    {
        my $class = shift;
        my $self = {};

        // initialize Tables specific resources

        bless $self, $class;
    }

    sub get
    {
        my $self = shift;
        my ($table, $name) = @_;
        return $self->one_row("SELECT * FROM %s WHERE id = ?", [$table], $name);
    }

    sub list
    {
        my $self = shift;
        my ($table) = @_;
        return $self->all_col("SELECT id FROM %s %s", [$table, $self->limit]);
    }

DESCRIPTION

This abstract class declares interface between database artifacts (like tables, data rows, functions, roles etc.) and Fuse hooks in FusqlFS.

The point of this class is to abstract database layer interaction from file system structure operations, so it provides some basic operations under database artifacts like "get", "list", "create", "drop", etc.

For example FusqlFS::Backend::PgSQL::Tables subclass defines it's get method to return table's description and list method to list all available tables, so this subclass is represented as directory with tables in file system.

For more examples see childrens of this class.

METHODS

Basic interface methods
new

Fallback constructor, shouldn't be called at all.

Input: $class Output: $artifact_instance.

get

Get item from this artifact.

Input: @names. Output: $hashref|$arrayref|$scalarref|$coderef|$scalar|undef.

Hashrefs and arrayref are represented as directories in filesystem with keys (or indices in case of arrayref) as filenames and values as their content (maybe hashrefs or arrayrefs as well).

Scalarrefs are represented as symlinks, their content being the path to referenced object in filesystem.

Coderefs provide "pseudopipes" interface: at first request referenced sub is called without parameters for initialization and file content will be whatever the sub returns. On any write to the "pseudopipe" the sub is called with written data as first argument and the content of the file will be any text the sub returns back. Dynamic DB queries in FusqlFS::Backend::PgSQL::Queries class are implemented with this interface.

Scalars are represented with plain files.

If this sub returns undef the file with given name is considered non-existant, and user will get NOENT error.

list

Get list of items, represented by class.

Input: @names. Output: $arrayref|undef.

If this method returns arrayref of scalars, then the class is represented with directory containing elements with names from this array, otherwise (the method returns undef) the type of filesystem object is determined solely on "get" method call results.

rename

Renames given database artifact.

Input: @names, $newname. Output: $success.

This method must rename database object defined with @names to new $newname and return any "true" value on success or undef on failure.

drop

Removes given database artifact.

Input: @names. Output: $success.

This method must drop given database object defined with @names and return any "true" value on success or undef on failure.

create

Creates brand new database artifact.

Input: @names. Output: $success.

This method must create new database object by given @name and return any "true" value on success or undef on failure. If given object can't be created without additional "content" data (e.g. table's index) it should create some kind of stub in memory/cache/anywhere and this stub must be visible via "get" and "list" methods giving the user a chance to fill it with some real data, so successive "store" call can create the object.

store

Stores any changes to object in database.

Input: @names, $data. Output: $success.

This method must accept the same $data structure as provided by "get" method, possibly modified by user, and store it into database, maybe creating actual database object in process (see "create" for details). The method must return any "true" value on success or undef on failure.