s3 -- -- json -- -- db
使用 Amazon S3 作为简单的 JSON 数据库和没有服务器的 API
关于
S3 JSON DB是亚马逊S3的一个简单的基于文件的JSON数据库. 它允许您插入,更新,检索和删除条目. 所有条目都存储在S3上,作为单个json文件中的对象,因此您也可以轻松地从单一页面应用程序或任何服务器侧已渲染的应用程序中取出(不需要这个模块). 您可以使用它来快速为您的 SPA 原型一个没有服务器的应用程序或后端. 与亚马逊S3相兼容,数字海洋空间,Linode对象存储,后布雷泽B2等. https://www.npmjs.com/package/@dashpilot/s3-json-db
安装
npm install @dashpilot/s3-json-db
使用量
const S3DB = require('s3-json-db');
const db = new S3DB(s3_key, s3_secret, s3_bucket, s3_prefix, s3_acl, s3_endpoint);
const table = 'entries';
let data = {
title: 'This is the first entry',
body: 'Lorem ipsum dolor site amet'
}
// insert
db.insert(table, data).then(id => {
console.log("created " + id);
});
// update
db.update(table, data, id).then(id => {
console.log("updated " + id);
});
// delete
db.delete(table, id).then(id => {
console.log("deleted " + id);
});
// get one entry by id
db.get(table, id).then(data => {
console.log(data);
});
// get all entries
db.get_all(table).then(data => {
console.log(data);
});
配置
s3_key (required): your S3 API key
s3_secret (required): your S3 API secret
s3_bucket (required): your S3 bucket
s3_prefix (optional): optional file prefix or subfolder (for the latter end with a slash). default "";
s3_acl (optional): ACL (https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl). Default: "private", set to "public-read" if you want your data to be public (to use with a client-side app).
s3_endpoint (optional): change the endpoint if you use Digitalocean Spaces, Linode Object Storage, Backblaze B2, etc. Default: false.
要获取所有条目客户端( 设置 s3 ACL 为“ 公共阅读 ” ):
{your_s3_url}/{bucket}/{s3_prefix}/{table}.json
按: star: 按钮
别忘了按下:星:按下按钮让我知道,我应该继续改进这个项目.