dynamic-record
Advanced tools
Comparing version 0.5.2 to 0.5.3
@@ -107,28 +107,28 @@ "use strict"; | ||
const db = opts.db; | ||
const promises = []; | ||
// Create the collection, ensuring that is doesn't already exist | ||
// in the database | ||
promises.push(db.createCollection(tableSlug, { strict: true })); | ||
const createCounters = new Promise((resolve, reject) => { | ||
db.collection("_counters", { strict: true }, (err, col) => { | ||
if (err) | ||
return reject(err); | ||
col.insertOne({ | ||
_$id: tableSlug, | ||
sequences: {} | ||
}).then(() => { | ||
resolve(); | ||
return db.createCollection(tableSlug, { strict: true }).then(() => { | ||
return new Promise((resolve, reject) => { | ||
db.collection("_counters", { strict: true }, (err, col) => { | ||
if (err) | ||
return reject(err); | ||
col.insertOne({ | ||
_$id: tableSlug, | ||
sequences: {} | ||
}).then(() => { | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}).then(() => { | ||
const databaseInsert = schema; | ||
schema._$schema = schema.$schema; | ||
schema._$id = schema.$id; | ||
delete schema.$schema; | ||
delete schema.$id; | ||
return db.collection("_schema").insertOne(databaseInsert); | ||
}).then(() => { | ||
this.definition = columns; | ||
return this._writeSchema(); | ||
}); | ||
promises.push(createCounters); | ||
const databaseInsert = schema; | ||
schema._$schema = schema.$schema; | ||
schema._$id = schema.$id; | ||
delete schema.$schema; | ||
delete schema.$id; | ||
promises.push(db.collection("_schema").insertOne(databaseInsert)); | ||
this.definition = columns; | ||
promises.push(this._writeSchema()); | ||
return Promise.all(promises); | ||
}).then(() => { | ||
@@ -159,2 +159,3 @@ this.tableName = tableName; | ||
}).catch((err) => { | ||
// NOTE: potentially undo stuff that's done at this point | ||
this.tableName = null; | ||
@@ -161,0 +162,0 @@ this.tableSlug = null; |
@@ -5,3 +5,7 @@ require("dotenv").config(); | ||
const mongoURL = f("mongodb://%s:%s@%s/%s", process.env.mongo_user, process.env.mongo_pass, process.env.mongo_server, process.env.mongo_db_name); | ||
const connection = MongoClient.connect(mongoURL, { poolSize: 10 }); | ||
const client = new MongoClient(mongoURL, { | ||
poolSize: 10, | ||
useUnifiedTopology: true | ||
}); | ||
const connection = client.connect(); | ||
module.exports = connection.then((client) => { | ||
@@ -8,0 +12,0 @@ const db = client.db(); |
{ | ||
"name": "dynamic-record", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "A bare minimum Javascript implementation of the Active Record pattern", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -151,36 +151,32 @@ require("dotenv").config(); | ||
const db = opts.db; | ||
const promises = []; | ||
// Create the collection, ensuring that is doesn't already exist | ||
// in the database | ||
promises.push(db.createCollection(tableSlug, {strict: true})); | ||
return db.createCollection(tableSlug, {strict: true}).then(() => { | ||
return new Promise((resolve, reject) => { | ||
db.collection("_counters", {strict: true}, (err, col) => { | ||
if(err) return reject(err); | ||
const createCounters = new Promise((resolve, reject) => { | ||
db.collection("_counters", {strict: true}, (err, col) => { | ||
if(err) return reject(err); | ||
col.insertOne({ | ||
_$id: tableSlug, | ||
sequences: {} | ||
}).then(() => { | ||
resolve(); | ||
col.insertOne({ | ||
_$id: tableSlug, | ||
sequences: {} | ||
}).then(() => { | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
promises.push(createCounters); | ||
}).then(() => { | ||
const databaseInsert = schema; | ||
schema._$schema = schema.$schema; | ||
schema._$id = schema.$id; | ||
const databaseInsert = schema; | ||
schema._$schema = schema.$schema; | ||
schema._$id = schema.$id; | ||
delete schema.$schema; | ||
delete schema.$id; | ||
delete schema.$schema; | ||
delete schema.$id; | ||
return db.collection("_schema").insertOne(databaseInsert); | ||
}).then(() => { | ||
this.definition = columns; | ||
return this._writeSchema(); | ||
}); | ||
promises.push(db.collection("_schema").insertOne(databaseInsert)); | ||
this.definition = columns; | ||
promises.push(this._writeSchema()); | ||
return Promise.all(promises); | ||
}).then(() => { | ||
@@ -217,2 +213,3 @@ this.tableName = tableName; | ||
}).catch((err) => { | ||
// NOTE: potentially undo stuff that's done at this point | ||
this.tableName = null; | ||
@@ -219,0 +216,0 @@ this.tableSlug = null; |
@@ -6,3 +6,7 @@ require("dotenv").config(); | ||
const mongoURL = f("mongodb://%s:%s@%s/%s", process.env.mongo_user, process.env.mongo_pass, process.env.mongo_server, process.env.mongo_db_name); | ||
const connection = MongoClient.connect(mongoURL, {poolSize: 10}); | ||
const client = new MongoClient(mongoURL, { | ||
poolSize: 10, | ||
useUnifiedTopology: true | ||
}); | ||
const connection = client.connect(); | ||
module.exports = connection.then((client) => { | ||
@@ -9,0 +13,0 @@ const db = client.db(); |
@@ -8,3 +8,3 @@ // For setup and clean ups | ||
const mongoURL = f("mongodb://%s:%s@%s/%s", process.env.mongo_user, process.env.mongo_pass, process.env.mongo_server, process.env.mongo_db_name); | ||
const connect = MongoClient.connect(mongoURL); | ||
const connect = MongoClient.connect(mongoURL, {useUnifiedTopology: true}); | ||
@@ -11,0 +11,0 @@ // Test dependencies |
@@ -8,3 +8,3 @@ // For setup and clean ups | ||
const mongoURL = f("mongodb://%s:%s@%s/%s", process.env.mongo_user, process.env.mongo_pass, process.env.mongo_server, process.env.mongo_db_name); | ||
const connect = MongoClient.connect(mongoURL); | ||
const connect = MongoClient.connect(mongoURL, {useUnifiedTopology: true}); | ||
@@ -168,3 +168,2 @@ // Test dependencies | ||
return Random.all().then((col) => { | ||
console.log(col.data, testData[0]); | ||
assert.deepInclude(col.data, testData[0], "collection data includes first test data"); | ||
@@ -171,0 +170,0 @@ assert.deepInclude(col.data, testData[1], "collection data includes second test data"); |
@@ -8,3 +8,3 @@ // For setup and clean ups | ||
const mongoURL = f("mongodb://%s:%s@%s/%s", process.env.mongo_user, process.env.mongo_pass, process.env.mongo_server, process.env.mongo_db_name); | ||
const connect = MongoClient.connect(mongoURL); | ||
const connect = MongoClient.connect(mongoURL, {useUnifiedTopology: true}); | ||
@@ -11,0 +11,0 @@ // Test dependencies |
@@ -8,3 +8,3 @@ // For setup and clean ups | ||
const mongoURL = f("mongodb://%s:%s@%s/%s", process.env.mongo_user, process.env.mongo_pass, process.env.mongo_server, process.env.mongo_db_name); | ||
const connect = MongoClient.connect(mongoURL); | ||
const connect = MongoClient.connect(mongoURL, {useUnifiedTopology: true}); | ||
@@ -11,0 +11,0 @@ // Test dependencies |
@@ -5,3 +5,3 @@ const MongoClient = require("mongodb").MongoClient; | ||
const mongoURL = `mongodb://${response.username}:${response.password}@${response.serverPath}/${response.database}`; | ||
const connect = MongoClient.connect(mongoURL); | ||
const connect = MongoClient.connect(mongoURL, {useUnifiedTopology: true}); | ||
@@ -8,0 +8,0 @@ return connect.then((client) => { |
149870
4201
34