reallywang/dynamo-db
Composer 安装命令:
composer create-project reallywang/dynamo-db
包简介
DynamoDB操作封装
README 文档
README
像使用MySQL一样使用DynamoDB(Use DynamoDB as you would with MySQL)
禁止使用保留字,具体哪些是保留字可在包文件 DynamoDb.php 文件中查看,如果已经使用保留字的用户,请读下一条
保留字问题已在内部处理,使用者可以不用关心保留字问题(AWS不支持的地方此工具同样不支持,AWS支持的地方此工具已内部处理)
目录
1. 安装
2. 使用
3. 新增数据
4. 修改数据
5. 查询数据
6. 删除数据
7. 获取数量
8. 部分删除
9. 自增与自减
现在,开始
1. 安装
composer require reallywang/dynamo-db
或是composer.json中require下添加
"reallywang/dynamo-db": "^1.4"
2. 使用
require_once "vendor/autoload.php";
use ReallyWang\DynamoDB\DB;
// 整理配置
$config = [
'default' => [
'region' => '',
'version' => '',
'credentials' => [
'key' => '',
'secret' => ''
]
],
'test' => [
'region' => '',
'version' => '',
'credentials' => [
'key' => '',
'secret' => ''
]
]
];
// 获取连接对象
DB::config($config); // 默认为default
// DB::config($config, 'test'); // 使用test数据库配置
3. 新增数据
// 向wrtest表中新增数据
$result = DB::table('wrtest')->insert(['id' => 1, 'detail' => '23123']);
4. 修改数据
// 修改wrtest表中 id = 123 且detail 大于 2的行 detail 为 23123
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail' => ['>', 2]])->update(['detail' => '23123']);
5. 查询数据
// 查询wrtest表中id = 123的数据(id 必须是主键,find方法必须与key方法同时使用)
$result = DB::table('wrtest')->key(['id' => '123'])->find();
// 查询wrtest表中id = 1 且 detail 大于 2 的数据中的detail属性,condition 中必须包括主键
$result = DB::table('wrtest')->condition(['id' => 1, 'detail' => ['>', 2]])->field(['detail'])->get();
// 查询wrtest表中detail 小于 0 或 detail 在 2 和 3 之间的数据
$result = DB::table('wrtest')->condition(['detail' => ['<', 0]])->orCondition(['detail' => ['between', 2, 3]])->scan();
6. 删除数据
// 删除wrtest表中 id = 123 且detail 大于 2的行
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail' => ['>', 2]])->delete();
7. 获取数量
// 获取wrtest表中 id = 123 且detail 大于 2的数据条数
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail' => ['>', 2]])->count();
8. 部分删除
// 修改wrtest表中 id = 123 且detail 大于 2的行 detail 为 23123
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail' => ['>', 2]])->remove(['detail.author[0]']);
// 将wrtest表中 id = 123 且detail.author 中有3个元素 的行 detail.author中的第一个元素删掉
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail.author' => ['size', 3]])->remove(['detail.author[0]']);
// 将wrtest表中 id = 123 且detail.author 中元素数量大于等于3 的行 detail.author中的第一个元素删掉
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail.author' => ['size', '>=', 3]])->remove(['detail.author[0]']);
// 将wrtest表中 id = 123 且detail.author 中元素个数在3和10之间 的行 detail.author中的第一个元素删掉
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail.author' => ['size', 'between', 3, 10]])->remove(['detail.author[0]']);
9. 自增与自减
// wrtest表 符合 id 为123 的行 num属性会递增 1
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail' => '123'])->step('num');
// wrtest表 符合 id 为123 的行 num属性会递减 2
$result = DB::table('wrtest')->key(['id' => '123'])->condition(['detail' => '123'])->step('num', false, 2);
reallywang/dynamo-db 适用场景与选型建议
reallywang/dynamo-db 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 99 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 02 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 reallywang/dynamo-db 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 reallywang/dynamo-db 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 99
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-27