Comments (2)
A simple solution I am using is to concatenate the data values in every iteration of the data attribute. This may not be the best solution : /
This simple wrapper allows both getting all the results and getting the stream of the results:
import presto = require('presto-client');
import {PassThrough} from 'stream';
export class SqlClient {
private client: any;
constructor(options?: Record<string, any>) {
this.client = new presto.Client({
host: options?.host,
port: options?.port,
user: options?.user
});
}
async query(sql: string): Promise<any[]> {
const result: any[] = [];
const stream = this.queryStream(sql);
for await (const chunk of stream) {
result.push(chunk);
}
return result;
}
queryStream(sql: string): PassThrough {
const stream = new PassThrough({objectMode: true});
const onData = (
error: any,
data: any[][],
columns: {name: string}[]
): void => {
if (error) {
return;
}
for (const row of data) {
stream.write(
Object.fromEntries(columns.map((c, i) => [c.name, row[i]]))
);
}
};
const onDone = (error: any): void => {
if (error) {
console.error(error);
stream.destroy(error);
}
stream.end();
};
this.client.execute({
query: sql,
data: onData,
callback: onDone
});
return stream;
}
}
from presto-client-node.
A simple solution I am using is to concatenate the data values in every iteration of the data attribute. This may not be the best solution : /
from presto-client-node.
Related Issues (20)
- Add support for Trino HOT 3
- Discussion: support kerberos authentication HOT 1
- Rewrite this library in TypeScript
- ReferenceError: client is not defined
- Support for promise in data_callback and success_callback methods
- How to provide certificate file (for secure connection) when connecting to presto? HOT 1
- How to define presto session properties?
- columns callback but no data callback HOT 1
- Unable to configure SQL preprocessing using 'prepares'. "message: 'Prepared statement not found: query0'" HOT 1
- [HELP]: Access Denied: User pbennett cannot impersonate user paul
- Query execution fails with multiple database connection HOT 1
- Real world example: datalake-graphql-wrapper
- Add CI tests for the library HOT 1
- Remove error from callbacks that don't return an error HOT 5
- TypeError if missing error callback when using success callback HOT 1
- Undefined error when nextUri request returns non-200 status code HOT 2
- Retrieving query status and cancelling query HOT 1
- How can I update values of particular records? HOT 1
- nextUri can return 301 redirect due to https/http mismatch HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from presto-client-node.