是否可以基于每个模型设置sails-disk adapter的filePath和fileName?

时间:2015-08-20 00:56:17

标签: sails.js

我知道我可以通过更改config / connections.js来更改localDisk.db的最终位置

DECLARE @Id int, @NoOfRecordsToDisplay int

SET @Id = 123
SET @NoOfRecordsToDisplay = 3

SELECT COUNT(*) FROM myTable
WHERE
  TypeofValue = 2
  AND Id = @Id
  AND [Year] IN ( SELECT TOP(@NoOfRecordsToDisplay) [Year] FROM myTable
              WHERE TypeofValue = 1 AND Id = @Id
              ORDER BY [Year] DESC)

但是有可能在每个型号的基础上进行设置吗?

1 个答案:

答案 0 :(得分:1)

通过仔细查看文档看起来我找到了自己的答案。

http://sailsjs.org/documentation/concepts/models-and-orm/model-settings

我可以在每个模型的基础上设置连接,这意味着我可以在config / connections.js中将User.db,Host.db等定义为不同的设置:

localHostsDB: {
    adapter: 'sails-disk',
    filePath: '/data/',
    fileName: 'hosts.db'
},
localUsersDB: {
    adapter: 'sails-disk',
    filePath: '/data/',
    fileName: 'users.db'
},

然后在我的api / models / Host.js的顶部:

module.exports = {
  connection: 'localHostsDb',
  attributes: {
    name: { type: 'string', required: true, unique: true },