简体   繁体   English

检查指定名称的数据库是否存在

[英]Check if database with specified name exists or not

As you may know that whenever we set a new database inside "sails-orientdb adapter" configurations it creates database, now on the creation time of the database of course database will be created if there is no database inside orientdb with this name, now I want to create vertices related to a class you can say those vertices are defaults of my application, whenever new database will be created those defaults will also be created, but when database already exists those defaults will also be skipped. 您可能知道,每当我们在“ sails-orientdb适配器”配置中设置新数据库时,它都会创建数据库,现在,如果orientdb中没有使用该名称的数据库,那么现在将在创建数据库的时候创建数据库要创建与类相关的顶点,可以说这些顶点是我的应用程序的默认值,每当创建新数据库时,这些默认值也会被创建,但是当数据库已经存在时,这些默认值也将被跳过。

Now, is there any function like exists() available inside Waterline or Oriento which can check that database with the specified name inside configurations exists or not inside orientdb and return true or false? 现在,在Waterline或Oriento中是否有可用的函数,例如exist()可以检查orientdb中配置内指定名称的数据库是否存在,并返回true或false?

There is not a function .exists() but Oriento has a function named .list() which will list all DBs and allows checking if a particular DB is present. 没有.exists()函数,但是Oriento有一个名为.list()的函数,该函数将列出所有DB,并允许检查是否存在特定的DB。 To do this from Sails-OrientDB you can use the custom method .getServer() as follows: 要从Sails-OrientDB执行此操作,可以使用自定义方法.getServer() ,如下所示:

// Assume a model named "Post"
Post.getServer()
  .list()
  .then(function (dbs) {
    var dbExists = _.find(dbs, function(db) {
      return db.name === 'myDatabaseName';
    });
    console.log('myDatabaseName exists:', dbExists);
});

This is the logic that Sails-OrientDB uses to determine if the DB exists before creating it: https://github.com/appscot/sails-orientdb/blob/master/lib/connection.js#L604-L608 这是Sails-OrientDB在创建数据库之前用于确定数据库是否存在的逻辑: https : //github.com/appscot/sails-orientdb/blob/master/lib/connection.js#L604-L608

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM