threefoldtecharchive / jumpscaleX_archived

Apache License 2.0
1 stars 6 forks source link

gunjs integration in JSX [development_webdb] #685

Closed despiegk closed 5 years ago

despiegk commented 5 years ago

branch: development_webdb

make example how to work with gunjs in JSX towards BCDB use j.servers.gundb and make test gevent server there

xmonader commented 5 years ago

https://github.com/threefoldtech/digitalmeX/commit/6c1cc8d4d69bbd6cdd24932252c4bdd0b2c07070

AhmedHanafy725 commented 5 years ago

jumpscaleX

branch: development_jumpscale commit: de84017b2cfdfe0479c336a298cd386d79ee883a

digitalmeX

branch: development_webdb commit: https://github.com/threefoldtech/digitalmeX/commit/4b65a9b1960d349fada260b2e3428f5ae42c9076

Following docs here

Steps:

1- Add schemas:

bcdb = j.data.bcdb.get(name="test")
bcdb.reset()
j.data.schema.add_from_text("""
@url = proj.os
name* = "" (S)
""")

j.data.schema.add_from_text("""
@url = proj.phone
model* = "" (S)
os* = "" !proj.os
""")

j.data.schema.add_from_text("""
@url = proj.human
name* = "" (S)
phone* = "" !proj.phone
""")

2- Start gun server:

j.servers.gundb._server_test_start()

3- Run js in html file in browser:

<html>
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
<script>
      var gun = Gun("ws://172.17.0.2:7766/gun")

      gun.get("proj.human://1").put({"name":"xmon"})
      gun.get("proj.human://1").get("phone").put({
          "model":"samsung"
      })
      gun.get("proj.human://1").get("phone").get("os").put({
          "name":"android"
      })

      gun.get("proj.human://2").put({"name":"richxmon"})
      gun.get("proj.human://2").get("phone").put({
          "model":"iphone"
      })
      gun.get("proj.human://2").get("phone").get("os").put({
          "name":"ios"
      })
</script>
</html>

4- Check bcdb is containing data stored by gunjs:

JSX> bcdb.get_all()                                                                                 
## {BLUE}proj.human
{RESET}{GRAY}id: 1
{RESET}{RED}name                : xmon
{RESET}favnums             : []
langs               : []
phone               : {'model': 'samsung', 'os': {'name': 'android'}}
{RESET}
## {BLUE}proj.human
{RESET}{GRAY}id: 2
{RESET}{RED}name                : richxmon
{RESET}favnums             : []
langs               : []
phone               : {'model': 'iphone', 'os': {'name': 'ios'}}
{RESET}
[, ]