使用 knexjs 创建分页的最佳方法是什么?我真的不知道如何做一般的分页。在我的代码下面:
router.get("/", (req, res) => {
db.select("*")
.from("site.site_product")
.offset(0)
.limit(10)
.then(data => {
res.render("inventory/site_product", { data: data });
});
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
谢谢
我想将文件从AWS S3自动下载到我的应用程序文件夹中。现在,这可以手动完成。代码如下:
router.get("/download", (req, res) => {
//File S3 URL
var fileKey =
"key";
AWS.config.update({
accessKeyId: IAM_USER_KEY,
secretAccessKey: IAM_USER_SECRET,
Bucket: BUCKET_NAME
});
var s3 = new AWS.S3();
var file = fs.createWriteStream("test.csv");
var options = {
Bucket: "name",
Key: fileKey
};
res.attachment(fileKey);
var fileStream = s3
.getObject(options)
.createReadStream()
.on("error", error => {
console.log(error);
res.json({ error: "An error has occured, check console." });
})
.on("httpData", function(data) {
file.write(data);
})
.on("httpDone", function() {
file.end();
});
fileStream.pipe(res);
// fse.writeFileSync("text.csv");
});
Run Code Online (Sandbox Code Playgroud)
如前所述,可以手动下载和保存文件。但是如何写文件并将其自动保存在特定的文件夹中呢?
谢谢