Skip to content

Commit

Permalink
Add async query support (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekim authored Jan 18, 2023
1 parent d1c18ea commit 0ab3b79
Show file tree
Hide file tree
Showing 10 changed files with 9,095 additions and 409 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: yarn install
- run: yarn build
- name: Add API_KEY to .env
Expand All @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn build
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ jobs:
os: [ubuntu-latest, macos-latest]
env:
API_KEY: ${{ secrets.API_KEY }}
RELAY_KEY: ${{ secrets.RELAY_KEY }}
RELAY_SECRET: ${{ secrets.RELAY_SECRET }}
name: Test on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up NodeJS
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- name: Install requirements
run: |
yarn install
yarn build
- name: Add API_KEY to .env
- name: Add secrets to .env
run: |
echo $API_KEY > .env
echo $RELAY_KEY >> .env
echo $RELAY_SECRET >> .env
- name: Running tests
run: |
yarn test
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

Spice.xyz client library for Node.JS

See full documentation at [docs.spice.xyz](https://docs.spice.xyz/sdks/node.js-sdk).

## Installation

`npm install @spiceai/spice` or `yarn add @spiceai/spice`

## Usage

### Arrow Query
### High-Performance Apache Arrow Flight Query

```js
import { SpiceClient } from "@spiceai/spice";
import { SpiceClient } from '@spiceai/spice';

const main = async () => {
const spiceClient = new SpiceClient("API_KEY");
const spiceClient = new SpiceClient('API_KEY');
const table = await spiceClient.query(
'SELECT number, "timestamp", gas_used FROM eth.recent_blocks LIMIT 10'
);
Expand All @@ -29,6 +31,38 @@ Querying data is done through a `SpiceClient` object that initializes the connec
- `apiKey` (string, required): API key to authenticate with the endpoint.
- `url` (string, optional): URL of the endpoint to use (default: flight.spiceai.io:443)

Read more about the Spice.xyz Apache Arrow Flight API at [docs.spice.xyz](https://docs.spice.xyz/api/sql-query-api/apache-arrow-flight-api).

### Async Query

```js
import { SpiceClient } from '@spiceai/spice';
const main = async () => {
const spiceClient = new SpiceClient('API_KEY');
const queryResp = await client.queryAsync(
'recent_blocks',
'SELECT number, "timestamp", gas_used FROM eth.recent_blocks LIMIT 10',
'https://o4skc7qyx7mrl8x7wdtgmc.hooks.webhookrelay.com'
);

if (!queryResp.ok) {
console.error('Query failed.', queryResp.status);
return;
}

// Webhook trigger with body
const queryResults = await client.getResultsFromQueryCompleteNotification(
body
);

console.log(queryResults);
};

main();
```

Read more about the Spice.xyz Async HTTP API at [docs.spice.xyz](https://docs.spice.xyz/api/sql-query-api/http-api-1).

## Documentation

Check out our [API documentation](https://docs.spice.xyz/sdks/node.js-sdk) to learn more about how to use the Node.js SDK.
Loading

0 comments on commit 0ab3b79

Please sign in to comment.