Skip to content

Commit 529377a

Browse files
authored
fix(presto-client): improve published package information (#7)
1 parent 9a9881a commit 529377a

File tree

14 files changed

+298
-197
lines changed

14 files changed

+298
-197
lines changed

README.md

Lines changed: 6 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,11 @@
1-
# Presto JS Client
1+
# presto-client
22

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).
44

5-
## Installation
5+
## Presto JS Client
66

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.
108

11-
## Usage
9+
## Contributing
1210

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.

apps/nest-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To run this application, follow these steps:
2121
3. After starting the Nest Server, you can make a `GET` request to the following endpoint to see the response from querying the local Presto container using the `prestodb-js-client` library:
2222

2323
```
24-
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:3000/api/call-centers | json
24+
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:3000/api/query-test | json
2525
```
2626

2727
Output:

apps/nest-server/src/app/app.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AppService } from './app.service'
66
export class AppController {
77
constructor(private readonly appService: AppService) {}
88

9-
@Get('call-centers')
9+
@Get('query-test')
1010
async getData() {
1111
try {
1212
return await this.appService.getData()

apps/nest-server/src/app/app.service.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ import PrestoClient, { PrestoClientConfig } from '@prestodb/presto-js-client'
55
export class AppService {
66
async getData(): Promise<unknown> {
77
const clientParams: PrestoClientConfig = {
8-
catalog: 'tpcds',
8+
catalog: 'tpch',
99
host: 'http://localhost',
1010
port: 8080,
11-
schema: 'sf10',
11+
schema: 'sf1',
1212
user: 'root',
1313
}
1414
const client = new PrestoClient(clientParams)
15-
const results = await client.query(`SELECT * FROM call_center`)
16-
return { columns: results.columns, rows: results.data }
15+
try {
16+
const results = await client.query(
17+
`select returnflag, linestatus, sum(quantity) as sum_qty, sum(extendedprice) as sum_base_price, sum(extendedprice * (1 - discount)) as sum_disc_price, sum(extendedprice * (1 - discount) * (1 + tax)) as sum_charge, avg(quantity) as avg_qty, avg(extendedprice) as avg_price, avg(discount) as avg_disc, count(*) as count_order from lineitem where shipdate <= date '1998-12-01' group by returnflag, linestatus order by returnflag, linestatus`,
18+
)
19+
return { columns: results.columns, rows: results.data }
20+
} catch (error) {
21+
return JSON.stringify({
22+
error,
23+
})
24+
}
1725
}
1826
}

apps/nest-server/src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { NestFactory } from '@nestjs/core'
99
import { AppModule } from './app/app.module'
1010

1111
async function bootstrap() {
12-
const app = await NestFactory.create(AppModule)
12+
const app = await NestFactory.create(AppModule, {
13+
logger: ['error', 'warn', 'log', 'debug'],
14+
})
1315
const globalPrefix = 'api'
1416
app.setGlobalPrefix(globalPrefix)
1517
const port = process.env.PORT || 3000

apps/nextjs/app/api/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function GET() {
77
catalog: 'tpcds',
88
host: 'http://localhost',
99
port: 8080,
10-
schema: 'sf10',
10+
schema: 'sf1',
1111
user: 'root',
1212
}
1313
const client = new PrestoClient(prestoClientConfig)

docker-compose/presto/presto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ npm run presto:up
1111
Use the Presto-CLI to run queries:
1212

1313
```
14-
docker exec -it prestodb presto-cli --catalog tpcds --schema sf10
14+
docker exec -it prestodb presto-cli --catalog tpcds --schema sf1
1515
```
1616

1717
Examples:

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
"name": "presto-js-client",
33
"description": "JavaScript client for Presto",
44
"keywords": [
5-
"javascript",
5+
"database",
66
"presto",
77
"prestodb",
8-
"typescript"
8+
"sql"
99
],
10-
"license": "Apache-2.0",
1110
"repository": "https://github.com/prestodb/presto-js-client",
11+
"license": "Apache-2.0",
12+
"workspaces": [
13+
"packages/*"
14+
],
1215
"scripts": {
1316
"build": "nx build",
1417
"commit": "cz",
@@ -90,11 +93,7 @@
9093
"verdaccio": "^5.0.4"
9194
},
9295
"engines": {
93-
"npm": ">=9.6",
94-
"node": ">=18.17"
95-
},
96-
"private": true,
97-
"workspaces": [
98-
"packages/*"
99-
]
96+
"node": ">=18.17",
97+
"npm": ">=9.6"
98+
}
10099
}

presto-client/.swcrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
"module": {
2626
"type": "commonjs"
2727
},
28-
"sourceMaps": true
28+
"sourceMaps": false
2929
}

presto-client/CONTRIBUTING.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# presto-client
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Building
6+
7+
To build the library using [SWC](https://swc.rs), run the following command:
8+
9+
```bash
10+
npm run build presto-client
11+
```
12+
13+
## Linting
14+
15+
To lint the library using [ESLint](https://eslint.org), run the following command:
16+
17+
```bash
18+
npm run lint presto-client
19+
```
20+
21+
## Publishing
22+
23+
### Locally
24+
25+
To publish a new version to a private local registry, follow these steps:
26+
27+
#### Steps
28+
29+
1. Start by cleaning your workspace using the following command:
30+
31+
```bash
32+
git stash
33+
```
34+
35+
2. Start a private local registry using [Verdaccio](https://verdaccio.org):
36+
37+
```bash
38+
npm run local-registry presto-js-client
39+
```
40+
41+
3. In another terminal, publish the new version by running the following command:
42+
43+
```bash
44+
npm run publish:local presto-client
45+
```
46+
47+
If you're publishing a Pre-release version, run instead:
48+
49+
```bash
50+
npm run publish:local presto-client -- --releaseAs=premajor|preminor|prepatch --preid=beta
51+
```
52+
53+
Check the [semver options](https://github.com/jscutlery/semver#available-options) for all available options.
54+
55+
4. If the output of the previous command is successful, check that:
56+
57+
- A new local git tag was generated.
58+
- `presto-client/CHANGELOG.md` file was updated.
59+
- `presto-client/package.json` file was updated.
60+
61+
5. Visit http://localhost:4873 and ensure that `@prestodb/presto-js-client` was pushed successfully to the private local registry, including the git tag, `CHANGELOG.md`, and `package.json` files reviewed above.
62+
63+
6. Now you can run `npm i @prestodb/presto-js-client` in any other project locally to test the released version before releasing it to NPM.
64+
65+
### NPM
66+
67+
To publish a new version to NPM, follow these steps:
68+
69+
#### Pre-requisites
70+
71+
- Have a valid `NPM_TOKEN` with write permissions to [prestodb NPM organization](https://www.npmjs.com/settings/prestodb/packages).
72+
- Install [GitHub CLI](https://cli.github.com/) on your machine.
73+
74+
#### Steps
75+
76+
1. Start by cleaning your workspace using the following command:
77+
78+
```bash
79+
git stash
80+
```
81+
82+
2. Publish a new version by running the following command:
83+
84+
```bash
85+
npm run publish presto-client
86+
```
87+
88+
If you're publishing a Pre-release version, run instead:
89+
90+
```bash
91+
npm run publish presto-client -- --releaseAs=premajor|preminor|prepatch --preid=beta
92+
```
93+
94+
Check the [semver options](https://github.com/jscutlery/semver#available-options) for all available options.
95+
96+
3. As part of the previous command, a draft GitHub release is also created. Go to [GitHub Releases](https://github.com/prestodb/presto-js-client/releases), review and edit it if necessary, and then click "Publish release" to make it public.
97+
98+
\*If you published the package as a Pre-release version, please also mark the GitHub release as a "Pre-release."
99+
100+
## Testing
101+
102+
To test the library using [Jest](https://jestjs.io), run the following command:
103+
104+
```bash
105+
npm run test presto-client
106+
```
107+
108+
## Sample apps
109+
110+
You can run the sample apps to check the client still works properly.
111+
112+
### NestJS Server
113+
114+
Run the server with
115+
116+
```sh
117+
npx nx serve nest-server
118+
```
119+
120+
Check the server is live and you can make queries on this URL:
121+
122+
```
123+
http://localhost:3000/api/query-test
124+
```
125+
126+
### NextJS Server Side Rendered app
127+
128+
Run the application with
129+
130+
```sh
131+
npx nx serve nextjs
132+
```
133+
134+
Check the app is running on your browser:
135+
136+
```
137+
http://localhost:4200/
138+
```

0 commit comments

Comments
 (0)