jarjak/dbal-manager
Composer 安装命令:
composer require jarjak/dbal-manager
包简介
Doctrine DBAL helper for bulk data imports in MySQL and other stuff.
README 文档
README
Set of helper classes for Doctrine DBAL. It has been made maily to ease creating bulk imports. It provides a method to execute INSERT ... ON DUPLICATE KEY UPDATE query on MySQL-compatible databases, which is what I miss in Doctrine's MySQL driver.
Symfony installation
To use this class in Symfony 2/3, please look at DBALManagerBundle.
In Symfony 4, thanks to autowiring you are not forced to use a bundle, just add these lines in your services.yaml:
services: _defaults: autowire: true JarJak\DBALManager: ~
Integration with other frameworks
Run:
composer require jarjak/dbal-manager
The class is PSR-0/PSR-4 compatible, so it can be integrated easily with any modern framework. Here is an example for Silex:
//Application.php $app['dbal_manager'] = $app->share(function ($app) { $manager = new JarJak\DBALManager($app['db']); return $manager; });
Simple example:
You want to insert data or update them if row already exists.
$sqlArray = [ 'id' => 1, 'username' => 'JohnKennedy', 'email' => 'john@kennedy.gov' ]; /* @var $manager JarJak\DBALManager */ $manager->insertOrUpdate('user', $sqlArray);
Or you want to just skip this row if it exists:
$manager->insertIgnore('user', $sqlArray);
Advanced example:
Lets say we have user table with:
- unique usernames and emails
- column active can contain only 0 or 1 (not nullable)
- column address can be null
$sqlArray = [ 'username' => 'JohnKennedy', 'email' => 'john@kennedy.gov', 'password' => $password, 'address' => '', 'active' => 0, ]; /* @var $manager JarJak\DBALManager */ $manager->insertOrUpdate('user', $sqlArray, 2, ['active']);
Dumping Queries
DBALManager can use VarDumper to dump SQL queries from QueryBuilder ready to be copypasted into database server (with parameters already included).
/* @var QueryBuilder $queryBuilder */ \JarJak\SqlDumper::dumpQuery($queryBuilder);
If you don't use QueryBuilder you can still dump parametrized SQL with:
\JarJak\SqlDumper::dumpSql($sql, $params);
Testing
Run tests with:
composer run-script test
Fix code style with:
composer run-script csfix
jarjak/dbal-manager 适用场景与选型建议
jarjak/dbal-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 112.62k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「persistence」 「dbal」 「queryobject」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jarjak/dbal-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jarjak/dbal-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jarjak/dbal-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
This bundle provides tools to build persistence-agnostic storage layer.
Propel2 is an open-source Object-Relational Mapping (ORM) for PHP 5.5 and up.
Kinikit - PHP Application development framework MVC component
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
统计信息
- 总下载量: 112.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-15