diff options
author | yipstanley <stanley_yip@brown.edu> | 2019-02-11 17:29:30 -0500 |
---|---|---|
committer | yipstanley <stanley_yip@brown.edu> | 2019-02-11 17:29:30 -0500 |
commit | 448f8880b50dc50090a596cafaf68d2f444ce3db (patch) | |
tree | 025ad6877131f51a9c419bc8c5316254e31521b5 /src | |
parent | a33f178285505db54549ad3cec313daa914dc6e8 (diff) | |
parent | 1eb3d60457d4fc0ae957832c3ab751b54a24cc21 (diff) |
Merge branch 'database' of https://github.com/browngraphicslab/Dash-Web into server_database_merge
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/Main.tsx | 4 | ||||
-rw-r--r-- | src/database.ts | 41 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 9a359e868..da3576066 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -13,6 +13,8 @@ import "./Main.scss"; import { ContextMenu } from './ContextMenu'; import { DocumentView } from './nodes/DocumentView'; import { ImageField } from '../../fields/ImageField'; +import { CompileScript } from './util/Scripting'; +import { database } from './database'; configure({ @@ -39,6 +41,8 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) { //runInAction(() => { + let db = new database(); + db.update('1', '2', '3'); let doc1 = Documents.TextDocument({ title: "hello" }); let doc2 = doc1.MakeDelegate(); doc2.Set(KS.X, new NumberField(150)); diff --git a/src/database.ts b/src/database.ts new file mode 100644 index 000000000..a822b15bf --- /dev/null +++ b/src/database.ts @@ -0,0 +1,41 @@ +import { action, configure } from 'mobx'; +import * as mongodb from 'mongodb'; + +export class database { + private MongoClient = mongodb.MongoClient; + private url = 'mongodb://localhost:27017/website'; + + public update(id: string, field: string, value: string) { + this.MongoClient.connect(this.url, (err, db) => { + let collection = db.db().collection('documents'); + collection.update({ "id": id }, { $set: { field: 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: JSON) { + this.MongoClient.connect(this.url, (err, db) => { + let collection = db.db().collection('documents'); + collection.insert(kvpairs, () => { }); + db.close(); + }); + } + + public getDocument(id: string) { + var result: Array<JSON>; + this.MongoClient.connect(this.url, (err, db) => { + let collection = db.db().collection('documents'); + collection.find({ "id": id }).toArray((err, db) => { result = db }); + db.close(); + return result[0]; + }); + } +} |