or81/eloquent
Composer 安装命令:
composer require or81/eloquent
包简介
A lightweight and versatile PHP database class that supports both MySQL and SQLite, providing an easy-to-use interface for common database operations such as `SELECT`, `INSERT`, `UPDATE`, and `DELETE`.
README 文档
README
A lightweight and versatile PHP database class that supports both MySQL and SQLite, providing an easy-to-use interface for common database operations such as SELECT, INSERT, UPDATE, and DELETE.
Features
- Multiple Database Support: Easily switch between MySQL and SQLite by changing the configuration.
- Automatic Table Naming: Automatically determines the table name based on the class name, with an option to override it.
- Flexible Query Builder: Chain methods for
WHERE,JOIN,ORDER BY,LIMIT, and more. - CRUD Operations: Simplified methods for creating, reading, updating, and deleting records.
- Aggregation Functions: Includes
MIN,MAX, andCOUNTfunctions for efficient data retrieval. - File Creation for SQLite: Automatically creates the SQLite database file if it doesn't exist.
Installation
-
Clone this repository to your project:
git clone https://github.com/OR81/eloquent.git
-
Include the
DBclass in your project:require_once 'path/to/DB.php';
-
Configure the class for your database:
- MySQL (default):
$db = new \Config\DB();
- SQLite:
$db = new \Config\DB(); $db->driver = 'sqlite'; $db->sqlitePath = 'path/to/your/database.sqlite';
- MySQL (default):
Usage
Selecting Data
-
Basic Select:
$results = $db->table('users')->select('*')->get();
-
With Where Clause:
$results = $db->table('users')->where('age', '>', 25)->get();
-
With Join:
$results = $db->table('users') ->join('posts', 'users.id', 'posts.user_id') ->select('users.name, posts.title') ->get();
-
Aggregation:
$maxAge = $db->table('users')->max('age');
Inserting Data
-
Single Insert:
$user = $db->table('users')->insert([ 'name' => 'John Doe', 'email' => 'john@example.com' ]);
-
Multiple Inserts:
$db->table('users')->insertMultiple([ ['name' => 'Alice', 'email' => 'alice@example.com'], ['name' => 'Bob', 'email' => 'bob@example.com'] ]);
Updating Data
- Update Record:
$db->table('users') ->where('id', 1) ->update(['name' => 'John Smith']);
Deleting Data
- Delete Record:
$db->table('users')->where('id', 1)->delete();
Counting Records
- Count All Records:
$userCount = $db->table('users')->count();
Configuration
The DB class can be configured by modifying the following properties:
-
MySQL Configuration:
$driver = 'mysql';(default)$host = 'localhost';$dbName = 'your_database';$username = 'your_username';$password = 'your_password';
-
SQLite Configuration:
$driver = 'sqlite';$sqlitePath = 'path/to/your/database.sqlite';
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue on GitHub.
Contact
For any inquiries or support, please reach out to omidrajabi81@gmail.com.
or81/eloquent 适用场景与选型建议
or81/eloquent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 or81/eloquent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 or81/eloquent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-08-14