maleeshagimshan98/query-builder
Composer 安装命令:
composer require maleeshagimshan98/query-builder
包简介
README 文档
README
A tool to easily generate simple SQL queries. The built-in query builder for my ORM project Infinite-Simple-ORM
About
The QueryBuilder is a PHP class that provides a set of methods for building SQL queries. This class supports building queries for CRUD Operations as well as adding conditions, limits, and offsets to the queries. Additionally, the class supports joining tables and ordering and grouping data.
Installation
To install the package, add the package to composer.json and update.
"require": {
"maleeshagimshan98/query-builder": "1.0.*"
}
run following command :
php composer.phar update
Getting Started
To get started, add this file to your project folder,
use Infinite\SimpleOrm\Query\QueryBuilder;
$builder = new QueryBuilder();
Here are key methods of the class:
from(string $table): Sets the table to select data from.select(array $columns = null): Adds columns to select data from. If no columns are specified, all columns are selected.where(array $condition): Adds a where condition to the query.leftJoin(string $tableName, array $condition): Adds a left join with another table.orderBy(string $column, string $type = "ASC"): Adds an order by clause to the query.limit(string $limit, string $offset): Sets the limit and offset of the result.insert(string $table, array $values): Builds an insert query.update(string $table, array $values, array $condition = []): Builds an update query.delete(string $table, array $condition = []): Builds a delete query.
SELECT
select data from the users table, the following code can be used:
$builder = new QueryBuilder();
$builder->from('users');
$builder->select(['id', 'name', 'email']);
$query = $builder->sql();
SELECT with WHERE (Only uses "=")
Select data with WHERE condition. Compares the array's key and value using "=" operator.
Syntax :
where([...['column_name' => 'value_evaluated']])
$builder->from('users');
$builder->select(['id', 'name', 'email'])->where(['id' => '123','name' => "'abc'"])
$query = $builder->sql(); //... returns the generated sql query
SELECT with WHERE (Use comparison operators)
Select data with WHERE condition, use any comparison operators (=, >, <, etc.)
syntax :
where([.., [..], ['column_name','comparison_operator', 'value_evaluated']])
$builder->from('users');
$builder->select(['id', 'name', 'email'])->where([['id','=','00002'],['name','=',"'aaaa'"]]);
$query = $builder->sql();
LEFT JOIN
Select data and left join another table
$builder->from('users');
$builder->select(['id', 'name', 'email'])->leftJoin('products',[['product.user_id', '=', 'users.id'],['product.type','=','electronic']]);
$query = $builder->sql();
INSERT
To insert data into the users table, the following code can be used:
$builder = new QueryBuilder();
$builder->insert('users', ['name' => 'John Doe', 'email' => 'john.doe@example.com']);
$query = $builder->sql();
This code will generate a SQL query to insert a new row into the users table with the name 'John Doe' and the email 'john.doe@example.com'.
UPDATE
To update data in the users table, the following code can be used:
$builder = new QueryBuilder();
$builder->update('users', ['name' => 'John Doe', 'email' => 'john.doe@example.com']);
$query = $builder->sql();
DELETE
To delete data in the users table, the following code can be used:
$builder = new QueryBuilder();
$builder->delete('users', ['name' => 'John Doe', 'email' => 'john.doe@example.com']);
$query = $builder->sql();
Overall, the QueryBuilder provides a convenient and flexible way to build SQL queries in PHP code.
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request
Licence
Distributed under the MIT License
Contact
- name - Maleesha Gimshan
- email - (maleeshagimshan74@gmail.com)
maleeshagimshan98/query-builder 适用场景与选型建议
maleeshagimshan98/query-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 maleeshagimshan98/query-builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maleeshagimshan98/query-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-11