bmorais/database
最新稳定版本:v3.0.4
Composer 安装命令:
composer require bmorais/database
包简介
The data layer is a persistent abstraction component of your database that PDO
README 文档
README
The database is a persistent abstraction component of your database that PDO has prepared instructions for performing common routines such as registering, reading, editing, and removing data.
O database é um componente para abstração de persistência no seu banco de dados que usa PDO com prepared statements para executar rotinas comuns como cadastrar, ler, editar e remover dados.
About BMorais Code
BMorais Code is a set of small and optimized PHP components for common tasks. Held by Bruno Morais. With them you perform routine tasks with fewer lines, writing less and doing much more.
BMorais Code é um conjunto de pequenos e otimizados componentes PHP para tarefas comuns. Mantido por Bruno Morais. Com eles você executa tarefas rotineiras com poucas linhas, escrevendo menos e fazendo muito mais.
Highlights
- Easy to set up (Fácil de configurar)
- Total CRUD asbtration (Asbtração total do CRUD)
- Create safe models (Crie de modelos seguros)
- Composer ready (Pronto para o composer)
- PSR-2 compliant (Compatível com PSR-2)
Installation
Database is available via Composer:
"bmorais/database": "2.0.*"
or run
composer require bmorais/database
Documentation
For details on how to use the Data Layer, see the sample folder with details in the component directory
Para mais detalhes sobre como usar o Database, veja a pasta de exemplo com detalhes no diretório do componente
connection
To begin using the Data Layer, you need to connect to the database (MariaDB / MySql). For more connections PDO connections manual on PHP.net
Para começar a usar o Data Layer precisamos de uma conexão com o seu banco de dados. Para ver as conexões possíveis acesse o manual de conexões do PDO em PHP.net
const CONFIG_DATA_LAYER = [ "driver" => "mysql", "host" => "localhost", "port" => "3306", "dbname" => "database", "username" => "user", "passwd" => "", "options" => [ PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8, lc_time_names = 'pt_BR'", PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::MYSQL_ATTR_FOUND_ROWS => true, PDO::ATTR_STRINGIFY_FETCHES => true ], "homologation" => "homologacao", "directory_models" => "App\\Models\\", "display_errors_details" => true, ];
your model
The Database is based on an MVC structure with the Layer Super Type and Active Record design patterns. Soon to consume it is necessary to create the model of your table and inherit the Data Layer.
O database é baseado em uma estrutura MVC com os padrões de projeto Layer Super Type e Active Record. Logo para consumir é necessário criar o modelo de sua tabela e herdar o CRUD.
<?php class Usuario extends Crud { public function __construct() { $this->setTableName("EXAMPLE"); $this->setClassModel("exampleModel"); $this->setDatabase("nomeBD"); } /** * @param $codusuario * @return array|null */ public function buscarIdObj($codusuario) { $result = $this->select("*","WHERE CODUSUARIO=?",[$codusuario]); if ($result){ return $result; } else { return null; } } /** * @param $codusuario * @return AutUserModel[] | null */ public function buscarIdModelExample($codusuario) { $result = $this->select("*","WHERE CODUSUARIO=?",[$codusuario], true); if ($result){ return $result; } else { return null; } } /** * @param $codusuario * @return AutUserModel[] | null */ public function buscarIdModelExample2($codusuario) { $sql = "SELECT * FROM AUT_USER AS U WHERE U.CODUSUARIO=?"; $params = array($codusuario); $result = $this->executeSQL($sql,$params); if (!empty($result)){ return $this->getObjModel($result,$this->classModel); } else { return null; } } /** * @param $coduser * @return bool */ public function updateUser($name, $email, $coduser) { $result = $this->update("NAME, EMAIL", array($name, $email), "CODUSER=?"); if ($result){ return true; } else { return false; } } /** * @param $name * @return bool */ public function insertUser($name, $email) { $result = $this->insert("NOME, EMAIL", array($name, $email)); if ($result){ return true; } else { return false; } } }
Contributing
Please see CONTRIBUTING for details.
Support
Security: If you discover any security related issues, please email contato@bmorais.com instead of using the issue tracker.
Se você descobrir algum problema relacionado à segurança, envie um e-mail para contato@bmorais.com em vez de usar o rastreador de problemas.
Thank you
Credits
- Bruno Morais (Developer)
- Athus Felipe (Developer)
Contributing
🚧 Contributing Guidelines - Currently being updated 🚧
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 appropriate tag. 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
Remember to include a tag, and to follow Conventional Commits and Semantic Versioning when uploading your commit and/or creating the issue.
Aknowledgements
Thank you to all the people who contributed to this project, whithout you this project would not be here today.
Obrigado a todas as pessoas que contribuíram para este projeto, sem vocês este projeto não estaria aqui hoje.
License
The MIT License (MIT). Please see License File for more information.
bmorais/database 适用场景与选型建议
bmorais/database 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 466 次下载、GitHub Stars 达 4, 最近一次更新时间为 2022 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「pdo」 「crud」 「delete」 「save」 「destroy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bmorais/database 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bmorais/database 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bmorais/database 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Gii Generator for double model generation
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.
A PSR-7 compatible library for making CRUD API endpoints
Admin panel generator for Laravel 8 and based on Vuetify Admin, a separate SPA admin framework running on top of REST APIs.
统计信息
- 总下载量: 466
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-11