-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsimple-http.js
More file actions
executable file
·44 lines (40 loc) · 1.45 KB
/
simple-http.js
File metadata and controls
executable file
·44 lines (40 loc) · 1.45 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
const http = require('http')
const hostname = 'localhost'
const port = 2020
const { TestEnv } = require('../../test/env/test-env')
const env = new TestEnv()
const connectionString = env.connectionString
const query = 'select top 50 object_name(c.object_id), (select dc.definition from sys.default_constraints as dc where dc.object_id = c.default_object_id) as DefaultValueExpression from sys.columns as c'
async function test (request, response) {
response.statusCode = 200
response.setHeader('Content-Type', 'text/plain')
console.log('>> test')
try {
console.log('sqlOpen ....')
const connection = await env.sql.promises.open(connectionString)
console.log('..... sqlOpen')
try {
const d = new Date()
console.log('connectionQuery 1 ....')
const data = await connection.promises.query(query)
console.log('... connectionQuery 1')
const elapsed = new Date() - d
console.log(`rows.length ${data.first.length} elapsed ${elapsed}`)
response.end(JSON.stringify(data, null, 4))
console.log('close ...')
await connection.promises.close()
console.log('... close')
console.log('<< test')
} catch (err) {
response.end(err.message)
}
} catch (err) {
response.end(err.message)
}
}
const httpServer = http.createServer((request, response) => {
test(request, response)
})
httpServer.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`)
})