Skip to content

Commit

Permalink
Merge pull request #4312 from szarnyasg/nits-20241208b
Browse files Browse the repository at this point in the history
Linter and typo fixes
  • Loading branch information
szarnyasg authored Dec 8, 2024
2 parents ddc4bb4 + 01970ff commit d1c9950
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
21 changes: 17 additions & 4 deletions docs/api/node_neo/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ layout: docu
title: Node.js API (Neo)
---

# DuckDB Node.js API (Neo)

An API for using [DuckDB](https://duckdb.org/) in [Node.js](https://nodejs.org/).

This is a high-level API meant for applications.
Expand All @@ -14,6 +12,7 @@ available separately as [@duckdb/duckdb-bindings](https://www.npmjs.com/package/
## Features

### Main differences from [duckdb-node](https://www.npmjs.com/package/duckdb)

- Native support for Promises; no need for separate [duckdb-async](https://www.npmjs.com/package/duckdb-async) wrapper.
- DuckDB-specific API; not based on the [SQLite Node API](https://www.npmjs.com/package/sqlite3).
- Lossless & efficent support for values of all [DuckDB data types](https://duckdb.org/docs/sql/data_types/overview).
Expand All @@ -23,6 +22,7 @@ available separately as [@duckdb/duckdb-bindings](https://www.npmjs.com/package/
### Roadmap

Some features are not yet complete:

- Appending and binding advanced data types. (Additional DuckDB C API support needed.)
- Writing to data chunk vectors. (Needs special handling in Node.)
- User-defined types & functions. (Support for this was added to the DuckDB C API in v1.1.0.)
Expand Down Expand Up @@ -55,21 +55,25 @@ import { DuckDBInstance } from '@duckdb/node-api';
```

Create with an in-memory database:

```ts
const instance = await DuckDBInstance.create(':memory:');
```

Equivalent to the above:

```ts
const instance = await DuckDBInstance.create();
```

Read from and write to a database file, which is created if needed:

```ts
const instance = await DuckDBInstance.create('my_duckdb.db');
```

Set configuration options:

```ts
const instance = await DuckDBInstance.create('my_duckdb.db', {
threads: '4'
Expand Down Expand Up @@ -100,17 +104,20 @@ const result = await prepared.run();
### Inspect Result

Get column names and types:

```ts
const columnNames = result.columnNames();
const columnTypes = result.columnTypes();
```

Fetch all chunks:

```ts
const chunks = await result.fetchAllChunks();
```

Fetch one chunk at a time:

```ts
const chunks = [];
while (true) {
Expand All @@ -124,18 +131,21 @@ while (true) {
```

Read chunk data (column-major):

```ts
// array of columns, each as an array of values
const columns = chunk.getColumns();
```

Read chunk data (row-major):

```ts
// array of rows, each as an array of values
const columns = chunk.getRows();
```

Read chunk data (one value at a time)
Read chunk data (one value at a time):

```ts
const columns = [];
const columnCount = chunk.columnCount;
Expand All @@ -154,20 +164,23 @@ for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
### Result Reader

Run and read all data:

```ts
const reader = await connection.runAndReadAll('from test_all_types()');
const rows = reader.getRows();
// OR: const columns = reader.getColumns();
```

Run and read up to (at lesat) some number of rows:
Run and read up to (at least) some number of rows:

```ts
const reader = await connection.runAndReadUtil('from range(5000)', 1000);
const rows = reader.getRows();
// rows.length === 2048. (Rows are read in chunks of 2048.)
```

Read rows incrementally:

```ts
const reader = await connection.runAndRead('from range(5000)');
reader.readUntil(2000);
Expand Down
2 changes: 1 addition & 1 deletion docs/data/json/installing_and_loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ The `json` extension is shipped by default in DuckDB builds, otherwise, it will
```sql
INSTALL json;
LOAD json;
```
```
2 changes: 1 addition & 1 deletion docs/data/json/loading_json.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Besides the `maximum_object_size`, `format`, `ignore_errors` and `compression`,
| `sample_size` | Option to define number of sample objects for automatic JSON type detection. Set to -1 to scan the entire input file | `UBIGINT` | `20480` |
| `timestampformat` | Specifies the date format to use when parsing timestamps. See [Date Format]({% link docs/sql/functions/dateformat.md %}) | `VARCHAR` | `'iso'`|
| `union_by_name` | Whether the schema's of multiple JSON files should be [unified]({% link docs/data/multiple_files/combining_schemas.md %}) | `BOOL` | `false` |
| `map_inference_threshold` | Controls the threshold for number of columns whose schema will be auto-detected; if JSON schema auto-detection would infer a `STRUCT` type for a field that has _more_ than this threshold number of subfields, it infers a `MAP` type instead. Set to -1 to disable `MAP` inference. | `BIGINT` | `24`
| `map_inference_threshold` | Controls the threshold for number of columns whose schema will be auto-detected; if JSON schema auto-detection would infer a `STRUCT` type for a field that has _more_ than this threshold number of subfields, it infers a `MAP` type instead. Set to -1 to disable `MAP` inference. | `BIGINT` | `24` |

Example usage:

Expand Down
9 changes: 4 additions & 5 deletions docs/extensions/spatial/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,11 @@ VARCHAR ST_AsSVG (col0 GEOMETRY, col1 BOOLEAN, col2 INTEGER)

Convert the geometry into a SVG fragment or path

Convert the geometry into a SVG fragment or path
The SVG fragment is returned as a string. The fragment is a path element that can be used in an SVG document.
The second Boolean argument specifies whether the path should be relative or absolute.
The third argument specifies the maximum number of digits to use for the coordinates.
The SVG fragment is returned as a string. The fragment is a path element that can be used in an SVG document.
The second Boolean argument specifies whether the path should be relative or absolute.
The third argument specifies the maximum number of digits to use for the coordinates.

Points are formatted as cx/cy using absolute coordinates or x/y using relative coordinates.
Points are formatted as cx/cy using absolute coordinates or x/y using relative coordinates.

#### Example

Expand Down
4 changes: 2 additions & 2 deletions docs/sql/functions/aggregates.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ The table below shows the available general aggregate functions.
| [`fsum(arg)`](#fsumarg) | Calculates the sum using a more accurate floating point summation (Kahan Sum). |
| [`geomean(arg)`](#geomeanarg) | Calculates the geometric mean of all non-null values in `arg`. |
| [`histogram(arg)`](#histogramarg) | Returns a `MAP` of key-value pairs representing buckets and counts. |
| [`histogram(arg, boundaries)`](#histogramargboundaries) | Returns a `MAP` of key-value pairs representing the provided upper `boundaries` and counts of elements in the corresponding left-open and right-closed partition of the datatype. A boundary at the largest value of the datatype is automatically added when elements larger than all provided `boundaries` appear, see [`is_histogram_other_bin`]({% link docs/sql/functions/utility.md %}#is_histogram_other_binarg). Boundaries may be provided, e.g., via [`equi_width_bins`]({% link docs/sql/functions/utility.md %}#equi_width_binsminmaxbincountnice). |
| [`histogram_exact(arg, elements)`](#histogram_exactargelements) | Returns a `MAP` of key-value pairs representing the requested elements and their counts. A catch-all element specific to the data-type is automatically added to count other elements when they appear, see [`is_histogram_other_bin`]({% link docs/sql/functions/utility.md %}#is_histogram_other_binarg). |
| [`histogram(arg, boundaries)`](#histogramarg-boundaries) | Returns a `MAP` of key-value pairs representing the provided upper `boundaries` and counts of elements in the corresponding left-open and right-closed partition of the datatype. A boundary at the largest value of the datatype is automatically added when elements larger than all provided `boundaries` appear, see [`is_histogram_other_bin`]({% link docs/sql/functions/utility.md %}#is_histogram_other_binarg). Boundaries may be provided, e.g., via [`equi_width_bins`]({% link docs/sql/functions/utility.md %}#equi_width_binsminmaxbincountnice). |
| [`histogram_exact(arg, elements)`](#histogram_exactarg-elements) | Returns a `MAP` of key-value pairs representing the requested elements and their counts. A catch-all element specific to the data-type is automatically added to count other elements when they appear, see [`is_histogram_other_bin`]({% link docs/sql/functions/utility.md %}#is_histogram_other_binarg). |
| [`last(arg)`](#lastarg) | Returns the last value of a column. This function is [affected by ordering](#order-by-clause-in-aggregate-functions). |
| [`list(arg)`](#listarg) | Returns a `LIST` containing all the values of a column. This function is [affected by ordering](#order-by-clause-in-aggregate-functions). |
| [`max(arg)`](#maxarg) | Returns the maximum value present in `arg`. |
Expand Down
2 changes: 1 addition & 1 deletion docs/sql/functions/utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The functions below are difficult to categorize into specific function types and
| [`current_setting('setting_name')`](#current_settingsetting_name) | Return the current value of the configuration setting. |
| [`currval('sequence_name')`](#currvalsequence_name) | Return the current value of the sequence. Note that `nextval` must be called at least once prior to calling `currval`. |
| [`error(message)`](#errormessage) | Throws the given error `message`. |
| [`equi_width_bins(min, max, bincount, nice := false)`](#equi_width_binsminmaxbincountnice) | Returns the upper boundaries of a partition of the interval `[min, max]` into `bin_count` equal-sized subintervals (for use with, e.g., [`histogram`]({% link docs/sql/functions/aggregates.md %}#histogramargboundaries)). If `nice = true`, then `min`, `max`, and `bincount` may be adjusted to produce more aesthetically pleasing results. |
| [`equi_width_bins(min, max, bincount, nice := false)`](#equi_width_binsmin-max-bincount-nice--false) | Returns the upper boundaries of a partition of the interval `[min, max]` into `bin_count` equal-sized subintervals (for use with, e.g., [`histogram`]({% link docs/sql/functions/aggregates.md %}#histogramargboundaries)). If `nice = true`, then `min`, `max`, and `bincount` may be adjusted to produce more aesthetically pleasing results. |
| [`force_checkpoint(database)`](#force_checkpointdatabase) | Synchronize WAL with file for (optional) database interrupting transactions. |
| [`gen_random_uuid()`](#gen_random_uuid) | Alias of `uuid`. Return a random UUID similar to this: `eeccb8c5-9943-b2bb-bb5e-222f4e14b687`. |
| [`getenv(var)`](#getenvvar) | Returns the value of the environment variable `var`. Only available in the [command line client]({% link docs/api/cli/overview.md %}). |
Expand Down

0 comments on commit d1c9950

Please sign in to comment.