Ambrosia

 view release on metacpan or  search on metacpan

Example/MusicS.sql  view on Meta::CPAN

DROP SCHEMA IF EXISTS `MusicDB` ;
CREATE SCHEMA IF NOT EXISTS `MusicDB` DEFAULT CHARACTER SET utf8;
USE `MusicDB` ;

DROP TABLE IF EXISTS `tblArtist`;
CREATE TABLE `tblArtist` (
  `ArtistId` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(64) NOT NULL,
  PRIMARY KEY (`ArtistId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `tblAlbum`;
CREATE TABLE `tblAlbum` (
  `AlbumId` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(64) NOT NULL,
  `Releas` date NOT NULL,
  `RefArtistId` int(11) NOT NULL,
  PRIMARY KEY (`AlbumId`),
  KEY `fk_idx_Album_Artist` (`RefArtistId`),
  CONSTRAINT `fk_idx_Album_Artist` FOREIGN KEY (`RefArtistId`) REFERENCES `tblArtist` (`ArtistId`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Example/README  view on Meta::CPAN

Enter the path for perl's lib [empty for done]: /home/Ambrosia/myperllib/CPAN/perl5lib/lib/perl5/i386-freebsd-64int
Enter the path for perl's lib [empty for done]: /home/Ambrosia/Project/lib
Enter the path for perl's lib [empty for done]:
Enter the path to dojo toolkit:/home/Ambrosia/DOJO/dojo-release-1.7.2
Choose the database [m(MySQL)|p(PostgresQL)]: m
Enter the schema of database [Music]:MusicDB
Enter the host location of database [localhost]:
Enter the port for connection to database or enter 's' for use UNIX socket [3306]:
Enter the username of database [root]:
Enter user's password []:
Enter the charset of database [utf8]:
Enter the settings for connecting to the database as a string [database=MusicDB;host=localhost;port=3306]:

Then follow the instructions.

For access to created application you must use 
    login => 'god',
    password => 'fv,hjpbz'

You can change it in the PATH_TO_PROJECT/Music/Config/Music.conf

Makefile.PL  view on Meta::CPAN

        {
            engine_name   => 'mysql',
            source_name   => 'Client',
            catalog       => undef,
            schema        => '$schema',
            host          => '$host',
            $port
            user          => '$user',
            password      => '$password',
            additional_params => { AutoCommit => 0, RaiseError => 1, LongTruncOk => 1 },
            additional_action => sub { my \$dbh = shift; \$dbh->do('SET NAMES utf8')},
        },
    ]
};
EOB
    close $fh;
}

use ExtUtils::MakeMaker 6.31;

use File::ShareDir::Install;

benchmark/Ambrosia/DataProvider.b  view on Meta::CPAN


my $confDS = {
    DBI => [
        {
            engine_name   => 'mysql',
            source_name   => 'Employee',
            user          => 'root',
            password      => '',
            engine_params => 'database=test;host=localhost;',
            additional_params => { AutoCommit => 0, RaiseError => 1, LongTruncOk => 1 },
            additional_action => sub { my $dbh = shift; $dbh->do('SET NAMES utf8')},
        },
    ]
};

instance Ambrosia::DataProvider(test => $confDS);
Ambrosia::DataProvider::assign 'test';

my $d = storage()->driver('DBI', 'Employee');
my $dbh = $d->handler();

$dbh->do(q~DROP TABLE IF EXISTS `tClient`~);
$dbh->do(<<CREATE_TABLE);
 CREATE TABLE `tClient` (
  `Client_Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `LastName` varchar(32) NOT NULL,
  `FirstName` varchar(32) NOT NULL,
  `MiddleName` varchar(32) NOT NULL,
  `Age` tinyint(4) NOT NULL,
  PRIMARY KEY (`Client_Id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
CREATE_TABLE
$d->save_transaction();

my $NUM_ITER = 1000;

#    my $q = $d->reset()
#                ->source('tClient')
#                ->select()
#                ->what(qw/LastName FirstName MiddleName Age/)
#                ->predicate(['Client_Id', '<=', 30],['Client_Id', '>', $NUM_ITER-10])

benchmark/Ambrosia/EntityDataModel.b  view on Meta::CPAN

            engine_name   => 'mysql',
            source_name   => 'Employee',
            catalog       => undef,#optional
            schema        => 'test',
            host          => 'localhost',#optional
            port          => 3306,#optional
            user          => 'root',
            password      => '',
#            engine_params => 'database=test;host=localhost;',
            additional_params => { AutoCommit => 0, RaiseError => 1, LongTruncOk => 1 },
            additional_action => sub { my $dbh = shift; $dbh->do('SET NAMES utf8')},
        },
    ]
};

instance Ambrosia::DataProvider(test => $confDS);
Ambrosia::DataProvider::assign 'test';

my $d = storage()->driver('DBI', 'Employee');
my $dbh = $d->handler();

$dbh->do(q~DROP TABLE IF EXISTS `tPerson`~);
$dbh->do(<<CREATE_TABLE);
 CREATE TABLE `tPerson` (
  `PersonId` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `LastName` varchar(32) NOT NULL,
  `FirstName` varchar(32) NOT NULL,
  `Age` tinyint(4) NOT NULL,
  PRIMARY KEY (`PersonId`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
CREATE_TABLE

$d->save_transaction();

my $NUM_ITER = 1000;
my $i = 1;
timethese($NUM_ITER, {
    'save' => sub {
            my $p = new PersonEDM(FirstName => 'John'.$i, LastName => 'Smit'.$i, Age => 20+$i);
            $p->save();

benchmark/Ambrosia/QL.b  view on Meta::CPAN


my $confDS = {
    DBI => [
        {
            engine_name   => 'mysql',
            source_name   => 'Client',
            user          => 'root',
            password      => '',
            engine_params => 'database=test;host=localhost;',
            additional_params => { AutoCommit => 0, RaiseError => 1, LongTruncOk => 1 },
            additional_action => sub { my $dbh = shift; $dbh->do('SET NAMES utf8')},
        },
    ]
};

instance Ambrosia::DataProvider(test => $confDS);
Ambrosia::DataProvider::assign 'test';

my $d = storage()->driver('DBI', 'Client');
my $dbh = $d->handler();

$dbh->do(q~DROP TABLE IF EXISTS `tClient`~);
$dbh->do(<<CREATE_TABLE);
 CREATE TABLE `tClient` (
  `ClientId` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `LastName` varchar(32) NOT NULL,
  `FirstName` varchar(32) NOT NULL,
  `MiddleName` varchar(32) NOT NULL,
  `Age` tinyint(4) NOT NULL,
  PRIMARY KEY (`ClientId`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
CREATE_TABLE
$d->save_transaction();

my $NUM_ITER = 100;
my $NUM_ROWS = 5000;

for ( 1 .. $NUM_ROWS )
{
    $d->source('tClient')
        ->insert()

lib/Ambrosia/DataProvider.pm  view on Meta::CPAN

    use Ambrosia::DataProvider;
    my $confDS = {
        DBI => [
            {
                engine_name   => 'DB::mysql',
                source_name  => 'Employee',
                engine_params => 'database=EmployeeDB;host=localhost;',
                user         => 'test',
                password     => 'test',
                additional_params => { AutoCommit => 0, RaiseError => 1, LongTruncOk => 1 },
                additional_action => sub { my $dbh = shift; $dbh->do('SET NAMES utf8')},
            },
            #........
        ],
        IO => [
            {
                engine_name => 'IO::CGI',
                source_name => 'cgi',
                engine_params => {
                    header_params => {
                            '-Pragma' => 'no-cache',

lib/Ambrosia/View/JSON.pm  view on Meta::CPAN

    my $self = shift;

    return $self->as_json;
}

sub as_json
{
    my $self = shift;

    my $json = JSON::XS->new;
    $json->utf8(0);
    $json->latin1(1);

    my $str = '';
    eval
    {
        $json->convert_blessed(1);
        $str = $self->data ? $json->encode($self->data) : '{}';
warn "$str\n";
    };
    if ( $@ )

lib/Ambrosia/core/Object.pm  view on Meta::CPAN

    }
    else
    {
        $ex_node->setAttribute( $p, $v );
    }
    return $ex_node;
}

# Parameters
#    document => 'xml_document', #optional. If not defined then the document will be created.
#    charset => 'charset_of_xml_document', #if not defined document. Optional. Default is 'utf8'
#    name => 'name_of_root_node', #optional. If nod present then the name will be making from '$self'
#    error_ignore => 'true or false in perl notation (1 or 0))', #optional. default is true
#    methods => [], #optional. See 
#

sub as_xml
{
    my $self = shift;
    my %params = @_;

lib/Ambrosia/core/Object.pm  view on Meta::CPAN

Is called with the following params

=over 4

=item document

The xml document. Optional. If not defined, the document will be created.

=item charset

Charset of xml document if it has not been defined. Optional. Default is 'utf8'.

=item name

Name of root node. Optional. If not presented, the class name will be used.

=item error_ignore ($bool)

True or false in perl notation (1 or 0). Optional. Default value is true.
In the case of error and if C<$bool> is true, the error will be ignored.

share/Managers/buildXml.pm  view on Meta::CPAN

    push @$schema_list, $schema;

    my $ds = getDataSource($type, $source_name);

    $schema->{config} = {
        db_engine   => $ds->{engine_name},
        db_source   => $source_name,
        db_params   => $ds->{engine_params},
        db_user     => $ds->{user},
        db_password => $ds->{password},
        db_charset  => (config->data_source_info->{$type}->{$source_name}->{charset} || 'utf8'),
    };

    my $tables = table_info($driver);
    my %hTables = ();

    my %foreign_keys = ();
    foreach ( @{foreign_key_info($driver)} )
    {
        push @{$foreign_keys{$_->{pktable_name}}}, {
            fktable_name => $_->{fktable_name},

share/XSD/AmbrosiaDL.xsd  view on Meta::CPAN

                  <xs:sequence>
                    <xs:element name="Source">
                      <xs:complexType>
                        <xs:attribute name="Name" type="xs:NCName" use="required"/>
                        <xs:attribute name="Engine" type="atns:EngineSource" use="required"/>
                        <xs:attribute name="Catalog" type="xs:NCName" use="optional"/>
                        <xs:attribute name="Schema" type="xs:NCName" use="required"/>
                        <xs:attribute name="User" type="xs:NCName" use="required"/>
                        <xs:attribute name="Password" type="xs:string" use="optional"/>
                        <xs:attribute name="Params" type="xs:string" use="optional"/>
                        <xs:attribute name="Charset" type="xs:string" use="optional" default="utf8"/>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="Name" type="atns:DataSource"/>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <!-- end of DataSource -->

t/Ambrosia/DataProvider.t  view on Meta::CPAN


$dbh->do(q~DROP TABLE IF EXISTS `tClient`~);
$dbh->do(<<CREATE_TABLE);
 CREATE TABLE `tClient` (
  `ClientId` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `LastName` varchar(32) NOT NULL,
  `FirstName` varchar(32) NOT NULL,
  `MiddleName` varchar(32) NOT NULL,
  `Age` tinyint(4) NOT NULL,
  PRIMARY KEY (`ClientId`)
) ENGINE=InnoDB AUTO_INCREMENT=5001 DEFAULT CHARSET=utf8
CREATE_TABLE

ok ($d->save_transaction(), 'save_transaction');

my $NUM_ROWS = 20;
for ( 1 .. $NUM_ROWS )
{
    $d->source('tClient')
        ->insert()
        ->what(qw/LastName FirstName MiddleName Age/)

t/Ambrosia/EntityDataModel.t  view on Meta::CPAN

my $dbh = $d->handler();

$dbh->do(q~DROP TABLE IF EXISTS `tPerson`~);
$dbh->do(<<CREATE_TABLE);
 CREATE TABLE `tPerson` (
  `PersonId` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `LastName` varchar(32) NOT NULL,
  `FirstName` varchar(32) NOT NULL,
  `Age` tinyint(4) NOT NULL,
  PRIMARY KEY (`PersonId`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
CREATE_TABLE

ok ($d->save_transaction(), 'save_transaction');

my $p = t::PersonEDM->new(FirstName => 'John', LastName => 'Smit', Age => 33);
ok($p, 'created');
ok($p->save(), 'saved');
ok($p->PersonId == 1, 'get id');

cmp_deeply($p->as_hash(), t::PersonEDM->load($p->PersonId)->as_hash(), 'load from cache');

t/Ambrosia/QL.t  view on Meta::CPAN


$dbh->do(q~DROP TABLE IF EXISTS `tClient`~);
$dbh->do(<<CREATE_TABLE);
    CREATE TABLE `tClient` (
      `ClientId` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `LastName` varchar(32) NOT NULL,
      `FirstName` varchar(32) NOT NULL,
      `MiddleName` varchar(32) NOT NULL,
      `Age` tinyint(4) NOT NULL,
      PRIMARY KEY (`ClientId`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
CREATE_TABLE
$d->save_transaction();

my $NUM_ROWS = 30;
for ( 1 .. $NUM_ROWS )
{
    $d->source('tClient')
        ->insert()
        ->what(qw/LastName FirstName MiddleName Age/)
        ->execute('LastName'.$_, 'FirstName'.$_, 'MiddleName'.$_, 20+$_);

t/db.params  view on Meta::CPAN

        {
            engine_name   => 'mysql',
            source_name   => 'Client',
            catalog       => undef,
            schema        => 'test',
            host          => 'localhost',
            port          => 3306,
            user          => 'nick',
            password      => '',
            additional_params => { AutoCommit => 0, RaiseError => 1, LongTruncOk => 1 },
            additional_action => sub { my $dbh = shift; $dbh->do('SET NAMES utf8')},
        },
    ]
};



( run in 1.251 second using v1.01-cache-2.11-cpan-49f99fa48dc )