Componette

Componette

wakerscz

wakerscz / nette-propel2 0.9.4

๐Ÿ‘๏ธ Propel 2 ORM integration (extension) for Nette 2.4 with Tracy debugger panel. Supports all configuration features from Propel.

download-cloud-line composer require wakers/nette-propel2

Propel 2 ORM in Nette 2.4

Propel 2 ORM integration for Nette 2.4 with Tracy debugger panel.

Tracy Debugger

Installation

  1. Install this nette-extensions via composer require wakers/nette-propel2:v0.9

  2. Register this extensions in your application config.neon

    extensions:
        wakers-propel: Wakers\Propel\DI\PropelExtension
  3. Add propel configuration file in ./app/config/db.local.neon

    wakers-propel:
        propel:
    
            general:
                project: Wakers CMS 5
                version: 5
    
            database:
                connections:
                    wakers_cms:
                        adapter: mysql
                        classname: Propel\Runtime\Connection\ProfilerConnectionWrapper
                        dsn: 'mysql:host=mariadb;dbname=wakers_cms_db'
                        user: root
                        password: root
                        attributes:
                        settings:
                            charset: utf8
    
            runtime:
                defaultConnection: wakers_cms
                connections:
                    - wakers_cms
    
            generator:
                defaultConnection: wakers_cms
                connections:
                    - wakers_cms
                tablePrefix: wakers_
                dateTime:
                    dateTimeClass: \Nette\Utils\DateTime
    
            paths:
                schemaDir: './app/schema'
                outputDir: './app/schema'
                phpDir: './app/schema/model'
                migrationDir: './app/schema/migration'
                sqlDir: './app/schema/sql'
    
            reverse:
                connection: wakers_cms
    
            migrations:
                tableName: 1_propel_migration

Example

Create schema

<database name="wakers_cms" namespace="Wakers\Module" defaultIdMethod="native"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd"
>

    <table name="book" namespace="MyModule\DB" package="./book/">
        <column name="id" type="INTEGER" required="TRUE" primaryKey="TRUE" autoIncrement="TRUE"/>
        <column name="name" type="VARCHAR" required="TRUE" size="64"/>
    
        <unique>
            <unique-column name="name"/>
        </unique>
    </table>
    
</database>

Use commands

Commands are same as official but without aliases.

# Compare DB with schema (eventually create migration)
./vendor/bin/wpropel migration:diff

# Run migration
./vendor/bin/wpropel migration:migrate

# Create model classes
./vendor/bin/wpropel model:build

# Show all allowed commands
./vendor/bin/wpropel

Create PHP code

$con = Propel\Runtime\Propel::getConnection();

$con->beginTransaction();

try
{
    $book = new Wakers\Module\MyModule\Book;
    $book->setName('Any book name');
    $book->save();
    
    // Do something else
    
    $con->commit();
}
catch (Propel\Runtime\Exception\PropelException $exception)
{
    $con->rollBack();
}


$books = Wakers\Module\MyModule\BookQuery::create()->find();

foreach ($books as $book)
{
    bdump($book->getName());
}

About Propel 2

Please think about using Propel 2 before you start, because actually Propel 2 is not maintained.

If you still want to use Propel2 in Nette, this extension is the right way.

We're welcome pull requests and issues.

  • 0.9.4 Fixed image size in tracy panel

    • Fixed image size in tracy panel
  • v0.9.3 Fixed .env support

    • Fixed .env loading in scam config
  • v0.9.2 Added env support

    What new?

    • Added support for environment variables in neon
  • v0.9.1 Created Propel2 extension for Nette 2.4

Componette Componette felix@nette.org