|
|
@ -52,7 +52,7 @@ const db = new Map<Collection, nedb>(); |
|
|
|
|
|
|
|
|
|
|
|
let dbInsertOne = (collection: Collection, doc: object) => { |
|
|
|
let dbInsertOne = (collection: Collection, doc: object) => { |
|
|
|
return new Promise<string>((resolve, reject) => { |
|
|
|
return new Promise<string>((resolve, reject) => { |
|
|
|
db[collection].insert(doc, (err, newDoc) => { |
|
|
|
db.get(collection).insert(doc, (err, newDoc: any) => { |
|
|
|
if(err) { |
|
|
|
if(err) { |
|
|
|
reject(err); |
|
|
|
reject(err); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -64,7 +64,7 @@ let dbInsertOne = (collection: Collection, doc: object) => { |
|
|
|
|
|
|
|
|
|
|
|
let dbInsertMany = (collection: Collection, docs: object[]) => { |
|
|
|
let dbInsertMany = (collection: Collection, docs: object[]) => { |
|
|
|
return new Promise<string[]>((resolve, reject) => { |
|
|
|
return new Promise<string[]>((resolve, reject) => { |
|
|
|
db[collection].insert(docs, (err, newDocs: any[]) => { |
|
|
|
db.get(collection).insert(docs, (err, newDocs: any[]) => { |
|
|
|
if(err) { |
|
|
|
if(err) { |
|
|
|
reject(err); |
|
|
|
reject(err); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -77,7 +77,7 @@ let dbInsertMany = (collection: Collection, docs: object[]) => { |
|
|
|
let dbUpdateOne = (collection: Collection, query: string | object, updateQuery: object) => { |
|
|
|
let dbUpdateOne = (collection: Collection, query: string | object, updateQuery: object) => { |
|
|
|
query = wrapIdToQuery(query); |
|
|
|
query = wrapIdToQuery(query); |
|
|
|
return new Promise<void>((resolve, reject) => { |
|
|
|
return new Promise<void>((resolve, reject) => { |
|
|
|
db[collection].update(query, updateQuery, { /* options */ }, (err: Error) => { |
|
|
|
db.get(collection).update(query, updateQuery, { /* options */ }, (err: Error) => { |
|
|
|
if(err) { |
|
|
|
if(err) { |
|
|
|
reject(err); |
|
|
|
reject(err); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -90,7 +90,7 @@ let dbUpdateOne = (collection: Collection, query: string | object, updateQuery: |
|
|
|
let dbFindOne = (collection: Collection, query: string | object) => { |
|
|
|
let dbFindOne = (collection: Collection, query: string | object) => { |
|
|
|
query = wrapIdToQuery(query); |
|
|
|
query = wrapIdToQuery(query); |
|
|
|
return new Promise<any>((resolve, reject) => { |
|
|
|
return new Promise<any>((resolve, reject) => { |
|
|
|
db[collection].findOne(query, (err, doc) => { |
|
|
|
db.get(collection).findOne(query, (err, doc) => { |
|
|
|
if(err) { |
|
|
|
if(err) { |
|
|
|
reject(err); |
|
|
|
reject(err); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -103,7 +103,7 @@ let dbFindOne = (collection: Collection, query: string | object) => { |
|
|
|
let dbFindMany = (collection: Collection, query: string[] | object) => { |
|
|
|
let dbFindMany = (collection: Collection, query: string[] | object) => { |
|
|
|
query = wrapIdsToQuery(query); |
|
|
|
query = wrapIdsToQuery(query); |
|
|
|
return new Promise<any[]>((resolve, reject) => { |
|
|
|
return new Promise<any[]>((resolve, reject) => { |
|
|
|
db[collection].findOne(query, (err, docs) => { |
|
|
|
db.get(collection).findOne(query, (err, docs: any[]) => { |
|
|
|
if(err) { |
|
|
|
if(err) { |
|
|
|
reject(err); |
|
|
|
reject(err); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -116,7 +116,7 @@ let dbFindMany = (collection: Collection, query: string[] | object) => { |
|
|
|
let dbRemoveOne = (collection: Collection, id: string) => { |
|
|
|
let dbRemoveOne = (collection: Collection, id: string) => { |
|
|
|
let query = { _id: id }; |
|
|
|
let query = { _id: id }; |
|
|
|
return new Promise<boolean>((resolve, reject) => { |
|
|
|
return new Promise<boolean>((resolve, reject) => { |
|
|
|
db[collection].remove(query, (err, numRemoved) => { |
|
|
|
db.get(collection).remove(query, (err, numRemoved) => { |
|
|
|
if(err) { |
|
|
|
if(err) { |
|
|
|
reject(err); |
|
|
|
reject(err); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -133,7 +133,7 @@ let dbRemoveOne = (collection: Collection, id: string) => { |
|
|
|
let dbRemoveMany = (collection: Collection, query: string[] | object) => { |
|
|
|
let dbRemoveMany = (collection: Collection, query: string[] | object) => { |
|
|
|
query = wrapIdsToQuery(query); |
|
|
|
query = wrapIdsToQuery(query); |
|
|
|
return new Promise<number>((resolve, reject) => { |
|
|
|
return new Promise<number>((resolve, reject) => { |
|
|
|
db[collection].remove(query, (err, numRemoved) => { |
|
|
|
db.get(collection).remove(query, (err, numRemoved) => { |
|
|
|
if(err) { |
|
|
|
if(err) { |
|
|
|
reject(err); |
|
|
|
reject(err); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -161,5 +161,5 @@ function checkDataFolders(): void { |
|
|
|
checkDataFolders(); |
|
|
|
checkDataFolders(); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: it's better if models request db which we create if it`s needed
|
|
|
|
// TODO: it's better if models request db which we create if it`s needed
|
|
|
|
db[Collection.ANALYTIC_UNITS] = new nedb({ filename: config.ANALYTIC_UNITS_DATABASE_PATH, autoload: true }); |
|
|
|
db.set(Collection.ANALYTIC_UNITS, new nedb({ filename: config.ANALYTIC_UNITS_DATABASE_PATH, autoload: true })); |
|
|
|
db[Collection.SEGMENTS] = new nedb({ filename: config.SEGMENTS_DATABASE_PATH, autoload: true }); |
|
|
|
db.set(Collection.SEGMENTS, new nedb({ filename: config.SEGMENTS_DATABASE_PATH, autoload: true })); |
|
|
|