定制 guilhermeabel/matcha-orm 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

guilhermeabel/matcha-orm

Composer 安装命令:

composer require guilhermeabel/matcha-orm

包简介

A lightweight and flexible Object-Relational Mapping (ORM) library for PHP

README 文档

README

PHP

Matcha ORM is a lightweight and flexible Object-Relational Mapping (ORM) library for PHP. It provides an easy-to-use API for working with relational databases, enabling developers to interact with data through an object-oriented approach.

Features ✨

  • ✅ CRUD operations (Create, Read, Update, Delete)
  • 🗺️ Mapping classes to database tables and properties to columns
  • 🔍 Querying and filtering data
  • 📦 Migrations and schema management (coming soon...)
  • 🧑‍🤝‍🧑 Relationships between entities (one-to-one, one-to-many, many-to-many)
  • 🚛 Lazy and eager loading
  • 🔄 Transactions and concurrency control

Installation 📦

You can install Matcha ORM using Composer:

composer require guilhermeabel/matcha-orm

Getting Started 🏁

To get started, you have to define your database connection constants:

<?php

define('DB_NAME', 'matcha');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_DRIVER', 'mysql');
define('DB_HOST', 'localhost');

Next, create a model class that extends the MatchaORM\Model class and maps to a database table:

use MatchaORM\Model;

class User extends Model
{
 protected $fillable = ['name', 'email', 'password'];
}

Make sure to define the $fillable property with the columns that can be mass assigned.

MatchaORM will automatically create a new instance for connection using the database configuration constants defined earlier.

Now you can perform CRUD operations and more with your User model:

// Create a user
$user = new User();
$user->name = 'John Doe';
$user->email = 'johndoe@example.com';
$user->save();

// Update a user
$user = User::find(1);
$user->name = 'John Doe';
$user->email = 'johndoe@example.com' . rand(1, 100);
$user->save();

// Delete a user
$user = User::find(1);
$user->delete();

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-04