alaa / magento2-table-query
Magento 2 表格查询
1.0.0
2018-10-02 20:02 UTC
Requires
- php: 7.0.2|7.0.4|~7.0.6|~7.1.0
- magento/framework: 101.0.*
This package is auto-updated.
Last update: 2024-09-09 10:06:39 UTC
README
一个简单的模块,作为对数据库表执行 CRUD 操作的 Magento 连接的包装器
安装
composer require alaa/magento2-table-query
工作原理
使用工厂
public function __construct(\Alaa\TableQuery\Model\QueryInterfaceFactory $queryFactory)
{
$this->queryFactory = $queryFactory;
}
创建查询对象
$query = $this->queryFactory->create(['table' => 'my_table', 'primaryId' => 'primary_id']);
添加新记录
$data = [
[
'name' => 'some name'
'age' => 33,
...
],
[...]
]
$query->put($data);
使用以 fetch 开头的方法检索记录
检索并删除记录
根据条件检索记录
$query->pull('id = 5')
检索第一条记录并删除它
$query->poll()
检索最后一条记录并删除它
$query->pop()
截断表
$query->purge();
更新记录
$query->update(...)
使用迭代器
$it = $query->iterator();
while ($it->valid()) {
$row = $it->current();
// ... do something with row
$it->next();
}
贡献
欢迎提出问题和贡献力量
许可证
MIT