lambdacasserole/condense
Composer 安装命令:
composer require lambdacasserole/condense
包简介
Flat-file database in PHP.
README 文档
README
Flat-file database in PHP.
Based on the Fllat and Prequel libraries by Wylst. Special mention for Alfred Xing who seems to be the main contributor behind both. With added support for:
- Encrypted databases using php-encryption by Taylor Hornby
- Composer via Packagist
Installation
Install Condense via Composer like this:
composer require lambdacasserole/condense
Or alternatively, if you're using the PHAR (make sure the php.exe executable is in your PATH):
php composer.phar require lambdacasserole/condense
Usage
To initialize a new database or load an existing one, do this.
$db = new Database('employees');
This will, by default, create a file db/employees.dat or load that file, if it already exists. You can change the path at which the flat file database will be created thusly.
$db = new Database('employees', '../storage');
The constructor also accepts a third parameter which allows you to specify a key to use to encrypt the database with.
$db = new Database('secrets', '../private', 'my-secret-password');
When loading the database again, this same password must be used.
Create
Use insert to add a record (row) to the database.
$hire = ['first_name' => 'Ethan', 'last_name' => 'Benson', 'salary' => 20000]; $employees->insert($hire);
Retrieve
Condense provides several methods for data retrieval.
One Value
Use the get method. Specify a field name, another field name, and a value. It will return the value of the first field where (in the same row), the value of the second field matches the given value.
// Returns the salary of the first employee with the first name 'Ethan' (20000). $employees->get('salary', 'first_name', 'Ethan');
Field Subset
Use the select method. Returns some (or all) fields in a table, specified by giving an array of desired field names.
// Returns the whole database. $employees->select([]); // Returns the first name of each employee, for example: // [['Ethan'],['Thomas'],['James']] $employees->select(['first_name']);
Update
Condense provides a couple of methods for updating existing data in a database.
One Field
Use the to method to update one field for any row satisfying a condition.
// Change every employee with a first name 'Ethan' to have the surname 'Smithers'. $employees->to('last_name', 'Smithers', 'first_name', 'Ethan');
One Row
Use the update method to update a row by index.
// Change the first row in the database completely. $employees->update(0, ['first_name' => 'Alison', 'last_name' => 'Bradberry']);
Delete
Use the remove method to delete a row in the database.
// Remove the first row in the database. $employees->remove(0);
Caveats
This is a flat file database system. It removes the headache of setting up and configuring a database server, but introduces a few of its own:
- I/O will be much slower due to many disk read/write actions
- Encrypting a database will hugely affect performance
- Bugs may arise due to concurrency issues
- Misconfigured web applications using this library may accidentally allow their databases to be downloaded over HTTP
lambdacasserole/condense 适用场景与选型建议
lambdacasserole/condense 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 136 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lambdacasserole/condense 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lambdacasserole/condense 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 136
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-24
