Browse Source

doc: Modifying chat example

Matthias Ladkau 3 years ago
parent
commit
78dc8dff05

+ 3 - 2
README.md

@@ -153,6 +153,7 @@ EliasDB uses a single configuration file called eliasdb.config.json. After start
 | ECALLogFile | Logfile for ECAL interpreter. An empty string will cause the logger to write to the console. |
 | ECALLogLevel | Log level for ECAL interpreter. Can be debug, info or error. |
 | ECALScriptFolder | Directory for ECAL scripts. |
+| ECALWorkerCount | Number of worker threads in the ECA engine's thread pool. |
 | EnableAccessControl | Flag if access control for EliasDB should be enabled. This provides user authentication and authorization features. |
 | EnableCluster | Flag if EliasDB clustering support should be enabled. EXPERIMENTAL! |
 | EnableClusterTerminal | Flag if the cluster terminal file /web/db/cluster.html should be created. |
@@ -240,13 +241,13 @@ docker build --tag krotik/eliasdb .
 
 Example Applications
 --------------------
-- [Chat](examples/chat/doc/chat.md) - A simple chat application showing user management and subscriptions.
+- [Chat](examples/chat/doc/chat.md) - A simple chat application showing node modification via ECAL script, user management and subscriptions.
 - [Data-mining](examples/data-mining/doc/data-mining.md) - A more complex application which uses the cluster feature of EliasDB and GraphQL for data queries.
 - [Game](examples/game/doc/game.md) - A multiplayer game example using ECAL for simulating the game scene in the backend.
 
 Further Reading
 ---------------
-- A design document which describes the different components of the graph database. [Link](https://devt.de/krotik/eliasdb/src/master/eliasdb_design.md)
+- A design document which describes the different components of the graph database. [Link](eliasdb_design.md)
 - A reference for EliasDB's custom query language EQL. [Link](eql.md)
 - A reference for EliasDB's support for GraphQL. [Link](graphql.md)
 - A quick overview of what you can do when you embed EliasDB in your own Go project. [Link](embedding.md)

+ 2 - 1
ecal.md

@@ -8,7 +8,7 @@ ECAL was added for the following use-cases:
 - Enforce certain aspects of a database schema
 - Providing back-end logic for web applications using EliasDB
 
-The source of EliasDB comes with a [game example](examples/game/doc/game.md) which demonstrates a more complex application of ECAL.
+The source of EliasDB comes with a [chat example](examples/game/doc/chat.md) containing a simple ECAL script which adds a timestamp to nodes and a [game example](examples/game/doc/game.md) which demonstrates a more complex application of ECAL.
 
 ECAL related config values:
 --
@@ -24,6 +24,7 @@ These ECAL related config options are available in `eliasdb.config.json`:
 | EnableECALDebugServer | Enable debugging and start the ECAL debug server. Note: Activating debugging will slow down the interpreter speed significantly! |
 | ECALDebugServerHost | Host for the debug server. |
 | ECALDebugServerPort | Port for the debug server. |
+| ECALWorkerCount | Number of worker threads in the ECA engine's thread pool. |
 
 ECAL Debugging
 --

+ 1 - 0
examples/chat/doc/chat.md

@@ -1,6 +1,7 @@
 EliasDB Chat Example
 ==
 This example demonstrates a simple application which uses advanced features of EliasDB:
+- Node modification via ECAL script
 - User Management
 - GraphQL subscriptions
 

File diff suppressed because it is too large
+ 1 - 1
examples/chat/res/chat/dist/chat.js


+ 2 - 1
examples/chat/res/chat/src/component/ChatWindow.vue

@@ -16,7 +16,7 @@ Chat window which displays an ongoing chat channel.
         <div class="chat-msg-window" 
             v-for="msg in messages"
             v-bind:key="msg.key">
-                <div>{{msg.message}}</div>
+                <div>{{msg.message}} at {{new Date(msg.ts / 1000).toLocaleString()}}</div>
         </div>
         <chat-text-area :channel="channel"/>
     </div>
@@ -66,6 +66,7 @@ subscription {
   ${this.channel}(ascending:key, last:11) { # last:11 because channel node will be last
       key,
       message,
+      ts,
   }
 }`,
             data => {

+ 9 - 0
examples/chat/res/eliasdb.config.json

@@ -3,9 +3,18 @@
     "ClusterLogHistory": 100,
     "ClusterStateInfoFile": "cluster.stateinfo",
     "CookieMaxAgeSeconds": "86400",
+    "ECALDebugServerHost": "127.0.0.1",
+    "ECALDebugServerPort": "33274",
+    "ECALEntryScript": "main.ecal",
+    "ECALLogFile": "",
+    "ECALLogLevel": "info",
+    "ECALScriptFolder": "scripts",
+    "ECALWorkerCount": 10,
     "EnableAccessControl": true,
     "EnableCluster": false,
     "EnableClusterTerminal": false,
+    "EnableECALDebugServer": false,
+    "EnableECALScripts": true,
     "EnableReadOnly": false,
     "EnableWebFolder": true,
     "EnableWebTerminal": false,

+ 21 - 0
examples/chat/res/scripts/main.ecal

@@ -0,0 +1,21 @@
+/*
+ Modify all stored nodes which have a message with a timestamp.
+ */
+sink AddNodeTimestamp
+    kindmatch ["db.node.store", "db.node.update"]
+    priority 0
+{
+    log("Node Event: ", event)
+
+    if event.state.node.message != NULL and event.state.node.ts == NULL {
+        try {
+            log("store node")
+            event.state.node.ts := now()
+            db.storeNode(event.state.part, event.state.node)
+        } except e {
+            error(e)
+        } otherwise {
+            db.raiseGraphEventHandled()
+        }
+    }
+}

+ 2 - 0
examples/chat/start.bat

@@ -5,7 +5,9 @@ if NOT EXIST run (
   mkdir run
   cd run
   mkdir web
+  mkdir scripts
   xcopy /e ..\res\chat\* web
+  xcopy /e ..\res\scripts\* scrips
   copy ..\res\eliasdb.config.json .
   copy ..\res\access.db .
   cd ..  

+ 2 - 0
examples/chat/start.sh

@@ -3,7 +3,9 @@ cd "$(dirname "$0")"
 
 if ! [ -d "run" ]; then
   mkdir -p run/web
+  mkdir -p run/scripts
   cp -fR res/chat/* run/web
+  cp -fR res/scripts/* run/scripts
   cp -fR res/eliasdb.config.json run
   cp -fR res/access.db run
 fi