-
-
Notifications
You must be signed in to change notification settings - Fork 668
Expand file tree
/
Copy pathinit_db.js
More file actions
50 lines (45 loc) · 1.3 KB
/
init_db.js
File metadata and controls
50 lines (45 loc) · 1.3 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
'use strict';
const Command = require('../command.js');
const { sendResult, sendError } = require('./send_result.js');
class ServerInitDb extends Command {
constructor(handler) {
super();
this._handler = handler;
}
start(packet, connection) {
packet.readInt8();
const encoding =
(connection.clientHelloReply && connection.clientHelloReply.encoding) ||
'utf8';
const schemaName = packet.readString(undefined, encoding);
let result;
try {
result = this._handler(schemaName);
} catch (err) {
sendError(connection, err);
return null;
}
if (result && typeof result.then === 'function') {
result
.then(() => sendResult(connection, undefined))
.catch((err) => sendError(connection, err))
.then(() => {
this.next = null;
this.emit('end');
connection._command = connection._commands.shift();
if (connection._command) {
connection.sequenceId = 0;
connection.compressedSequenceId = 0;
connection.handlePacket();
}
});
return ServerInitDb.prototype._awaitResult;
}
sendResult(connection, undefined);
return null;
}
_awaitResult() {
return ServerInitDb.prototype._awaitResult;
}
}
module.exports = ServerInitDb;