Skip to content

Commit

Permalink
chore(nodejs): regenerate docs (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz authored Aug 13, 2024
1 parent 92fd173 commit 1509446
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 70 deletions.
2 changes: 1 addition & 1 deletion docs/Sender.html
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
<br class="clear">

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/SenderOptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
<br class="clear">

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
137 changes: 71 additions & 66 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,149 +56,154 @@ <h2>Examples</h2>
<p>The examples below demonstrate how to use the client. <br>
For more details, please, check the <a href="Sender.html">Sender</a>'s documentation.</p>
<h3>Basic API usage</h3>
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require('@questdb/nodejs-client');
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require(&quot;@questdb/nodejs-client&quot;)

async function run() {
// create a sender using HTTP protocol
const sender = Sender.fromConfig('http::addr=localhost:9000');

// add rows to the buffer of the sender
await sender.table('prices').symbol('instrument', 'EURUSD')
.floatColumn('bid', 1.0195).floatColumn('ask', 1.0221)
.at(Date.now(), 'ms');
await sender.table('prices').symbol('instrument', 'GBPUSD')
.floatColumn('bid', 1.2076).floatColumn('ask', 1.2082)
.at(Date.now(), 'ms');

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

// add rows to the buffer again, and send it to the server
await sender.table('prices').symbol('instrument', 'EURUSD')
.floatColumn('bid', 1.0197).floatColumn('ask', 1.0224)
.at(Date.now(), 'ms');
await sender.flush();

// close the connection after all rows ingested
await sender.close();
// create a sender using HTTP protocol
const sender = Sender.fromConfig(&quot;http::addr=127.0.0.1:9000&quot;)

// add rows to the buffer of the sender
await sender
.table(&quot;trades&quot;)
.symbol(&quot;symbol&quot;, &quot;ETH-USD&quot;)
.symbol(&quot;side&quot;, &quot;sell&quot;)
.floatColumn(&quot;price&quot;, 2615.54)
.floatColumn(&quot;amount&quot;, 0.00044)
.at(Date.now(), &quot;ms&quot;)

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

// close the connection after all rows ingested
// unflushed data will be lost
await sender.close()
}

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

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

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

// close the connection after all rows ingested
await sender.close();
await sender.close()
}

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

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

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

// close the connection after all rows ingested
await sender.close();
await sender.close()
}

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

// fake venue
// generates random prices for a ticker for max 5 seconds, then the feed closes
// generates random prices and amounts for a ticker for max 5 seconds, then the feed closes
function* venue(ticker) {
let end = false;
setTimeout(() => { end = true; }, rndInt(5000));
let end = false
setTimeout(() => { end = true; }, rndInt(5000))
while (!end) {
yield {'ticker': ticker, 'price': Math.random()};
yield {ticker, price: Math.random(), amount: Math.random()}
}
}

// market data feed simulator
// uses the fake venue to deliver price updates to the feed handler (onTick() callback)
// uses the fake venue to deliver price and amount updates to the feed handler (onTick() callback)
async function subscribe(ticker, onTick) {
const feed = venue(workerData.ticker);
const feed = venue(workerData.ticker)
let tick;
while (tick = feed.next().value) {
await onTick(tick);
await sleep(rndInt(30));
await onTick(tick)
await sleep(rndInt(30))
}
}

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

// subscribe for the market data of the ticker assigned to the worker
// ingest each price update into the database using the sender
let count = 0;
await subscribe(workerData.ticker, async (tick) => {
await sender
.table('prices')
.symbol('ticker', tick.ticker)
.floatColumn('price', tick.price)
.at(Date.now(), 'ms');
.table(&quot;trades&quot;)
.symbol(&quot;symbol&quot;, tick.ticker)
.symbol(&quot;side&quot;, &quot;sell&quot;)
.floatColumn(&quot;price&quot;, tick.price)
.floatColumn(&quot;amount&quot;, tick.amount)
.at(Date.now(), &quot;ms&quot;)
await sender.flush();
count++;
});

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

// close the connection to the database
await sender.close();
await sender.close()
}
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise(resolve => setTimeout(resolve, ms))
}

function rndInt(limit) {
return Math.floor((Math.random() * limit) + 1);
return Math.floor((Math.random() * limit) + 1)
}

run()
.then(console.log)
.catch(console.error);
.catch(console.error)
</code></pre></article>
</section>

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

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/options.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
<br class="clear">

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/sender.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sender.ht
<br class="clear">

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down

0 comments on commit 1509446

Please sign in to comment.