Skip to content

Commit 4998cad

Browse files
committed
format readme to fit in column
1 parent 8cd56bf commit 4998cad

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

api/pkgs/@duckdb/node-api/README.md

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

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

5-
This is a high-level API meant for applications. It depends on low-level bindings that adhere closely to [DuckDB's C API](https://duckdb.org/docs/api/c/overview), available separately as [@duckdb/duckdb-bindings](https://www.npmjs.com/package/@duckdb/node-bindings).
5+
This is a high-level API meant for applications.
6+
It depends on low-level bindings that adhere closely to [DuckDB's C API](https://duckdb.org/docs/api/c/overview),
7+
available separately as [@duckdb/duckdb-bindings](https://www.npmjs.com/package/@duckdb/node-bindings).
68

79
## Features
810

@@ -17,7 +19,7 @@ This is a high-level API meant for applications. It depends on low-level binding
1719

1820
Some features are not yet complete:
1921
- Appending and binding advanced data types. (Additional DuckDB C API support needed.)
20-
- Writing to data chunk vectors. (Directly writing to binary buffers is challenging to support using the Node Addon API.)
22+
- Writing to data chunk vectors. (Needs special handling in Node.)
2123
- User-defined types & functions. (Support for this was added to the DuckDB C API in v1.1.0.)
2224
- Profiling info (Added in v1.1.0)
2325
- Table description (Added in v1.1.0)
@@ -64,7 +66,9 @@ const instance = await DuckDBInstance.create('my_duckdb.db');
6466

6567
Set configuration options:
6668
```ts
67-
const instance = await DuckDBInstance.create('my_duckdb.db', { threads: '4' });
69+
const instance = await DuckDBInstance.create('my_duckdb.db', {
70+
threads: '4'
71+
});
6872
```
6973

7074
### Connect
@@ -116,12 +120,14 @@ while (true) {
116120

117121
Read chunk data (column-major):
118122
```ts
119-
const columns = chunk.getColumns(); // array of columns, each as an array of values
123+
// array of columns, each as an array of values
124+
const columns = chunk.getColumns();
120125
```
121126

122127
Read chunk data (row-major):
123128
```ts
124-
const columns = chunk.getRows(); // array of rows, each as an array of values
129+
// array of rows, each as an array of values
130+
const columns = chunk.getRows();
125131
```
126132

127133
Read chunk data (one value at a time)
@@ -184,7 +190,8 @@ if (columnType.alias === 'JSON') {
184190
}
185191
```
186192

187-
Every type implements toString, matching DuckDB's type-to-string conversion.
193+
Every type implements toString.
194+
The result is both human-friendly and readable by DuckDB in an appropriate expression.
188195

189196
```ts
190197
const typeString = columnType.toString();
@@ -220,7 +227,8 @@ if (columnType.typeId === DuckDBTypeId.DATE) {
220227
if (columnType.typeId === DuckDBTypeId.DECIMAL) {
221228
const decimalWidth = columnValue.width;
222229
const decimalScale = columnValue.scale;
223-
const decimalValue = columnValue.value; // bigint (Scaled-up value. Represented number is value/(10^scale).)
230+
// Scaled-up value. Represented number is value/(10^scale).
231+
const decimalValue = columnValue.value; // bigint
224232
const decimalString = columnValue.toString();
225233
const decimalDouble = columnValue.toDouble();
226234
}
@@ -243,7 +251,8 @@ if (columnType.typeId === DuckDBTypeId.MAP) {
243251
}
244252

245253
if (columnType.typeId === DuckDBTypeId.STRUCT) {
246-
const structEntries = columnValue.entries; // { name1: value1, name2: value2, ... }
254+
// { name1: value1, name2: value2, ... }
255+
const structEntries = columnValue.entries;
247256
const structString = columnValue.toString();
248257
}
249258

@@ -265,20 +274,29 @@ if (columnType.typeId === DuckDBTypeId.TIMESTAMP_S) {
265274
if (columnType.typeId === DuckDBTypeId.TIMESTAMP_TZ) {
266275
const timestampTZMicros = columnValue.micros; // bigint
267276
const timestampTZString = columnValue.toString();
268-
const { date: { year, month, day }, time: { hour, min, sec, micros } } = columnValue.toParts();
277+
const {
278+
date: { year, month, day },
279+
time: { hour, min, sec, micros },
280+
} = columnValue.toParts();
269281
}
270282

271283
if (columnType.typeId === DuckDBTypeId.TIMESTAMP) {
272284
const timestampMicros = columnValue.micros; // bigint
273285
const timestampString = columnValue.toString();
274-
const { date: { year, month, day }, time: { hour, min, sec, micros } } = columnValue.toParts();
286+
const {
287+
date: { year, month, day },
288+
time: { hour, min, sec, micros },
289+
} = columnValue.toParts();
275290
}
276291

277292
if (columnType.typeId === DuckDBTypeId.TIME_TZ) {
278293
const timeTZMicros = columnValue.micros; // bigint
279294
const timeTZOffset = columnValue.offset;
280295
const timeTZString = columnValue.toString();
281-
const { time: { hour, min, sec, micros }, offset } = columnValue.toParts();
296+
const {
297+
time: { hour, min, sec, micros },
298+
offset,
299+
} = columnValue.toParts();
282300
}
283301

284302
if (columnType.typeId === DuckDBTypeId.TIME) {
@@ -298,13 +316,15 @@ if (columnType.typeId === DuckDBTypeId.UUID) {
298316
const uuidString = columnValue.toString();
299317
}
300318

301-
// other values are represented as null, boolean, number, bigint, or string
319+
// other possible values are: null, boolean, number, bigint, or string
302320
```
303321

304322
### Append To Table
305323

306324
```ts
307-
await connection.run(`create or replace table target_table(i integer, v varchar)`);
325+
await connection.run(
326+
`create or replace table target_table(i integer, v varchar)`
327+
);
308328

309329
const appender = await connection.createAppender('main', 'target_table');
310330

@@ -335,11 +355,11 @@ const extractedStatements = await connection.extractStatements(`
335355
`);
336356
const parameterValues = [10, 7];
337357
const statementCount = extractedStatements.count;
338-
for (let statementIndex = 0; statementIndex < statementCount; statementIndex++) {
339-
const prepared = await extractedStatements.prepare(statementIndex);
358+
for (let stmtIndex = 0; stmtIndex < statementCount; stmtIndex++) {
359+
const prepared = await extractedStatements.prepare(stmtIndex);
340360
let parameterCount = prepared.parameterCount;
341-
for (let parameterIndex = 1; parameterIndex <= parameterCount; parameterIndex++) {
342-
prepared.bindInteger(parameterIndex, parameterValues.shift());
361+
for (let paramIndex = 1; paramIndex <= parameterCount; paramIndex++) {
362+
prepared.bindInteger(paramIndex, parameterValues.shift());
343363
}
344364
const result = await prepared.run();
345365
// ...

0 commit comments

Comments
 (0)