STF -- 數據庫定義

STF的數據庫使用的是RethinkDB。RethinkDB啓動後,在瀏覽器裏輸入http://stf_server_ip:8080即可打開RethinkDB後臺管理中心。

在STF中,定義數據庫的文件爲stf_home/lib/db/tables.js。

var r = require('rethinkdb')

module.exports = {
  users: {//user表
    primaryKey: 'email'
  , indexes: {
      adbKeys: {
        indexFunction: function(user) {
          return user('adbKeys')('fingerprint')
        }
      , options: {
          multi: true
        }
      }
    }
  }
, accessTokens: {//accessTokens表
    primaryKey: 'id'
  , indexes: {
      email: null
    }
  }
, vncauth: {//vncauth表
    primaryKey: 'password'
  , indexes: {
      response: null
    , responsePerDevice: {
        indexFunction: function(row) {
          return [row('response'), row('deviceId')]
        }
      }
    }
  }
, devices: {//devices表
    primaryKey: 'serial'
  , indexes: {
      owner: {
        indexFunction: function(device) {
          return r.branch(
            device('present')
          , device('owner')('email')
          , r.literal()
          )
        }
      }
    , present: null
    , providerChannel: {
        indexFunction: function(device) {
          return device('provider')('channel')
        }
      }
    }
  }
, logs: {//logs表
    primaryKey: 'id'
  }
}


發佈了77 篇原創文章 · 獲贊 30 · 訪問量 27萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章