Comparing version 0.41.5 to 0.41.6
@@ -93,2 +93,3 @@ /* | ||
this.findEach = this.commonGateway( 'findEach' ) ; | ||
this.getNextCounterFor = this.commonGateway( 'getNextCounterFor' ) ; | ||
@@ -532,2 +533,12 @@ this.clear = this.commonGateway( 'clear' ) ; | ||
// Get and increment a counter | ||
MongoDriver.getNextCounterFor = async function( name ) { | ||
var result = await this.mongoCollection.findOneAndUpdate( { name } , { $inc: { counter: 1 } } , { upsert: true } ) ; | ||
// It returns the value before incrementation, so we have to add 1 | ||
return result ? result.counter + 1 : 1 ; | ||
} ; | ||
// Collection-wide | ||
@@ -534,0 +545,0 @@ |
@@ -134,2 +134,3 @@ /* | ||
rootsDb.VersionCollection = require( './VersionCollection.js' ) ; | ||
rootsDb.CountersCollection = require( './CountersCollection.js' ) ; | ||
@@ -136,0 +137,0 @@ rootsDb.Import = require( './Import.js' ) ; |
@@ -52,2 +52,5 @@ /* | ||
this.collections = {} ; | ||
this.versionCollection = null ; | ||
this.countersCollection = null ; | ||
} | ||
@@ -98,2 +101,21 @@ | ||
World.prototype.createCountersCollection = function( name , schema ) { | ||
if ( this.countersCollection ) { | ||
throw new Error( 'Counters collection already created' ) ; | ||
} | ||
this.countersCollection = this.collections[ name ] = new rootsDb.CountersCollection( this , name , schema ) ; | ||
return this.countersCollection ; | ||
} ; | ||
World.prototype.createAndInitCountersCollection = async function( name , schema ) { | ||
var collection = this.createCountersCollection( name , schema ) ; | ||
await collection.init() ; | ||
return collection ; | ||
} ; | ||
World.prototype.createMemoryModel = function( options ) { | ||
@@ -100,0 +122,0 @@ return new rootsDb.MemoryModel( this , options ) ; |
{ | ||
"name": "roots-db", | ||
"version": "0.41.5", | ||
"version": "0.41.6", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=16.20.1" |
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
288830
35
6025