mysql - 弃用 : `config.adapters.default` Sails. js

标签 mysql node.js sails.js

当我扬 sails 项目时,我在终端上收到这些警告

debug: Deprecated: config.adapters.default debug: (see http://links.sailsjs.org/docs/config/connections) debug: For now, I'll pretend you set config.models.connection.

debug: Deprecated: config.adapters debug: (see http://links.sailsjs.org/docs/config/connections) debug: For now, I'll pretend you set config.connections.

debug: Deprecated: config.adapters.*.module debug: (see http://links.sailsjs.org/docs/config/connections) debug: For now, I'll pretend you set config.connections["disk"].adapter.

而且我的数据没有存储在 mysql 数据库中。 这是我的api模型代码

module.exports = {

  schema:true,

  tableName: 'BusStop',

  adapters: 'mysql-adapter',

  migrate: 'safe',

  attributes: {
    stopID:{
        type: 'int'
    },
    stopName:{
        type: 'string'
    },
    latitude:{
        type: 'float'
    },
    longitude:{
        type: 'float'
    }
  }
};

这是我的 local.js 代码

module.exports = {

   port: process.env.PORT || 1337,

    environment: process.env.NODE_ENV || 'development',

    adapters:{
      'default': 'disk',
      disk:{
        module:'sails-disk'
      },

      'mysql-adapter': {
        module    : 'mysql-sails',
        host      : '127.0.0.1',
        user      : 'root',
        password  : '',
        database  : 'PublicTransport',
        schema    : true
      }
    }

};

这是我的 connections.js 代码

module.exports.connections = {
 localDiskDb: {
    adapter: 'sails-disk'
  },
  'mysql-adapter': {
    module    : 'sials-mysql',
    host      : '127.0.0.1',
    port      : 3306,
    user      : 'root',
    password  : '',
    database  : 'PublicTransport'
  },
  someMongodbServer: {
    adapter: 'sails-mongo',
    host: 'localhost',
    port: 27017,
  },
  somePostgresqlServer: {
    adapter: 'sails-postgresql',
    host: 'YOUR_POSTGRES_SERVER_HOSTNAME_OR_IP_ADDRESS',
    user: 'YOUR_POSTGRES_USER',
    password: 'YOUR_POSTGRES_PASSWORD',
    database: 'YOUR_POSTGRES_DB'
  }

};

我想知道如何删除这些已弃用的警告以及为什么我的数据没有存储在数据库中。

最佳答案

看起来那些弃用警告中的链接不正确。有关如何配置 Sails 连接的信息,请参阅 http://sailsjs.org/#/documentation/reference/sails.config/sails.config.connections.html .

按照他们关于设置什么配置键的说明,您应该能够让这些消息消失。

为了为特定模型设置连接,您现在设置connection 属性:

module.exports = {

  schema:true,

  tableName: 'BusStop',

  connection: 'mysql-adapter', // "adapter" is now "connection

  migrate: 'safe',

  attributes: {...}

}

为了指定用于连接的适配器,使用adapter键,而不是module;你已经在你的大部分连接中这样做了,你只需要更新 mysql-adapter

在您的 config/local.js 中,您正在使用已弃用的 adapters 键来设置连接;使用 connections 代替。

最后,为了为您的所有模型设置默认连接,您按照弃用消息中的说明进行操作并设置 sails.config.models.connection 而不是 sails.config。适配器默认值;您可以在 config/models.js 文件中或在您的 config/local.js 中轻松执行此操作,如下所示:

module.exports = {

  models: {
    connection: 'mysql-adapter'
  },

  ...more config...

}

关于mysql - 弃用 : `config.adapters.default` Sails. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26024790/

相关文章:

javascript - Mongoose - 检测重复字段

node.js - 自动重新加载 sails.js/node.js 中的客户端文件

node.js - 通过 WebSocket 在远程自治 Node.js 应用程序之间进行全双工消息传递?

node.js - 使用基本的 Sails 应用程序不间断地增加内存

java - 我可以使用 MySQL Connector/J 执行以分号分隔的多个查询吗?

php - fatal error : Call to a member function execute() on a non-object PDO Working

Mysql 替换搜索中的一部分(按模式替换)

javascript - 如何连接 Bookshelf.js 中的三个表?

javascript - 无论如何,有没有在jade中编写服务器端nodejs

mysql - 如何通过 SQL 查询从远程数据库中预设的记录集复制的现有输出中将列值替换为另一个列值