Node.js 从nedb到Postgres需要对代码进行哪些更改?

Node.js 从nedb到Postgres需要对代码进行哪些更改?,node.js,postgresql,feathersjs,Node.js,Postgresql,Feathersjs,我使用了feathers nedb库,并在Node中编写了一个服务器代码。现在我需要转到Postgres DB。我已经在feathers nedb中编写了模型和数据插入查询,所以有一种方法我不会弄乱结构,而是连接到Postgres并运行代码。有一种方法。您可以使用knex库。只需将nedb模型更改为feathers knex,并使用knex Postgres连接字符串创建一个模型 const dbPath = app.get('nedb'); const Model = new NeDB({

我使用了feathers nedb库,并在Node中编写了一个服务器代码。现在我需要转到Postgres DB。我已经在feathers nedb中编写了模型和数据插入查询,所以有一种方法我不会弄乱结构,而是连接到Postgres并运行代码。

有一种方法。您可以使用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。

我认为您在这里找不到1:1。这是两种截然不同的数据库产品:/