2017-07-06 49 views
0

我需要将orientDB连接到我的angularJS登录Web应用程序。 登录后用户被允许将一些数据发送到Web应用程序,这些数据也需要存储在东方DB数据库中。 所以我需要数据库,我angularJS Web应用程序连接并使用数据库来存储和检索数据,如何将orientDB连接到angularJS Web应用程序

+0

到目前为止你做了什么?你的问题没有显示任何努力,而且太笼统了。 – cccross

+0

@cccross我创建了使用angularJs(没有控制器)的web应用程序,这是我第一次尝试nosql数据库,它对我来说有点困难。我创建了数据库和顶点 (我对angularJs和orientDB都是新手) –

+0

从这一个中获得灵感:https://github.com/gauravdhiman/sailsjs-angularjs-orientdb-poc –

回答

0

这是一个示例Angular2服务连接到OrientDB

import {Injectable} from "@angular/core"; 
import {Headers, Http} from '@angular/http'; 

@Injectable() 
export class OrientService { 

    url = "http://localhost:2480/command/yourDbName/" 
    username = "admin"; 
    password = "admin"; 

    constructor(private http: Http) { 
    } 

    command(statement: string, success: (data: any) => void, error: (err: any) => void): void { 
    var url = this.url + "sql/-/-1" 
    var headers = new Headers(); 
    headers.append("Authorization", "Basic " + btoa(this.username + ":" +  this.password)); 

    this.http.post(url, 
     JSON.stringify({"command": statement}), 
     {headers: headers}) 
     .toPromise() 
     .then(success) 
     .catch(error); 
    } 
} 

然后你就可以按如下方式使用它:

this.orientService.command(
     "SELECT FROM V", 
     (res) => { 
     let body = res.json(); 
     ... 
     }, 
     (e) => { 
     console.log(e) 
     }); 

在这里你可以找到一个完整的例子:https://github.com/luigidellaquila/geospatial-demo/tree/geeconprague2016

想想看,你将不得不EN在OrientDB中能交叉点的请求https://orientdb.com/docs/2.2/Web-Server.html

相关问题