Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add query_all function #355

Merged
merged 8 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions bindings/nodejs/generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,49 @@ switch (platform) {
loadError = e
}
break
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'databend-driver.linux-riscv64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./databend-driver.linux-riscv64-musl.node')
} else {
nativeBinding = require('@databend-driver/lib-linux-riscv64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'databend-driver.linux-riscv64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./databend-driver.linux-riscv64-gnu.node')
} else {
nativeBinding = require('@databend-driver/lib-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, 'databend-driver.linux-s390x-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./databend-driver.linux-s390x-gnu.node')
} else {
nativeBinding = require('@databend-driver/lib-linux-s390x-gnu')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
Expand Down
2 changes: 2 additions & 0 deletions bindings/nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class Connection {
exec(sql: string): Promise<number>
/** Execute a SQL query, and only return the first row. */
queryRow(sql: string): Promise<Row | null>
/** Execute a SQL query and fetch all data into the result */
queryAll(sql: string): Promise<Array<Row>>
/** Execute a SQL query, and return all rows. */
queryIter(sql: string): Promise<RowIterator>
/** Execute a SQL query, and return all rows with schema and stats. */
Expand Down
13 changes: 13 additions & 0 deletions bindings/nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,19 @@ impl Connection {
.map_err(format_napi_error)
}

/// Execute a SQL query and fetch all data into the result
#[napi]
pub async fn query_all(&self, sql: String) -> Result<Vec<Row>> {
Ok(self
.0
.query_all(&sql)
.await
.map_err(format_napi_error)?
.into_iter()
.map(|row| Row(row))
.collect())
}

/// Execute a SQL query, and return all rows.
#[napi]
pub async fn query_iter(&self, sql: String) -> Result<RowIterator> {
Expand Down
Loading
Loading