node.js - 从 Feathers nedb 迁移到 Postgres 需要对代码进行哪些更改?
问题描述
我使用了 feathers-nedb 库并在 Node.js 中编写了一个服务器代码。现在我需要转移到 Postgres DB。我已经在 feathers-nedb 中编写了模型和数据插入查询,所以有没有办法我不会弄乱结构,而是连接到 Postgres 并运行代码。
解决方案
有一种方法。您可以使用 feathers-knex 库。只需将 nedb 模型更改为 feathers-knex 并使用 knex Postgres 连接字符串创建模型。
const dbPath = app.get('nedb');
const Model = new NeDB({
filename: path.join(dbPath, 'test.db'),
autoload: true
});
const Model = new knex({
client: 'pg',
connection: "postgres://postgres:password@localhost:5432/test",
searchPath: ['knex', 'public'],
});
这是模型端唯一需要的代码更改。在服务端,使用feathers-knex 代替feathers-nedb。
推荐阅读
- excel - VBA 将基于单元格值的特定工作表导出为 PDF
- python - 使用非传统图表的 pine 脚本中基于百分比的停止
- multithreading - Matlab 产生的线程太多了
- ruby-on-rails - ActiveRecord:如何查询特定工作日(例如周一、周二等)创建的记录
- javascript - 我有两个计时器不能在 javascript 中工作
- terraform - 我在运行 terraform 计划时遇到问题
- assembly - AVR 汇编器检查是奇数
- development-environment - 为什么在我的代码中找不到函数 setCredentials()?
- java - Java:无法使用 for 循环“蛮力”方程系统
- c# - 无法导入 System.Windows.Data