File

src/app/db-connection.service.ts

Index

Properties
Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

Async executeQuery
executeQuery(query: string)

sends a http POST request to the backend containing a query

Parameters :
Name Type Optional
query string No
Returns : unknown

promise

Properties

backendPort
Type : number
Default value : 3000
url
Default value : environment.baseUrlApi
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {environment} from '../environments/environment'

@Injectable({
  providedIn: 'root'
})
export class DbConnectionService {

  backendPort = 3000;
  url = environment.baseUrlApi;

  constructor(private http: HttpClient) {
  }

  /**
   * sends a http POST request to the backend containing a query
   * @param query
   * @returns promise
   */
  async executeQuery(query: string){
    return this.http.post(this.url, {'query': query}).toPromise().then(r => {
      if (r["error"]) // error handling
        return alert(`Error when connecting to database\n${r["error"]}`)
      return r // forward response
    });
  }


}

results matching ""

    No results matching ""