Skip to content

Commit d268dc2

Browse files
authored
use localhost instead of 127.0.0.1 in examples (#9)
* format example code use prettier for example snippets. The result is code formatted in a way more familiar way for javascript developer * use `localhost` instead of `127.0.0.1` in examples
1 parent c71c8f9 commit d268dc2

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function run() {
1818

1919
// connect to QuestDB
2020
// host and port are required in connect options
21-
await sender.connect({port: 9009, host: "127.0.0.1"});
21+
await sender.connect({port: 9009, host: "localhost"});
2222

2323
// add rows to the buffer of the sender
2424
sender.table("prices").symbol("instrument", "EURUSD")
@@ -69,7 +69,7 @@ async function run() {
6969

7070
// connect() takes an optional second argument
7171
// if 'true' passed the connection is secured with TLS encryption
72-
await sender.connect({port: 9009, host: "127.0.0.1"}, true);
72+
await sender.connect({port: 9009, host: "localhost"}, true);
7373

7474
// send the data over the authenticated and secure connection
7575
sender.table("prices").symbol("instrument", "EURUSD")
@@ -110,7 +110,7 @@ async function run(): Promise<number> {
110110

111111
// connect() takes an optional second argument
112112
// if 'true' passed the connection is secured with TLS encryption
113-
await sender.connect({port: 9009, host: "127.0.0.1"}, true);
113+
await sender.connect({port: 9009, host: "localhost"}, true);
114114

115115
// send the data over the authenticated and secure connection
116116
sender.table("prices").symbol("instrument", "EURUSD")

examples/auth.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async function run() {
66
const PRIVATE_KEY = "9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8";
77
const PUBLIC_KEY = {
88
x: "aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc",
9-
y: "__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg"
9+
y: "__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg",
1010
};
1111
const JWK = {
1212
...PUBLIC_KEY,
@@ -18,20 +18,27 @@ async function run() {
1818

1919
// pass the JsonWebKey to the sender
2020
// will use it for authentication
21-
const sender = new Sender({bufferSize: 4096, jwk: JWK});
21+
const sender = new Sender({ bufferSize: 4096, jwk: JWK });
2222

2323
// connect() takes an optional second argument
2424
// if 'true' passed the connection is secured with TLS encryption
25-
await sender.connect({port: 9009, host: "127.0.0.1"}, false);
25+
await sender.connect({ port: 9009, host: "localhost" }, false);
2626

2727
// send the data over the authenticated connection
28-
sender.table("prices").symbol("instrument", "EURUSD")
29-
.floatColumn("bid", 1.0197).floatColumn("ask", 1.0224).atNow();
28+
sender
29+
.table("prices")
30+
.symbol("instrument", "EURUSD")
31+
.floatColumn("bid", 1.0197)
32+
.floatColumn("ask", 1.0224)
33+
.atNow();
3034
await sender.flush();
3135

3236
// close the connection after all rows ingested
3337
await sender.close();
3438
return 0;
3539
}
3640

37-
run().then(value => console.log(value)).catch(err => console.log(err));
41+
run()
42+
.then((value) => console.log(value))
43+
.catch((err) => console.log(err));
44+

examples/auth_tls.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async function run() {
66
const PRIVATE_KEY = "9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8";
77
const PUBLIC_KEY = {
88
x: "aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc",
9-
y: "__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg"
9+
y: "__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg",
1010
};
1111
const JWK = {
1212
...PUBLIC_KEY,
@@ -18,20 +18,27 @@ async function run() {
1818

1919
// pass the JsonWebKey to the sender
2020
// will use it for authentication
21-
const sender = new Sender({bufferSize: 4096, jwk: JWK});
21+
const sender = new Sender({ bufferSize: 4096, jwk: JWK });
2222

2323
// connect() takes an optional second argument
2424
// if 'true' passed the connection is secured with TLS encryption
25-
await sender.connect({port: 9009, host: "127.0.0.1"}, true);
25+
await sender.connect({ port: 9009, host: "localhost" }, true);
2626

2727
// send the data over the authenticated and secure connection
28-
sender.table("prices").symbol("instrument", "EURUSD")
29-
.floatColumn("bid", 1.0197).floatColumn("ask", 1.0224).atNow();
28+
sender
29+
.table("prices")
30+
.symbol("instrument", "EURUSD")
31+
.floatColumn("bid", 1.0197)
32+
.floatColumn("ask", 1.0224)
33+
.atNow();
34+
3035
await sender.flush();
3136

3237
// close the connection after all rows ingested
3338
await sender.close();
3439
return 0;
3540
}
3641

37-
run().then(value => console.log(value)).catch(err => console.log(err));
42+
run()
43+
.then((value) => console.log(value))
44+
.catch((err) => console.log(err));

examples/basic.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,46 @@ const { Sender } = require("@questdb/nodejs-client");
22

33
async function run() {
44
// create a sender with a 4k buffer
5-
const sender = new Sender({bufferSize: 4096});
5+
const sender = new Sender({ bufferSize: 4096 });
66

77
// connect to QuestDB
88
// host and port are required in connect options
9-
await sender.connect({port: 9009, host: "127.0.0.1"});
9+
await sender.connect({ port: 9009, host: "localhost" });
1010

1111
// add rows to the buffer of the sender
12-
sender.table("prices").symbol("instrument", "EURUSD")
13-
.floatColumn("bid", 1.0195).floatColumn("ask", 1.0221).atNow();
14-
sender.table("prices").symbol("instrument", "GBPUSD")
15-
.floatColumn("bid", 1.2076).floatColumn("ask", 1.2082).atNow();
12+
sender
13+
.table("prices")
14+
.symbol("instrument", "EURUSD")
15+
.floatColumn("bid", 1.0195)
16+
.floatColumn("ask", 1.0221)
17+
.atNow();
18+
19+
sender
20+
.table("prices")
21+
.symbol("instrument", "GBPUSD")
22+
.floatColumn("bid", 1.2076)
23+
.floatColumn("ask", 1.2082)
24+
.atNow();
1625

1726
// flush the buffer of the sender, sending the data to QuestDB
1827
// the buffer is cleared after the data is sent and the sender is ready to accept new data
1928
await sender.flush();
2029

2130
// add rows to the buffer again and send it to the server
22-
sender.table("prices").symbol("instrument", "EURUSD")
23-
.floatColumn("bid", 1.0197).floatColumn("ask", 1.0224).atNow();
31+
sender
32+
.table("prices")
33+
.symbol("instrument", "EURUSD")
34+
.floatColumn("bid", 1.0197)
35+
.floatColumn("ask", 1.0224)
36+
.atNow();
37+
2438
await sender.flush();
2539

2640
// close the connection after all rows ingested
2741
await sender.close();
2842
return 0;
2943
}
3044

31-
run().then(value => console.log(value)).catch(err => console.log(err));
45+
run()
46+
.then((value) => console.log(value))
47+
.catch((err) => console.log(err));

0 commit comments

Comments
 (0)