didslm/sql-builder
最新稳定版本:v1.1.1
Composer 安装命令:
composer require didslm/sql-builder
包简介
A flexible PHP package to build SQL queries using the builder pattern.
README 文档
README
SQL Query Builder is a PHP package designed to help developers construct SQL queries, from the simplest to the most complex, using the builder pattern.
Features
- Simple and intuitive API.
- Supports various SQL operations including
SELECT,INSERT,UPDATE, andDELETE. - Extendable architecture allows for adding more custom query types.
- Strongly typed components like
Where,Join, andOrderByprovide better IDE support and reduce runtime errors.
Installation
Using Composer:
composer require didslm/sql-builder
Usage
Simple SELECT query
<?php require 'vendor/autoload.php'; use Didslm\QueryBuilder\SelectQueryBuilder; $query = SelectQueryBuilder::from('users') ->select('*') ->where('age', 18) ->build(); echo $query; // Outputs: SELECT * FROM users WHERE age = 18
Complex Query
$query = SelectQueryBuilder::from('users') ->select('*') ->join('posts', 'users.id', 'posts.user_id') ->where('users.age', 18, '>') ->where('posts.published', true) ->build(); echo $query; // Outputs: SELECT * FROM users JOIN posts ON users.id = posts.user_id WHERE users.age > 18 AND posts.published = true
Grouped conditions
$sql = SelectBuilder::from('users') ->where('name', 'John') ->and('age', 18) ->and('email', 'selimi') ->or('name', 'test') ->and('email', 'selimi') ->build(); echo $sql; // Outputs: SELECT * FROM users WHERE (name = 'John' AND age = 18 AND email = 'selimi') OR (name = 'test' AND email = 'selimi')
Testing
After cloning the repository and installing the dependencies, you can run the tests with:
vendor/bin/phpunit
Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.
Please make sure to update the tests as appropriate.
License
统计信息
- 总下载量: 88
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-30