Permalink
Browse files

changed semantics of dontCreate. Also fixed logic error where it was …

…returning null when the database existed
  • Loading branch information...
1 parent 5fd1caf commit 63387f46c3677b8c0093d035e02ad65ffd5dedca @rhino-security rhino-security committed Feb 1, 2010
Showing with 14 additions and 7 deletions.
  1. +14 −7 lib/couchdb.js
View
@@ -177,22 +177,29 @@ var CouchServer = {
/**
* Get a Database object to work with a database that belongs to this CouchServer.
* Creates the database if it does not exist.
- * @param name Name of the database.
+ * @param name Name of the database.
+ * @param shouldCreate If false, null will be returned if the db doesn't already exist.
+ * If true, the database will be created. Defaults to true.
* @return Database
* @type Object
*/
- database: function(name, dontCreate) {
+ database: function(name, shouldCreate) {
var db;
var getUri = (function() { return this.uri; }).bind(this);
var getHttpClient = (function() { return this.httpClient; }).bind(this);
var getUuid = (function() { return this.uuid(); }).bind(this);
name = encodeURIComponent(name);
-
- if (!this.hasDb(name) && !dontCreate){
- this.createDb(name);
- } else {
- return null;
+ if (shouldCreate === undefined) {
+ shouldCreate = true;
}
+
+ if (!this.hasDb(name)){
+ if (shouldCreate) {
+ this.createDb(name);
+ } else {
+ return null;
+ }
+ }
if (!/\/$/.test(name)){
name += "/";

0 comments on commit 63387f4

Please sign in to comment.