camouflage
Advanced tools
Comparing version 0.8.10 to 0.8.11
@@ -233,2 +233,21 @@ "use strict"; | ||
createIndex(collection, columnName, indexType, options){ | ||
options = options || {}; | ||
var that = this; | ||
return new Promise(function(resolve, reject){ | ||
var db = that._mongo.collection(collection); | ||
var indexDef = columnName; | ||
if(typeof indexType === 'string'){ | ||
indexDef = { [columnName]: indexType }; | ||
} | ||
db.createIndex(indexDef, { unique: options.unique, sparse: options.sparse }, function(err){ | ||
if(err){ | ||
reject(err); | ||
} else { | ||
resolve(true); | ||
} | ||
}); | ||
}); | ||
} | ||
static connect(url, options) { | ||
@@ -235,0 +254,0 @@ if (typeof(options) === 'undefined') { |
@@ -298,2 +298,17 @@ "use strict"; | ||
createIndex(collection, columnName, indexType, options){ | ||
options = options || {}; | ||
var that = this; | ||
return new Promise(function(resolve, reject){ | ||
var db = getCollection(collection, that._collections, that._path); | ||
db.ensureIndex({ fieldName: columnName, unique: options.unique, sparse: options.sparse }, function(err){ | ||
if(err){ | ||
reject(err); | ||
} else { | ||
resolve(true); | ||
} | ||
}) | ||
}); | ||
} | ||
static connect(url, options) { | ||
@@ -300,0 +315,0 @@ // Could be directory path or 'memory' |
@@ -28,2 +28,19 @@ "use strict"; | ||
static _initializeIndexes(){ | ||
if(this.indexesInitialized){ | ||
return; | ||
} | ||
this.indexesInitialized = true; | ||
var instance = this._instantiate(); | ||
var schema = instance._schema; | ||
for (var key in schema){ | ||
if(schema.hasOwnProperty(key)){ | ||
let indexType = schema[key].index; | ||
if(indexType){ | ||
DB().createIndex(instance._meta.collection, key, indexType); | ||
} | ||
} | ||
} | ||
} | ||
documentClass() { | ||
@@ -30,0 +47,0 @@ return 'document'; |
{ | ||
"name": "camouflage", | ||
"version": "0.8.10", | ||
"version": "0.8.11", | ||
"description": "A class-based ES6 ODM for Mongo-like databases.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -150,3 +150,4 @@ # Camouflage | ||
max: 25, | ||
choices: [2, 3, 5, 7, 11, 13, 17, 19, 23] | ||
choices: [2, 3, 5, 7, 11, 13, 17, 19, 23], | ||
index: true | ||
} | ||
@@ -164,2 +165,3 @@ ``` | ||
- `validate`: A 1-argument function that returns `false` if the value is invalid *(optional)* | ||
- `index`: Create an index on the given field if `true` or a string; a string can be supplied to define the index type, like `'2d'` *(optional)* | ||
@@ -166,0 +168,0 @@ To reference another document, just use its class name as the type. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
260782
5184
350