PHPackages                             quellabs/canvas-objectquel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. quellabs/canvas-objectquel

ActiveLibrary[Database &amp; ORM](/categories/database)

quellabs/canvas-objectquel
==========================

ObjectQuel integration for the Canvas PHP framework

1.0.27(1mo ago)030MITPHP

Since Jun 13Pushed 1mo agoCompare

[ Source](https://github.com/quellabs/canvas-objectquel)[ Packagist](https://packagist.org/packages/quellabs/canvas-objectquel)[ RSS](/packages/quellabs-canvas-objectquel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (13)Used By (0)

Canvas ObjectQuel Integration
=============================

[](#canvas-objectquel-integration)

[![Canvas ObjectQuel Logo](https://camo.githubusercontent.com/bbdd657e2bd89cf5642f05207da7647872bb04e9f6e4edbaa162220adbf9d872/68747470733a2f2f706c616365686f6c6465722d666f722d6c6f676f2e706e67)](https://camo.githubusercontent.com/bbdd657e2bd89cf5642f05207da7647872bb04e9f6e4edbaa162220adbf9d872/68747470733a2f2f706c616365686f6c6465722d666f722d6c6f676f2e706e67)

[![Latest Version](https://camo.githubusercontent.com/710a34f8d7b1a93b9523488aa741bc3b96a7d82fd535a7b0ce92a3e5f93da68f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7175656c6c6162732f63616e7661732d6f626a6563747175656c2e737667)](https://packagist.org/packages/quellabs/canvas-objectquel)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Downloads](https://camo.githubusercontent.com/9819a90877c09ba0fc3b04d6a0dc55a8c7743b83ffb0bbc24894026b2cd675f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7175656c6c6162732f63616e7661732d6f626a6563747175656c2e737667)](https://packagist.org/packages/quellabs/canvas-objectquel)

The Canvas ObjectQuel Integration package provides seamless integration between [ObjectQuel ORM](https://github.com/quellabs/objectquel) and the Canvas PHP framework. This package includes service discovery for dependency injection and Sculpt CLI commands for entity management.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Features](#features)
- [Configuration](#configuration)
- [Service Discovery](#service-discovery)
- [Sculpt Commands](#sculpt-commands)
- [Quick Start](#quick-start)
- [Configuration Reference](#configuration-reference)
- [Usage Examples](#usage-examples)
- [Support](#support)
- [License](#license)

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require quellabs/canvas-objectquel
```

The package requires:

- PHP 8.2 or higher
- Canvas PHP framework
- ObjectQuel ORM (&gt;=1.0)

Features
--------

[](#features)

### 🔌 **Automatic Service Discovery**

[](#-automatic-service-discovery)

- Automatic registration of ObjectQuel EntityManager with Canvas DI container
- Singleton pattern implementation for optimal performance
- Configuration-driven setup with sensible defaults

### 🛠️ **Sculpt CLI Integration**

[](#️-sculpt-cli-integration)

- Entity generation commands integrated with Canvas Sculpt
- Database migration management
- Entity-from-table generation
- Phinx configuration automation

### ⚙️ **Framework Integration**

[](#️-framework-integration)

- Seamless Canvas framework integration

Configuration
-------------

[](#configuration)

### Database Configuration

[](#database-configuration)

During installation, the package automatically copies `config/database.php` to your Canvas config directory. Edit this file to configure your database connection.

Service Discovery
-----------------

[](#service-discovery)

The package automatically registers ObjectQuel services with Canvas's dependency injection container through two service providers:

### EntityManager Service Provider

[](#entitymanager-service-provider)

Located in `Quellabs\Canvas\ObjectQuel\Discovery\ObjectQuelServiceProvider`, this provider:

- Registers the ObjectQuel EntityManager as a singleton service
- Automatically configures the EntityManager using your database configuration
- Provides dependency injection support for controllers and services

```
// The EntityManager is automatically available in your Canvas application
use Quellabs\Canvas\Controllers\BaseController;
use Quellabs\Canvas\Annotations\Route;

class ProductController extends BaseController {

    /**
     * @Route('/')
     */
    public function index() {
        $products = $this->em()->findBy(ProductEntity::class, [
            'active' => true
        ]);

        return $this->render('products.tpl', compact('products'));
    }
}
```

### Sculpt Service Provider

[](#sculpt-service-provider)

Located in `Quellabs\Canvas\ObjectQuel\Sculpt\ServiceProvider`, this provider registers ObjectQuel CLI commands with the Sculpt framework.

Sculpt Commands
---------------

[](#sculpt-commands)

The package provides several CLI commands for entity and database management:

### Generate Entity

[](#generate-entity)

Create a new entity class interactively:

```
php bin/sculpt make:entity
```

This command will prompt you to:

- Enter the entity name
- Define properties and their types
- Set up relationships
- Generate getters and setters

### Generate Entity from Database Table

[](#generate-entity-from-database-table)

Create an entity from an existing database table:

```
php bin/sculpt make:entity-from-table
```

This command will:

- List available database tables
- Generate an entity class based on the selected table schema
- Include proper annotations and relationships

### Generate Migrations

[](#generate-migrations)

Create database migrations from your entity changes:

```
php bin/sculpt make:migrations
```

This command:

- Analyzes differences between entities and database schema
- Generates Phinx migration files
- Includes index and constraint changes

### Run Migrations

[](#run-migrations)

Execute pending database migrations:

```
php bin/sculpt quel:migrate
```

Additional migration options:

```
# Roll back the last migration
php bin/sculpt quel:migrate --rollback

# Roll back multiple migrations
php bin/sculpt quel:migrate --rollback --steps=3

# Get help with migration commands
php bin/sculpt help quel:migrate
```

### Generate Phinx Configuration

[](#generate-phinx-configuration)

Create a Phinx configuration file for advanced migration management:

```
php bin/sculpt quel:create-phinx-config
```

Quick Start
-----------

[](#quick-start)

### 1. Install and Configure

[](#1-install-and-configure)

```
# Install the package
composer require quellabs/canvas-objectquel

# Configure your database in config/database.php
```

### 2. Create Your First Entity

[](#2-create-your-first-entity)

```
# Generate a new entity
php bin/sculpt make:entity

# Follow the prompts to create a Product entity
```

### 3. Create and Run Migrations

[](#3-create-and-run-migrations)

```
# Generate migrations for your new entity
php bin/sculpt make:migrations

# Apply the migrations to your database
php bin/sculpt quel:migrate
```

### 4. Use in Your Application

[](#4-use-in-your-application)

```
