|
1 | | -const redis = require('redis'), |
2 | | -util = require('util'), |
3 | | -ResultSet = require('./resultSet'); |
| 1 | +const redis = require("redis"), |
| 2 | + util = require("util"), |
| 3 | + ResultSet = require("./resultSet"); |
4 | 4 |
|
5 | 5 | /** |
6 | 6 | * RedisGraph client |
7 | 7 | */ |
8 | | -module.exports = class RedisGraph { |
9 | | - |
| 8 | +class RedisGraph { |
10 | 9 | /** |
11 | 10 | * Creates a client to a specific graph running on the specific host/post |
12 | | - * See: node_redis for more options on createClient |
| 11 | + * See: node_redis for more options on createClient |
13 | 12 | * |
14 | 13 | * @param graphId the graph id |
15 | 14 | * @param host Redis host or node_redis client |
16 | 15 | * @param port Redis port |
17 | 16 | * @param options node_redis options |
18 | 17 | */ |
19 | 18 | constructor(graphId, host, port, options) { |
20 | | - this._graphId = graphId; |
21 | | - let client = (host instanceof redis.RedisClient) ? host : redis.createClient.apply(redis, [].slice.call(arguments,1)); |
| 19 | + this._graphId = graphId; |
| 20 | + let client = |
| 21 | + host instanceof redis.RedisClient |
| 22 | + ? host |
| 23 | + : redis.createClient.apply(redis, [].slice.call(arguments, 1)); |
22 | 24 | this._sendCommand = util.promisify(client.send_command).bind(client); |
23 | 25 | } |
24 | | - |
| 26 | + |
25 | 27 | /** |
26 | 28 | * Execute a Cypher query |
27 | | - * |
| 29 | + * |
28 | 30 | * @param query Cypher query |
29 | | - * @return a result set |
| 31 | + * @return a result set |
30 | 32 | */ |
31 | | - query(query) { |
32 | | - return this._sendCommand('graph.QUERY',[this._graphId, query]) |
33 | | - .then((res) => { |
34 | | - return new ResultSet(res); |
35 | | - }); |
| 33 | + query(query) { |
| 34 | + return this._sendCommand("graph.QUERY", [this._graphId, query]).then( |
| 35 | + res => { |
| 36 | + return new ResultSet(res); |
| 37 | + } |
| 38 | + ); |
36 | 39 | } |
37 | | - |
38 | | - /** |
39 | | - * Deletes the entire graph |
40 | | - * |
41 | | - * @return delete running time statistics |
42 | | - */ |
43 | | - deleteGraph() { |
44 | | - return this._sendCommand('graph.DELETE',[this._graphId]) |
45 | | - .then((res) => { |
| 40 | + |
| 41 | + /** |
| 42 | + * Deletes the entire graph |
| 43 | + * |
| 44 | + * @return delete running time statistics |
| 45 | + */ |
| 46 | + deleteGraph() { |
| 47 | + return this._sendCommand("graph.DELETE", [this._graphId]).then(res => { |
46 | 48 | return new ResultSet(res); |
47 | 49 | }); |
48 | | - } |
49 | | - |
50 | | -}; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +module.exports = RedisGraph; |
0 commit comments