aboutsummaryrefslogtreecommitdiff
path: root/src/server/database.ts
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-02-13 16:38:09 -0500
committeryipstanley <stanley_yip@brown.edu>2019-02-13 16:38:09 -0500
commit430878f6dd8d36b1322e15d0898ada0d44fecacb (patch)
tree027fb9b578a3fee8d97b16922a930806da00afaa /src/server/database.ts
parent2eb147ab8f25e6dd90f47cf21499c7340642f0c9 (diff)
Asdfjkla/sdfklj
Diffstat (limited to 'src/server/database.ts')
-rw-r--r--src/server/database.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/server/database.ts b/src/server/database.ts
new file mode 100644
index 000000000..72ddbc82c
--- /dev/null
+++ b/src/server/database.ts
@@ -0,0 +1,60 @@
+import { action, configure } from 'mobx';
+import * as mongodb from 'mongodb';
+import { ObjectID } from 'mongodb';
+import { Transferable } from './Message';
+import { Utils } from '../Utils';
+
+export class Database {
+ public static Instance = new Database()
+ private MongoClient = mongodb.MongoClient;
+ private url = 'mongodb://localhost:27017/Dash';
+
+ public update(id: mongodb.ObjectID, value: any) {
+ this.MongoClient.connect(this.url, (err, db) => {
+ let collection = db.db().collection('documents');
+ collection.update({ _id: id }, { $set: value });
+ db.close();
+ });
+ }
+
+ public delete(id: string) {
+ this.MongoClient.connect(this.url, (err, db) => {
+ let collection = db.db().collection('documents');
+ collection.remove({ _id: id });
+ db.close();
+ });
+ }
+
+ public insert(kvpairs: any) {
+ this.MongoClient.connect(this.url, (err, db) => {
+ let collection = db.db().collection('documents');
+ collection.insertOne(kvpairs, () => { });
+ db.close();
+ });
+ }
+
+ public getDocument(id: mongodb.ObjectID): string | undefined {
+ var result: JSON;
+ this.MongoClient.connect(this.url, (err, db) => {
+ if (err) {
+ console.log(err)
+ return undefined
+ }
+ let collection = db.db().collection('documents');
+ collection.findOne({ _id: Utils.GenerateDeterministicGuid(id.toHexString()) }, (err: any, res: any) => result = res)
+ console.log(result)
+ db.close();
+ if (!result) {
+ console.log("not found")
+ return undefined
+ }
+ console.log("found")
+ return result;
+ });
+ return undefined
+ }
+
+ public print() {
+ console.log("db says hi!")
+ }
+}