guilhermeabel/matcha-orm
Composer 安装命令:
composer require guilhermeabel/matcha-orm
包简介
A lightweight and flexible Object-Relational Mapping (ORM) library for PHP
关键字:
README 文档
README
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
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-04