sheetdb/sheetdb-php
Composer 安装命令:
composer require sheetdb/sheetdb-php
包简介
PHP Library for accessing google spreadsheet content via SheetDB. https://sheetdb.io
README 文档
README
Installation
The SheetDB PHP Library is available through Composer
composer require sheetdb/sheetdb-php
Test spreadsheet
At any time you can play with our test API here: https://sheetdb.io/api/v1/58f61be4dda40
You can also go to Google Sheets and play with it: https://docs.google.com/spreadsheets/u/2/d/1mrsgBk4IAdSs8Ask5H1z3bWYDlPTKplDIU_FzyktrGk/edit The spreadsheet resets every hour.
Basic usage
In order to instantiate SheetDB connection you need to give an api id. You can find it in SheetDB Dashboard.
require('vendor/autoload.php'); use SheetDB\SheetDB; $sheetdb = new SheetDB('58f61be4dda40'); $response = $sheetdb->get(); // returns all spreadsheets data $response = $sheetdb->keys(); // returns all spreadsheets key names $response = $sheetdb->name(); // returns name of a spreadsheet document
Searching
You can use search method to find only specific rows. You have 2 options. Search rows that meets all of the conditions or search rows that meets at least one of the conditions.
You can use second parameter if you want the search to be case sensitive (it is boolean). By default it is not case sensitive.
$response = $sheetdb->search(['name'=>'Steve','age'=>'22']); // returns when name="Steve" AND age=22 $response = $sheetdb->searchOr(['name'=>'Steve','age'=>'19']); // returns when name="Steve" OR age=19 $response = $sheetdb->search(['name'=>'Steve'], true); // returns when name="Steve", this query is case sensitive
Creating a row(s)
If you want to create a new row you'll need to pass an array with key_name => value. If you want to create multiple rows that should be an array of arrays.
$sheetdb->create(['name'=>'Mark','age'=>'35']); $sheetdb->create([ ['name'=>'Chris','age'=>'34'], ['name'=>'Amanda','age'=>'29'], ]);
Updating a row(s)
First two parameters are key and value that need to match, third argument is array similar to the create one.
Fourth parameter is optional. If it's true not specified values will be emptied.
$sheetdb->update('name','Chris',['age'=>'33']); // it will change only age $sheetdb->update('name','Chris',['age'=>'33'],true); // it will update age to 33 but all other values will be emptied, in this case a name
Update the batch of rows in the spreadsheet
Update for various queries. First argument is data itself. Each object in it should have a query key with the actual query (for example, "id=5"), and the remaining keys will be updated, as in a regular PATCH / PUT request.
Second parameter is optional. If it's true not specified values will be emptied.
$sheetdb->batchUpdate([ [ 'query' => 'id=1', 'age' => '33', ], [ 'query' => 'id=2', 'age' => '52', ] ]);
Delete a row(s)
Just like in update first two parameters are key and value. Every row that will match query will be deleted.
$sheetdb->delete('name','Chris'); // will delete all rows with name = "Chris"
sheetdb/sheetdb-php 适用场景与选型建议
sheetdb/sheetdb-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 59.84k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2017 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sheetdb/sheetdb-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sheetdb/sheetdb-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 59.84k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-06