是否可以在Node.js中使用Tinkerpop / Gremlin来操纵OrientDB中的数据?

时间:2019-02-09 06:54:23

标签: orientdb gremlin tinkerpop3

我想使用Gremlin / Tinkerpop将我的本地 Nodejs 没有JVM )应用程序连接到远程OrientDB 3.x实例。那有可能吗?怎么样?

我使用“ gremlin” npm库尝试了一下,但没有成功。

<template>
<div>
    <div id="wrapper-ingredients">
        <div id="base">
            <img src="../img/base.svg" usemap="#image-map" alt="base">
            <drop id="pizza-base" @drop="handleDrop">
                <map name="image-map" id="image-map">
                    <area target="_self" alt="pizza-base" title="pizza-base"
                          coords="133,387,93,308,79,217,119,119,168,69,231,32,308,17,381,14,448,36,489,64,526,99,555,142,576,195,586,251,575,314,546,359,488,412,416,446,317,454,205,436"
                          shape="poly">
                </map>
            </drop>
        </div>

        <div id="ingredients">
            <drag class="drag" :transfer-data="bellpepper">
                <img src="../img/bellpepper-512.png" id="bellpepper" alt="pimiento amarillo" width="512"
                     height="512">
            </drag>
            <drag class="drag" :transfer-data="cheese">
                <img src="../img/cheese-512.png" alt="queso" width="512" height="512">
            </drag>
            <drag class="drag" :transfer-data="corn">
                <img src="../img/corn-512.png" alt="maiz" width="512" height="512">
            </drag>
            <drag class="drag" :transfer-data="mushroom">
                <img src="../img/mushroom-512.png" alt="seta" width="512" height="512">
            </drag>
            <drag class="drag" :transfer-data="olive">
                <img src="../img/olive-512.png" alt="oliva" width="512" height="512">
            </drag>
            <drag class="drag" :transfer-data="onion">
                <img src="../img/onion-512.png" alt="cebolla" width="512" height="512">
            </drag>
            <drag class="drag" :transfer-data="pepperoni">
                <img src="../img/pepperoni-512.png" alt="pepperoni" width="512" height="512">
            </drag>
            <drag class="drag" :transfer-data="tomato">
                <img src="../img/tomato-512.png" alt="tomate" width="512" height="512">
            </drag>
        </div>
    </div>
    <div id="wrapper-ticket">
        <ul>
            <li v-for="ingRec in ingredientsReceipt">{{ingRec.name + " X " + ingRec.quantity}}</li>
        </ul>
    </div>
</div>
</template>
<script>
import {Ticket} from "../model/Ticket.js"
import {Bellpepper} from "../model/Bellpepper.js"
import {Cheese} from "../model/Cheese.js"
import {Corn} from "../model/Corn.js"
import {Mushroom} from "../model/Mushroom.js"
import {Olive} from "../model/Olive.js"
import {Onion} from "../model/Onion.js"
import {Pepperoni} from "../model/Pepperoni.js"
import {Tomato} from "../model/Tomato.js"
import {Drag, Drop} from 'vue-drag-drop'

export default {
    components: {Drag, Drop},
    data() {
        return {
            ingredientsReceipt: [],
            bellpepper: new Bellpepper(2),
            cheese: new Cheese(3),
            corn: new Corn(1),
            mushroom: new Mushroom(2),
            olive: new Olive(3),
            onion: new Onion(4),
            pepperoni: new Pepperoni(5),
            tomato: new Tomato(6),
            ticket: new Ticket()
        }
    },
    methods: {
        handleDrop(data) {
            let x = event.clientX
            let y = event.clientY
            let img = document.createElement("img")
            img.setAttribute('src', data.img)
            img.setAttribute('name', data.name)
            img.style.position = 'absolute'
            img.style.width = '3.5%'
            img.style.height = '7%'
            img.style.left = x - img.offsetWidth / 2 - 50 + 'px'
            img.style.top = y - img.offsetHeight / 2 - 25 + 'px'
            img.style.zIndex = '1'
            document.querySelector('#pizza-base').appendChild(img)
            if (this.ingredientsReceipt.indexOf(data) === -1) {
                this.ingredientsReceipt.push(data)
            } else {
                let x = this.ingredientsReceipt.filter(arrayItem =>
                    arrayItem.name === data.name
                )
                x[0].quantity++
                console.log(x,this.ingredientsReceipt)
            }

            //HERE IS WHERE THE PROBLEM WILL BE...

            /*
            this.ingredientsReceipt[data.name] = (this.ingredientsReceipt[data.name] || 0) + 1
            if (this.ingredientsReceipt[data.name] !== data) {
                this.ingredientsReceipt[data.name] = data

            } else {
                this.ingredientsReceipt[data.name].quantity++

            }
            */
            img.addEventListener("click", () => {
                let x = this.ingredientsReceipt.filter( arrayItem => arrayItem.name === data.name)
                if (x[0].quantity > 0) {
                    x[0].quantity--
                    img.remove()
                } else {
                    img.remove()
                    delete this.ingredientsReceipt[data.name]
                }
            })
            /*console.log(this.ingredientsReceipt)*/
        },
    },
}
</script>

并且希望它能够连接,但我却收到此错误:

const gremlin = require('gremlin');

const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const traversal = gremlin.process.traversal;
const PlainTextSaslAuthenticator = gremlin.driver.auth.PlainTextSaslAuthenticator;

const authenticator = new PlainTextSaslAuthenticator('root', 'admin');
const g = await traversal().withRemote(new DriverRemoteConnection('wss://localhost:8182/demodb', {authenticator: authenticator}));

1 个答案:

答案 0 :(得分:0)

好吧,我设法用URL ws://localhost:8182/gremlin来做到这一点,而由gremlin访问的数据库我在OrientDB文件夹的gremlin-server.yaml文件中进行了配置。