Skip to content

Commit f4f4c5b

Browse files
committed
fix(docs): remove note on DataView parameter binding and update data type support details
1 parent 5aadba6 commit f4f4c5b

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ db.close();
4949

5050
\*API-compatible with Node.js SQLite, but this library adopts SQLite-recommended features and security-enhancing build flags. See [build configuration details](./doc/build-flags.md).
5151

52-
- DataView parameter binding is not currently supported. Use Buffer instead for binary data.
53-
5452
## Documentation
5553

5654
**Getting Started**

doc/features.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,11 @@ This package includes SQLite 3.51.3 with extensive compile-time options enabled.
120120

121121
### Data type support
122122

123-
- INTEGER (number and BigInt)
123+
- INTEGER (number and BigInt, configurable via `readBigInts`)
124124
- REAL (number)
125125
- TEXT (string)
126-
- BLOB (Buffer)
126+
- BLOB (TypedArray/DataView input, Uint8Array output)
127127
- NULL (null)
128-
- Automatic BigInt for large integers
129128

130129
### Resource management
131130

doc/working-with-data.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ for (const user of iter) {
5858

5959
## Parameter Binding
6060

61-
> **Note**: DataView parameter binding is not currently supported. Use Buffer instead for binary data.
62-
6361
### Positional Parameters (?)
6462

6563
```javascript
@@ -103,13 +101,21 @@ SQLite supports several data types, and this library handles JavaScript type con
103101

104102
### Type Mapping
105103

106-
| SQLite Type | JavaScript Type | Notes |
107-
| ----------- | ---------------- | ----------------------------------------------- |
108-
| NULL | null | |
109-
| INTEGER | number or bigint | BigInt for values outside safe integer range |
110-
| REAL | number | |
111-
| TEXT | string | |
112-
| BLOB | Buffer | Node.js Buffer objects (DataView not supported) |
104+
| Storage Class | JavaScript → SQLite | SQLite → JavaScript |
105+
| ------------- | ---------------------------- | ------------------------------------- |
106+
| `NULL` | `null` | `null` |
107+
| `INTEGER` | `number` or `bigint` | `number` or `bigint` _(configurable)_ |
108+
| `REAL` | `number` | `number` |
109+
| `TEXT` | `string` | `string` |
110+
| `BLOB` | `TypedArray` or `DataView` | `Uint8Array` |
111+
112+
APIs that read values from SQLite have a configuration option that determines
113+
whether `INTEGER` values are converted to `number` or `bigint` in JavaScript,
114+
such as the `readBigInts` option for statements and the `useBigIntArguments`
115+
option for user-defined functions. If an `INTEGER` value read from SQLite is
116+
outside the JavaScript [safe integer range](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger),
117+
and the option to read BigInts is not enabled, then an `ERR_OUT_OF_RANGE`
118+
error will be thrown.
113119

114120
### Working with Different Types
115121

@@ -147,18 +153,24 @@ const row = db.prepare("SELECT * FROM data_types WHERE id = ?").get(1);
147153
console.log(typeof row.count); // 'number'
148154
console.log(typeof row.price); // 'number'
149155
console.log(typeof row.name); // 'string'
150-
console.log(row.data); // <Buffer ...>
156+
console.log(row.data); // Uint8Array(11) [ ... ]
151157
```
152158

153159
### BigInt Support
154160

161+
By default, INTEGER values outside the safe integer range throw an
162+
`ERR_OUT_OF_RANGE` error. Enable `readBigInts` to return all integers as BigInt:
163+
155164
```javascript
156-
// Large integers automatically returned as BigInt
165+
// Without readBigInts, large integers throw ERR_OUT_OF_RANGE
157166
db.exec("CREATE TABLE big_numbers (value INTEGER)");
158167
const bigInsert = db.prepare("INSERT INTO big_numbers VALUES (?)");
159168
bigInsert.run(9007199254740993n); // Using BigInt literal
160169

161-
const result = db.prepare("SELECT value FROM big_numbers").get();
170+
// Enable readBigInts to read them back
171+
const stmt = db.prepare("SELECT value FROM big_numbers");
172+
stmt.setReadBigInts(true);
173+
const result = stmt.get();
162174
console.log(result.value); // 9007199254740993n
163175
console.log(typeof result.value); // 'bigint'
164176
```

0 commit comments

Comments
 (0)