|
1 | | -# Presto JS Client |
| 1 | +# presto-client |
2 | 2 |
|
3 | | -This is a Presto JavaScript client that connects to Presto via Presto's REST API to run queries. |
| 3 | +This monorepo was generated with [Nx](https://nx.dev). |
4 | 4 |
|
5 | | -## Installation |
| 5 | +## Presto JS Client |
6 | 6 |
|
7 | | -```sh |
8 | | -npm install @prestodb/presto-js-client |
9 | | -``` |
| 7 | +For information on the Presto JS Client check its [README](presto-client/README.md) file under presto-client. |
10 | 8 |
|
11 | | -## Usage |
| 9 | +## Contributing |
12 | 10 |
|
13 | | -Import the PrestoClient class from `@prestodb/presto-js-client`. |
14 | | - |
15 | | -Create a new instance by passing the connection parameters. |
16 | | - |
17 | | -### Example |
18 | | - |
19 | | -```typescript |
20 | | -import PrestoClient from '@prestodb/presto-js-client' |
21 | | - |
22 | | -... |
23 | | - |
24 | | -const client = PrestoClient({ |
25 | | - catalog: 'tpcs', |
26 | | - host: 'localhost', |
27 | | - interval: 0, |
28 | | - port: 8080, |
29 | | - schema: 'tiny', |
30 | | - timezone: 'America/Costa_Rica', |
31 | | - user: 'root' |
32 | | -}) |
33 | | -``` |
34 | | - |
35 | | -### Parameters |
36 | | - |
37 | | -The Presto client can be configured with the following parameters: |
38 | | - |
39 | | -- `host`: The hostname or IP address of the Presto coordinator. (Default: `http://localhost`) |
40 | | -- `port`: The port number of the Presto coordinator. (Default: `8080`) |
41 | | -- `user`: The username to use for authentication. (Default: `undefined`) |
42 | | -- `catalog`: The default catalog to use for queries. (Default: `undefined`) |
43 | | -- `schema`: The default schema to use for queries. (Default: `undefined`) |
44 | | -- `source`: The name of the source you want to use for reporting purposes (Default: `presto-js-client`) |
45 | | -- `timezone`: The timezone to use for queries. (Default: `undefined`) |
46 | | -- `interval`: The interval in milliseconds between checks for the status of a running query. (Default: `100`) |
47 | | - |
48 | | -## Querying |
49 | | - |
50 | | -The `query` method takes a single `string` parameter, which is the SQL query to be executed. The method returns a PrestoQuery object, which contains the results of the query, including the columns, data, and query ID. If the query fails, the `query` method will throw an error. |
51 | | - |
52 | | -The `string` parameter to the `query` method must be a valid SQL query. The query can be any type of SQL query, including `SELECT`, `INSERT`, `UPDATE`, and `DELETE` statements. |
53 | | - |
54 | | -### Return data structure (or error state) |
55 | | - |
56 | | -The `query` method returns a PrestoQuery object, which contains the results of the query, including the columns, data, and query ID. |
57 | | - |
58 | | -If the query succeeds, the PrestoQuery object will have the following properties: |
59 | | - |
60 | | -- `columns`: An array of objects that describe the columns in the results. |
61 | | -- `data`: An array of arrays that contain the actual data for the results. |
62 | | -- `queryId`: The ID of the query. |
63 | | - |
64 | | -If the query fails, the PrestoQuery object will have the following properties: |
65 | | - |
66 | | -- `error`: An object that contains information about the error. |
67 | | -- `queryId`: The ID of the query. |
68 | | - |
69 | | -You can use the `error` property to get more information about the error that occurred. You can also use the `queryId` property to cancel the query or to get more information about the status of the query. |
70 | | - |
71 | | -### Example usage |
72 | | - |
73 | | -The following example shows how to use the query() method to execute a SELECT statement: |
74 | | - |
75 | | -```typescript |
76 | | -const client = new PrestoClient({ |
77 | | - catalog: 'tpcds', |
78 | | - host: 'http://localhost', |
79 | | - port: 8080, |
80 | | - schema: 'sf10', |
81 | | - user: 'root', |
82 | | -}) |
83 | | - |
84 | | -const query = `SELECT * FROM my_table` |
85 | | - |
86 | | -const prestoQuery = await client.query(query) |
87 | | - |
88 | | -if (prestoQuery.error) { |
89 | | - // Handle the error. |
90 | | -} else { |
91 | | - // Use the results of the query. |
92 | | -} |
93 | | -``` |
94 | | - |
95 | | -### Additional notes |
96 | | - |
97 | | -Additional notes |
98 | | - |
99 | | -- The `query` method is asynchronous and will return a promise that resolves to a PrestoQuery object. |
100 | | -- The `query` method will automatically retry the query if it fails due to a transient error. |
101 | | -- The `query` method will cancel the query if the client is destroyed. |
| 11 | +Check the [CONTRIBUTING](CONTRIBUTING.md) file for information on how to build, test and publish the client. |
0 commit comments