Jifty:...nerator(3pm)

πŸ“¦
version 0.78 Β· 2 versions
  • 0.78 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.78 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Jifty::DBI::SchemaGenerator β€” the perl module, bestie πŸ’…

okay so this is the manual page for Jifty::DBI::SchemaGenerator (that's the Jifty:...nerator(3pm) one, from the User Contributed Perl Documentation section, iykyk) πŸŽ€


🌸 NAME 🌸

Jifty::DBI::SchemaGenerator β€” it generates a table schema from Jifty::DBI records. literally that's the whole job. slay. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe: this module takes a Jifty::Record object and turns it into an SQL schema for whichever database you picked. And rn your choices are MySQL, SQLite, or PostgreSQL. Oracle might also work right?? but it's untested, so like… no promises, bestie πŸ™ˆ


πŸ’– SYNOPSIS πŸ’–

✨ The Short Answer ✨

Scroll down for where we're getting the $handle and $model variables from, okay? πŸ‘€

use Jifty::DBI::SchemaGenerator;
...
my $s_gen = Jifty::DBI::SchemaGenerator->new( $handle );
$s_gen->add_model($model);

my @statements = $s_gen->create_table_sql_statements;
print join("\n", @statements, '');
...

🌈 The Long Version 🌈

For the first two parts, go look at Jifty::DBI for the details. πŸ‘‘

MyModel

package MyModel;
# lib/MyModel.pm

use warnings;
use strict;

use base qw(Jifty::DBI::Record);
# your custom code goes here.
1;

MyModel::Schema

package MyModel::Schema;
# lib/MyModel/Schema.pm

use warnings;
use strict;

use Jifty::DBI::Schema;

column foo => type is 'text';
column bar => type is 'text';

1;

myscript.pl

#!/usr/bin/env perl
# myscript.pl

use strict;
use warnings;

use Jifty::DBI::SchemaGenerator;

use Jifty::DBI::Handle;
use MyModel;
use MyModel::Schema;

my $handle = Jifty::DBI::Handle->new();
$handle->connect(
  driver   => 'SQLite',
  database => 'testdb',
);

my $model = MyModel->new($handle);
my $s_gen = Jifty::DBI::SchemaGenerator->new( $handle );
$s_gen->add_model($model);

# here's the basic point of this module:
my @statements = $s_gen->create_table_sql_statements;
print join("\n", @statements, '');

# this part is directly from Jifty::Script::Schema::create_all_tables()
$handle->begin_transaction;
for my $statement (@statements) {
  my $ret = $handle->simple_query($statement);
  $ret or die "error creating a table: " . $ret->error_message;
}
$handle->commit;

πŸŽ€ CONFIGURATION AND ENVIRONMENT πŸŽ€

Requires no configuration files or environment variables. like, zero. she's low maintenance fr fr πŸ’…


🧚 DEPENDENCIES 🧚

  • Class::Accessor::Fast
  • DBIx::DBSchema
  • Class::ReturnValue

πŸ‘‘ METHODS πŸ‘‘

πŸ’œ new HANDLE

Creates a new Jifty::DBI::SchemaGenerator object. The one single required argument is a Jifty::DBI::Handle. that's it, that's the whole thing ✨

πŸ’œ add_model MODEL

Adds a new model class to the SchemaGenerator. Model should be an object that's an instance of Jifty::DBI::Record or a subclass of it. It can also be a string that's the name of such a class/subclass β€” and in that case, add_model will go ahead and instantiate an object of that class for you. so helpful 🫢

The model must define the instance methods schema and table.

Returns true if the model got added successfully; otherwise it returns a false Class::ReturnValue error. 😭

πŸ’œ column_definition_sql TABLENAME COLUMNNAME

Give it a table name and a column name, and it returns the SQL fragment describing that column for the current database. cute and specific πŸ’…

πŸ’œ create_table_sql_statements

Returns a list of SQL statements (as strings) that create tables for all the models you added to the SchemaGenerator. periodt.

πŸ’œ create_table_sql_text

Returns a single string containing a sequence of SQL statements to create tables for all the models added to the SchemaGenerator.

This is literally just a trivial wrapper around create_table_sql_statements. that's it. she's a thin layer. 🌸

πŸ’œ PRIVATE _db_schema_table_from_model MODEL

Takes an object of a subclass of Jifty::DBI::Record; returns a brand new DBIx::DBSchema::Table object corresponding to the model. πŸ¦‹

πŸ’œ PRIVATE _error STRING

Takes in a string and hands it back to you as a Class::ReturnValue error object. πŸ’€


πŸ™ˆ INCOMPATIBILITIES πŸ™ˆ

None reported. (iconic behaviour, honestly)


πŸ’€ BUGS AND LIMITATIONS πŸ’€

No bugs have been reported.

Please report any bugs or feature requests to bug-<RT NAME>@rt.cpan.org, or through the web interface at <http://rt.cpan.org>. do it, bestie, they wanna hear from you 🫢


⭐ AUTHOR ⭐

David Glasser "glasser@bestpractical.com"

Some pod by Eric Wilhelm <ewilhelm at cpan dot org>


Copyright (c) 2005, Best Practical Solutions, LLC. All rights reserved.

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


πŸ”₯ DISCLAIMER OF WARRANTY πŸ”₯

okay bestie this part is in ALL CAPS in the original and I'm keeping every word because it's legally important, so read it, don't skim it πŸ’…

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


and that's the whole page, bestie!! πŸ’œ this one's from perl v5.34.0, dated 2022-06-15 β€” yeah she's a vintage queen and she still ate πŸ‘‘βœ¨ mwah, go build some tables πŸŽ€

πŸ“¦ where this page comes from