almacil/php-database
Composer 安装命令:
composer require almacil/php-database
包简介
A simple flat file database designed to persist data using just PHP and flat files. Perfect solution when no other database is available or for small projects.
README 文档
README
🗃 Almacil PHP Database
This is a simple flat file NoSQL like database implemented in PHP for small projects without any third-party dependencies that store data in plain JSON files.
Features
- Lightweight and Secure
- Easy to get started
- No external dependencies
- CRUD (create, read, update, delete) operations
- Supports multiple databases and tables/collections
Installation
Installation is possible using Composer
composer requiere almacil/php-database
Usage
Summary
// Create instance $db = new \Almacil\Database($database); // Basic $db->find($collection, /* function to find */); $db->insert($collection, $item); $db->update($collection, /* function to find */, $update); $db->remove($collection, /* function to find */, $permanent); // More $db->count($collection, /* function to find */); $db->findOne($collection, /* function to find */); $db->upsert($collection, /* function to find */, $update); $db->drop($collection); $db->newid();
Create instance
Create an instance of \Almacil\Database. Optionally, we can maintain the order of the databases and collections with a hierarchy using slash. We can also decide that the directory corresponds to a database and create another instance for another database in another directory.
// Require composer autoloader require __DIR__ . '/vendor/autoload.php'; // Directory containing the json files of databases $database = __DIR__ . '/data'; // Create de instance $db = new \Almacil\Database($database); // "database/collection" or "collection" or "collection/subcollection" $collection = 'mycollection/mysubcollection';
Find
// ... after insert $find = new stdClass(); $find->_id = $newItem->_id; $items = $db->update($collection, function($item) use ($find) { return $find->_id === $item->_id; });
Insert
// ... after create instance $db $item = new stdClass(); $item->name = 'Rubén'; $newItem = $db->insert($collection, $item);
Update
// ... after insert $find = new stdClass(); $find->_id = $newItem->_id; $update = new stdClass(); $update->name = 'Rubén Pérez'; $numberItemsUpdated = $db->update($collection, function($item) use ($find) { return $find->_id === $item->_id; }, $update);
Remove
When we delete an element, we don't really delete it but we set the _removed_at field with the value of microtime(). If we want to delete the element permanently we will send true in the third argument.
// ... after insert $find = new stdClass(); $find->_id = $newItem->_id; $permanent = true; $numberItemsRemoved = $db->remove($collection, function($item) use ($find) { return $find->_id === $item->_id; }, $permanent);
Made with ❤️ by developer for developers
almacil/php-database 适用场景与选型建议
almacil/php-database 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 922 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 08 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 almacil/php-database 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 almacil/php-database 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 922
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-06