forked from hull-ships/hull-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesystem.js
More file actions
105 lines (91 loc) · 1.82 KB
/
filesystem.js
File metadata and controls
105 lines (91 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Module dependencies.
*/
import Promise from "bluebird";
import fs from "fs";
import JSONStream from "JSONStream";
/**
* File system adapter.
*/
/**
* Open a new connection.
*
* Params:
* @connection_string String*
*
* Return:
* @client Instance
*/
export function openConnection() {}
/**
* Close the connection.
*
* Params:
* @client Instance
*/
export function closeConnection() {}
/**
* Wrap the user query
* inside a PostgreSQL request.
*
* Params:
* @query String*
* @last_updated_at String
*
* Return:
* @wrappedQuery String
*/
export function wrapQuery(query) {
return query;
}
export function cancelQuery() {}
/**
* Run a wrapped query.
*
* Params:
* @client Instance*
* @wrappedQuery String*
* @callback Function*
*
* Return:
* @callback Function
* - @error Object
* - @rows Array
*/
export function runQuery(client, query = {}) {
return new Promise((resolve) => {
return resolve(query);
});
}
/**
* Stream a wrapped query.
*
* Params:
* @client Instance*
* @wrappedQuery String*
* @callback Function*
*
* Return:
* @callback Function
* - @error Object
* - @stream Stream
*/
export function streamQuery(client, query) {
return new Promise((resolve) => {
const stream = fs.createReadStream(query).pipe(JSONStream.parse());
resolve(stream);
return stream;
});
}
export function upload(users, shipId, partNumber) {
const data = users.map(user => JSON.stringify(user)).join("\n");
return new Promise((resolve, reject) => {
const filename = `tests/extracts/${new Date().getTime()}-${partNumber}.json`;
fs.writeFile(filename, data, (err) => {
if (err) {
return reject(err);
}
return resolve({ url: `http://fake.url/${filename}`, partNumber, size: users.length });
});
});
}