Checks for existence of a database, creates if non-existent

@param  {string} name Name of database to open
@return {promise} Denotes existence of database
517522
function createDatabase (name) {
  var deferred = q.defer();

  // Make sure the database location exists
  ready.then(function () {
    // Check if database exists
    fs.exists(globalConfig.db.location + name + '.db.json', function (exists) {
      if(exists) return deferred.resolve();

      // If database is non-existent, simply write an empty object as placeholder
      fs.writeFile(globalConfig.db.location + name + '.db.json', '{}', function (err) {
        if(err) return deferred.reject('Database couldn\'t create table');

        return deferred.resolve();
      });
    });
  }, function () {
    deferred.reject('Database couldn\'t instantiate');
  });

  return deferred.promise;
}
161892
def create_db(name, **client_args):
    '''
    
    '''
    if db_exists(name, **client_args):
        log.info('DB \'%s\' already exists', name)
        return False

    client = _client(**client_args)
    client.create_database(name)

    return True
1358099
function OriginDB(name, options) {
  let objects = {};
  let checksums = {};

  if (!_.isString(name)) {
    throw new Error('Invalid name');
  }

  if (_.isObject(options)) {
    options = Object.assign({}, defaultOptions, options);
  } else {
    options = defaultOptions;
  }

  if (_.isString(options.adapter) && !_.has(adapters, options.adapter)) {
    throw new Error('Unknown adapter');
  }

  const save = _.isFunction(options.adapter) ?
    options.adapter(name, objects, checksums, options) :
    adapters[options.adapter](name, objects, checksums, options);

  /**
   * The database instance.
   *
   * @param {string} objectName
   * @param {Object} methods
   */
  function db(objectName) {
    if (_.isBoolean(save.hasLoaded)) deasync.loopWhile(() => !save.hasLoaded);
    if (!_.has(objects, objectName)) objects[objectName] = {};
    return createMethods(objects[objectName], save.bind(null, objectName));
  }

  // backwards compatability with < v2.4.1
  db.save = () => {
    if (_.isBoolean(save.hasLoaded)) deasync.loopWhile(() => !save.hasLoaded);
    _.forIn(objects, function(value, file) {
      save(file);
    });
  };

  return db;
}
512043
public static boolean collectionExists(MongoDatabase db, String collectionName) {
        return db.listCollections().filter(Filters.eq("name", collectionName)).first() != null;
    }
272783
function fileExists(filename) {
    var d = Promise.defer();

    fs.exists(filename, function(exists) {
        d.resolve(exists);
    });

    return d.promise;
}
137600
function() {
        if (!this._disconnected) {
            console.log(
                `LocalIndexedDBStoreBackend.connect: already connected or connecting`,
            );
            return Promise.resolve();
        }

        this._disconnected = false;

        console.log(
            `LocalIndexedDBStoreBackend.connect: connecting...`,
        );
        const req = this.indexedDB.open(this._dbName, VERSION);
        req.onupgradeneeded = (ev) => {
            const db = ev.target.result;
            const oldVersion = ev.oldVersion;
            console.log(
                `LocalIndexedDBStoreBackend.connect: upgrading from ${oldVersion}`,
            );
            if (oldVersion < 1) { // The database did not previously exist.
                this._isNewlyCreated = true;
                createDatabase(db);
            }
            if (oldVersion < 2) {
                upgradeSchemaV2(db);
            }
            if (oldVersion < 3) {
                upgradeSchemaV3(db);
            }
            // Expand as needed.
        };

        req.onblocked = () => {
            console.log(
                `can't yet open LocalIndexedDBStoreBackend because it is open elsewhere`,
            );
        };

        console.log(
            `LocalIndexedDBStoreBackend.connect: awaiting connection...`,
        );
        return reqAsEventPromise(req).then((ev) => {
            console.log(
                `LocalIndexedDBStoreBackend.connect: connected`,
            );
            this.db = ev.target.result;

            // add a poorly-named listener for when deleteDatabase is called
            // so we can close our db connections.
            this.db.onversionchange = () => {
                this.db.close();
            };

            return this._init();
        });
    }
1067029
function bucketExists () {
    // if bucket exists already set then return existing value
    if (defined(this._bucketExists)) {
        // if bucket does not exist then throw error
        if (this._bucketExists === false) {
            throw new Error(`bucket does not exist ${this.bucketName}`)
        }
        // otherwise return value which may be promise or true
        else {
            return Promise.resolve(this._bucketExists)
        }
    }
    // check if bucket exists storing promise so that check will only be done
    // once per instance
    this._bucketExists = this.bucket.exists().then(data => {
        var exists = data[0]
        // bucket exists
        if (exists === true) {
            // replace original promise with boolean
            this._bucketExists = true
            // resolve with true
            return true
        }
        // bucket does not exists and should not be created
        if (!this.createBucket) {
            throw new Error(`bucket does not exist ${this.bucketName}`)
        }
        // create bucket
        return this.bucket.create().then(data => {
            // replace original promise with boolean
            this._bucketExists = true
            // resolve with true
            return true
        })
    })
    // return promise
    return this._bucketExists
}
327370
def schema_exists(cls, cur, schema_name):
        
        cur.execute("SELECT EXISTS (SELECT schema_name FROM information_schema.schemata WHERE schema_name = '{0}');"
                    .format(schema_name))
        return cur.fetchone()[0]
64883
def _check_db_exists(self, instance):
        

        dsn, host, username, password, database, driver = self._get_access_info(instance, self.DEFAULT_DB_KEY)
        context = "{} - {}".format(host, database)
        if self.existing_databases is None:
            cursor = self.get_cursor(instance, None, self.DEFAULT_DATABASE)

            try:
                self.existing_databases = {}
                cursor.execute(DATABASE_EXISTS_QUERY)
                for row in cursor:
                    self.existing_databases[row.name] = True

            except Exception as e:
                self.log.error("Failed to check if database {} exists: {}".format(database, e))
                return False, context
            finally:
                self.close_cursor(cursor)

        return database in self.existing_databases, context
354563
def database(name, database_id = nil, &block)
      @databases << get_class_from_scope(Database, name)
        .new(self, database_id, &block)
    end
1147766
def exists(name, tags=None, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    try:
        rds = conn.describe_db_instances(DBInstanceIdentifier=name)
        return {'exists': bool(rds)}
    except ClientError as e:
        return {'error': __utils__['boto3.get_error'](e)}
1200621
async function getConnection(url, opts = {}) {
    try {
        const dbName = opts.databaseName;
        if (!dbName || dbName === '')
            throw boom.badImplementation('jollof-data-arangodb: databaseName config is required', { url, opts })

        const key = url + dbName;

        //Get connection
        let connection;
        if (connPool[key]) {
            connection = connPool[key];
        } else {
            connection = new Database(opts)
            connection.useBasicAuth(opts.username, opts.password)
            connPool[key] = connection;
        }

        //Now ensure database exists
        const dbNames = await connection.listDatabases();
        if (dbNames.indexOf(dbName) > -1) {
            //our db exists. use it.
            connection.useDatabase(dbName)
        } else {
            //our db does not exist. Attempting to create it
            await connection.createDatabase(dbName)
            connection.useDatabase(dbName)
        }

        return connection;
    } catch (e) {
        console.error(`There was an issue creating/ensuring connection to DB: ${url} with opts: ${util.inspect(opts)}`)
        throw new Error(e);
    }
}
306768
def exists(name):
    '''
    
    '''
    contextkey = 'nspawn.exists.{0}'.format(name)
    if contextkey in __context__:
        return __context__[contextkey]
    __context__[contextkey] = name in list_all()
    return __context__[contextkey]
124922
public function hasDatabase($name)
    {
        foreach ($this->dbList as $db) {
            if ($db->getName() === $name) {
                return true;
            }
        }

        return false;
    }
950252
public static function existe($name, $table = null)
    {
        $name = self::table($name);
        //
        // > I don't know why i put this
        $table = is_null($table) ? Config::get('database.database') : $table;
        //
        $i = Database::count(
                "select * FROM information_schema.tables WHERE table_schema ='".$table."' AND table_name = '".$name."' LIMIT 1;"
            );
        //
        return ($i > 0) ? true : false;
    }
589275
function get($name){
        if(!isset($this->db[$name])){
            return null;
        }
        $r = $this->db[$name];
        return $r();
    }
124310
def exists(name, delimiter=DEFAULT_TARGET_DELIM):
    '''
    
    '''
    name = re.sub(delimiter, DEFAULT_TARGET_DELIM, name)
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': 'Grain exists'}
    _non_existent = object()
    existing = __salt__['grains.get'](name, _non_existent)
    if existing is _non_existent:
        ret['result'] = False
        ret['comment'] = 'Grain does not exist'
    return ret