aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Main.tsx3
-rw-r--r--src/Server.ts (renamed from src/Server.tsx)0
-rw-r--r--src/SocketStub.ts (renamed from src/SocketStub.tsx)0
-rw-r--r--src/database.ts41
4 files changed, 44 insertions, 0 deletions
diff --git a/src/Main.tsx b/src/Main.tsx
index fa6230393..eee8554f3 100644
--- a/src/Main.tsx
+++ b/src/Main.tsx
@@ -14,6 +14,7 @@ import { ContextMenu } from './views/ContextMenu';
import { DocumentView } from './views/nodes/DocumentView';
import { CompileScript } from './util/Scripting';
import { ImageField } from './fields/ImageField';
+import { database } from './database';
configure({
@@ -40,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/Server.tsx b/src/Server.ts
index 645420771..645420771 100644
--- a/src/Server.tsx
+++ b/src/Server.ts
diff --git a/src/SocketStub.tsx b/src/SocketStub.ts
index f9d48c067..f9d48c067 100644
--- a/src/SocketStub.tsx
+++ b/src/SocketStub.ts
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];
+ });
+ }
+}