quickhelper/quickorm

ORM to manipulate databases through code without needing to write SQL queries.

v2.0.0 2025-04-04 01:36 UTC

This package is auto-updated.

Last update: 2025-04-04 01:41:16 UTC


README

This repository contains a project that leverages ORM (Object-Relational Mapping) technology to manage and interact with databases in a convenient and efficient manner. The project demonstrates how to use ORM to manipulate databases through code without needing to write SQL queries directly.

Features

  • Simple API: Easily manipulate databases using objects and classes.
  • Full CRUD Support: Insert, read, update, and delete data effortlessly.
  • Dynamic Queries: Build SQL queries dynamically with QueryBuilder.
  • Relationship Management: Handle relationships between tables, including one-to-one, one-to-many, and many-to-many.
  • Database Compatibility: Works with most relational databases supported by PDO.

Installation

To install quickhelper/quickorm via Composer, run the following command in your project directory:

composer require quickhelper/quickorm

Basic Usage

Setting up a Database Connection

Configure the database connection settings in your configuration in config/database.php ;

Creating a Model

Create a model that represents a table in your database:

use QuickORM\Model;

class User extends Model
{
    protected $table = 'users';
}

CRUD Operations

  • Insert a New Record:
$user = new User();
$user->name = 'John Doe';
$user->email = 'john@example.com';
$user->save();
  • Read a Record:
$user = User::find(1);
echo $user->name;
  • Update a Record:
$user = User::find(1);
$user->name = 'Jane Doe';
$user->save();
  • Delete a Record:
$user = User::find(1);
$user->delete();

Custom Queries

Use QueryBuilder to create custom SQL queries:

use QuickORM\QueryBuilder;

$results = QueryBuilder::table('users')
    ->where('age', '>', 30)
    ->get();

Relationship Management

Define relationships between models:

class Post extends Model
{
    protected $table = 'posts';

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}

class User extends Model
{
    protected $table = 'users';

    public function posts()
    {
        return $this->hasMany(Post::class);
    }
}

Contents

  • Introduction to ORM
  • Practical Examples
    • Creating objects and storing them in the database
    • Retrieving data from the database
    • Updating existing data
    • Deleting data
  • Best Practices

Project Advantages

  • Provides a convenient way to interact with databases.
  • Facilitates the process of managing software data.
  • Reduces errors caused by manual SQL queries.
  • Improves the efficiency and performance of applications.

How to Use

  1. Clone the Repository:

    git clone https://github.com/yossef-ashraf/QuickORM.git
  2. Environment Setup: Prepare your programming environment and install all required dependencies.

  3. Running Examples: Execute the examples included in the project to understand how to use the ORM.

Contribution

We welcome contributions to enhance this project. If you would like to participate, please:

  • Open an Issue for any questions or feedback.
  • Submit a Pull Request with your improvements.

License

This project is licensed under the MIT License.

Best regards,
Yossef Ashraf