mthenw / nosqlite
基于 SQLite3 的简单键值存储
v0.3.0
2013-09-26 19:14 UTC
Requires
- php: >=5.3.2
Requires (Dev)
- phpunit/phpunit: 3.7.*@stable
- squizlabs/php_codesniffer: 1.4.*@stable
This package is not auto-updated.
Last update: 2024-09-14 12:00:55 UTC
README
介绍
NoSQLite 是一个使用 SQLite 作为原始数据存储的简单键值存储。主要适用于 MySQL 太重、文件太丑的小型项目。
要求
- PHP >=5.3.2
- PDO(自 PHP 5.1.0 起默认启用)
- PDO_SQLITE(自 PHP 5.1.0 起默认启用)
通过 Composer 安装
获取 composer 并将以下行添加到 composer.json
{
"require": {
"mthenw/nosqlite": "*@stable"
}
}
用法
-
创建存储管理器(如果不存在,将创建文件)
$nsql = new NoSQLite\NoSQLite('mydb.sqlite');
-
获取存储
$store = $nsql->getStore('movies');
-
在存储中设置值(键和值的最大长度受 SQLite TEXT 数据类型的限制)
$store->set(uniqid(), json_encode(array('title' => 'Good Will Hunting', 'director' => 'Gus Van Sant')));
-
从存储中获取值(如果不存在则创建)
$store->get('3452345');
-
获取所有值
$store->getAll();
-
删除所有值
$store->deleteAll();
-
遍历存储(存储实现 Iterator 接口)
foreach($store as $key => $value) ...
-
获取存储中值的数量(存储实现 Countable 接口)
count($store);
测试
测试是用 PHPUnit 编写的,需要在 composer.json
中作为开发包要求。运行测试使用
./vendor/bin/phpunit
或简单地
make test