Skip to content

Commit 1509446

Browse files
authored
chore(nodejs): regenerate docs (#37)
1 parent 92fd173 commit 1509446

File tree

5 files changed

+75
-70
lines changed

5 files changed

+75
-70
lines changed

docs/Sender.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2827,7 +2827,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
28272827
<br class="clear">
28282828

28292829
<footer>
2830-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Apr 29 2024 20:05:17 GMT+0100 (British Summer Time)
2830+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Aug 13 2024 14:27:30 GMT+0300 (Eastern European Summer Time)
28312831
</footer>
28322832

28332833
<script> prettyPrint(); </script>

docs/SenderOptions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
690690
<br class="clear">
691691

692692
<footer>
693-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Apr 29 2024 20:05:17 GMT+0100 (British Summer Time)
693+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Aug 13 2024 14:27:30 GMT+0300 (Eastern European Summer Time)
694694
</footer>
695695

696696
<script> prettyPrint(); </script>

docs/index.html

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -56,149 +56,154 @@ <h2>Examples</h2>
5656
<p>The examples below demonstrate how to use the client. <br>
5757
For more details, please, check the <a href="Sender.html">Sender</a>'s documentation.</p>
5858
<h3>Basic API usage</h3>
59-
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require('@questdb/nodejs-client');
59+
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require(&quot;@questdb/nodejs-client&quot;)
6060

6161
async function run() {
62-
// create a sender using HTTP protocol
63-
const sender = Sender.fromConfig('http::addr=localhost:9000');
64-
65-
// add rows to the buffer of the sender
66-
await sender.table('prices').symbol('instrument', 'EURUSD')
67-
.floatColumn('bid', 1.0195).floatColumn('ask', 1.0221)
68-
.at(Date.now(), 'ms');
69-
await sender.table('prices').symbol('instrument', 'GBPUSD')
70-
.floatColumn('bid', 1.2076).floatColumn('ask', 1.2082)
71-
.at(Date.now(), 'ms');
72-
73-
// flush the buffer of the sender, sending the data to QuestDB
74-
// the buffer is cleared after the data is sent, and the sender is ready to accept new data
75-
await sender.flush();
76-
77-
// add rows to the buffer again, and send it to the server
78-
await sender.table('prices').symbol('instrument', 'EURUSD')
79-
.floatColumn('bid', 1.0197).floatColumn('ask', 1.0224)
80-
.at(Date.now(), 'ms');
81-
await sender.flush();
82-
83-
// close the connection after all rows ingested
84-
await sender.close();
62+
// create a sender using HTTP protocol
63+
const sender = Sender.fromConfig(&quot;http::addr=127.0.0.1:9000&quot;)
64+
65+
// add rows to the buffer of the sender
66+
await sender
67+
.table(&quot;trades&quot;)
68+
.symbol(&quot;symbol&quot;, &quot;ETH-USD&quot;)
69+
.symbol(&quot;side&quot;, &quot;sell&quot;)
70+
.floatColumn(&quot;price&quot;, 2615.54)
71+
.floatColumn(&quot;amount&quot;, 0.00044)
72+
.at(Date.now(), &quot;ms&quot;)
73+
74+
// flush the buffer of the sender, sending the data to QuestDB
75+
// the buffer is cleared after the data is sent, and the sender is ready to accept new data
76+
await sender.flush()
77+
78+
// close the connection after all rows ingested
79+
// unflushed data will be lost
80+
await sender.close()
8581
}
8682

87-
run()
88-
.then(console.log)
89-
.catch(console.error);
83+
run().then(console.log).catch(console.error)
9084
</code></pre>
9185
<h3>Authentication and secure connection</h3>
92-
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require('@questdb/nodejs-client');
86+
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require(&quot;@questdb/nodejs-client&quot;)
9387

9488
async function run() {
9589
// create a sender using HTTPS protocol with username and password authentication
96-
const sender = Sender.fromConfig('https::addr=localhost:9000;username=user1;password=pwd');
90+
const sender = Sender.fromConfig(&quot;https::addr=127.0.0.1:9000;username=admin;password=quest;&quot;)
9791

9892
// send the data over the authenticated and secure connection
99-
await sender.table('prices').symbol('instrument', 'EURUSD')
100-
.floatColumn('bid', 1.0197).floatColumn('ask', 1.0224)
101-
.at(Date.now(), 'ms');
102-
await sender.flush();
93+
await sender
94+
.table(&quot;trades&quot;)
95+
.symbol(&quot;symbol&quot;, &quot;ETH-USD&quot;)
96+
.symbol(&quot;side&quot;, &quot;sell&quot;)
97+
.floatColumn(&quot;price&quot;, 2615.54)
98+
.floatColumn(&quot;amount&quot;, 0.00044)
99+
.at(Date.now(), &quot;ms&quot;)
100+
await sender.flush()
103101

104102
// close the connection after all rows ingested
105-
await sender.close();
103+
await sender.close()
106104
}
107105

108-
run().catch(console.error);
106+
run().catch(console.error)
109107
</code></pre>
110108
<h3>TypeScript example</h3>
111-
<pre class="prettyprint source lang-typescript"><code>import { Sender } from '@questdb/nodejs-client';
109+
<pre class="prettyprint source lang-typescript"><code>import { Sender } from &quot;@questdb/nodejs-client&quot;
112110

113-
async function run(): Promise&lt;number> {
111+
async function run(): Promise&lt;void> {
114112
// create a sender using HTTPS protocol with bearer token authentication
115-
const sender: Sender = Sender.fromConfig('https::addr=localhost:9000;token=Xyvd3er6GF87ysaHk');
113+
const sender: Sender = Sender.fromConfig(&quot;https::addr=127.0.0.1:9000;token=Xyvd3er6GF87ysaHk;&quot;)
116114

117115
// send the data over the authenticated and secure connection
118-
sender.table('prices').symbol('instrument', 'EURUSD')
119-
.floatColumn('bid', 1.0197).floatColumn('ask', 1.0224).at(Date.now(), 'ms');
120-
await sender.flush();
116+
await sender
117+
.table(&quot;trades&quot;)
118+
.symbol(&quot;symbol&quot;, &quot;ETH-USD&quot;)
119+
.symbol(&quot;side&quot;, &quot;sell&quot;)
120+
.floatColumn(&quot;price&quot;, 2615.54)
121+
.floatColumn(&quot;amount&quot;, 0.00044)
122+
.at(Date.now(), &quot;ms&quot;)
123+
await sender.flush()
121124

122125
// close the connection after all rows ingested
123-
await sender.close();
126+
await sender.close()
124127
}
125128

126129
run().catch(console.error);
127130
</code></pre>
128131
<h3>Worker threads example</h3>
129-
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require('@questdb/nodejs-client');
130-
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
132+
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require(&quot;@questdb/nodejs-client&quot;)
133+
const { Worker, isMainThread, parentPort, workerData } = require(&quot;worker_threads&quot;)
131134

132135
// fake venue
133-
// generates random prices for a ticker for max 5 seconds, then the feed closes
136+
// generates random prices and amounts for a ticker for max 5 seconds, then the feed closes
134137
function* venue(ticker) {
135-
let end = false;
136-
setTimeout(() => { end = true; }, rndInt(5000));
138+
let end = false
139+
setTimeout(() => { end = true; }, rndInt(5000))
137140
while (!end) {
138-
yield {'ticker': ticker, 'price': Math.random()};
141+
yield {ticker, price: Math.random(), amount: Math.random()}
139142
}
140143
}
141144

142145
// market data feed simulator
143-
// uses the fake venue to deliver price updates to the feed handler (onTick() callback)
146+
// uses the fake venue to deliver price and amount updates to the feed handler (onTick() callback)
144147
async function subscribe(ticker, onTick) {
145-
const feed = venue(workerData.ticker);
148+
const feed = venue(workerData.ticker)
146149
let tick;
147150
while (tick = feed.next().value) {
148-
await onTick(tick);
149-
await sleep(rndInt(30));
151+
await onTick(tick)
152+
await sleep(rndInt(30))
150153
}
151154
}
152155

153156
async function run() {
154157
if (isMainThread) {
155-
const tickers = ['t1', 't2', 't3', 't4'];
158+
const tickers = [&quot;ETH-USD&quot;, &quot;BTC-USD&quot;, &quot;SOL-USD&quot;, &quot;DOGE-USD&quot;]
156159
// main thread to start a worker thread for each ticker
157-
for (let ticker in tickers) {
160+
for (let ticker of tickers) {
158161
const worker = new Worker(__filename, { workerData: { ticker: ticker } })
159162
.on('error', (err) => { throw err; })
160163
.on('exit', () => { console.log(`${ticker} thread exiting...`); })
161164
.on('message', (msg) => {
162-
console.log(`Ingested ${msg.count} prices for ticker ${msg.ticker}`);
165+
console.log(`Ingested ${msg.count} prices for ticker ${msg.ticker}`)
163166
});
164167
}
165168
} else {
166169
// it is important that each worker has a dedicated sender object
167170
// threads cannot share the sender because they would write into the same buffer
168-
const sender = Sender.fromConfig('http::addr=localhost:9000');
171+
const sender = Sender.fromConfig(&quot;http::addr=127.0.0.1:9000&quot;);
169172

170173
// subscribe for the market data of the ticker assigned to the worker
171174
// ingest each price update into the database using the sender
172175
let count = 0;
173176
await subscribe(workerData.ticker, async (tick) => {
174177
await sender
175-
.table('prices')
176-
.symbol('ticker', tick.ticker)
177-
.floatColumn('price', tick.price)
178-
.at(Date.now(), 'ms');
178+
.table(&quot;trades&quot;)
179+
.symbol(&quot;symbol&quot;, tick.ticker)
180+
.symbol(&quot;side&quot;, &quot;sell&quot;)
181+
.floatColumn(&quot;price&quot;, tick.price)
182+
.floatColumn(&quot;amount&quot;, tick.amount)
183+
.at(Date.now(), &quot;ms&quot;)
179184
await sender.flush();
180185
count++;
181186
});
182187

183188
// let the main thread know how many prices were ingested
184-
parentPort.postMessage({'ticker': workerData.ticker, 'count': count});
189+
parentPort.postMessage({ticker: workerData.ticker, count})
185190

186191
// close the connection to the database
187-
await sender.close();
192+
await sender.close()
188193
}
189194
}
190195

191196
function sleep(ms) {
192-
return new Promise(resolve => setTimeout(resolve, ms));
197+
return new Promise(resolve => setTimeout(resolve, ms))
193198
}
194199

195200
function rndInt(limit) {
196-
return Math.floor((Math.random() * limit) + 1);
201+
return Math.floor((Math.random() * limit) + 1)
197202
}
198203

199204
run()
200205
.then(console.log)
201-
.catch(console.error);
206+
.catch(console.error)
202207
</code></pre></article>
203208
</section>
204209

@@ -216,7 +221,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
216221
<br class="clear">
217222

218223
<footer>
219-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Apr 29 2024 20:05:17 GMT+0100 (British Summer Time)
224+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Aug 13 2024 14:27:30 GMT+0300 (Eastern European Summer Time)
220225
</footer>
221226

222227
<script> prettyPrint(); </script>

docs/options.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
458458
<br class="clear">
459459

460460
<footer>
461-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Apr 29 2024 20:05:17 GMT+0100 (British Summer Time)
461+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Aug 13 2024 14:27:30 GMT+0300 (Eastern European Summer Time)
462462
</footer>
463463

464464
<script> prettyPrint(); </script>

docs/sender.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
10051005
<br class="clear">
10061006

10071007
<footer>
1008-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Apr 29 2024 20:05:17 GMT+0100 (British Summer Time)
1008+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Aug 13 2024 14:27:30 GMT+0300 (Eastern European Summer Time)
10091009
</footer>
10101010

10111011
<script> prettyPrint(); </script>

0 commit comments

Comments
 (0)