Skip to content

Commit 1a54e93

Browse files
committed
updated api docs
1 parent 0a0bc8b commit 1a54e93

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

docs/api.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ const fs = require('fs');
256256

257257
db.table('filesystem_directory', {
258258
columns: ['filename', 'data'],
259-
*rows() {
259+
rows: function* () {
260260
for (const filename of fs.readdirSync(process.cwd())) {
261261
const data = fs.readFileSync(filename);
262262
yield { filename, data };
@@ -275,7 +275,7 @@ Virtual tables can be used like [table-valued functions](https://www.sqlite.org/
275275
```js
276276
db.table('regex_matches', {
277277
columns: ['match', 'capture'],
278-
*rows(pattern, text) {
278+
rows: function* (pattern, text) {
279279
const regex = new RegExp(pattern, 'g');
280280
let match;
281281

@@ -297,7 +297,7 @@ By default, the number of parameters accepted by a virtual table is inferred by
297297
db.table('regex_matches', {
298298
columns: ['match', 'capture'],
299299
parameters: ['pattern', 'text'],
300-
*rows(pattern, text) {
300+
rows: function* (pattern, text) {
301301
...
302302
},
303303
});
@@ -311,7 +311,7 @@ When querying a virtual table, any omitted parameters will be `undefined`. You c
311311
db.table('sequence', {
312312
columns: ['value'],
313313
parameters: ['length', 'start'],
314-
*rows(length, start = 0) {
314+
rows: function* (length, start = 0) {
315315
if (length === undefined) {
316316
throw new TypeError('missing required parameter "length"');
317317
}
@@ -327,6 +327,8 @@ db.prepare('SELECT * FROM sequence(10)').pluck().all();
327327
// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
328328
```
329329

330+
> Note that when using syntax like `start = 0` for default parameter values (shown above), the function's `.length` property does not include the optional parameter, so you need to explicitly declare `parameters` in this case.
331+
330332
Normally, when you register a virtual table, the virtual table *automatically exists* without needing to run a `CREATE VIRTUAL TABLE` statement. However, if you provide a factory function as the second argument (a function that *returns* virtual table definitions), then no virtual table will be created automatically. Instead, you can create multiple similar virtual tables by running [`CREATE VIRTUAL TABLE`](https://sqlite.org/lang_createvtab.html) statements, each with their own module arguments. Think of it like defining a virtual table "class" that can be instantiated by running `CREATE VIRTUAL TABLE` statements.
331333

332334
```js
@@ -336,7 +338,7 @@ db.table('csv', (filename) => {
336338
const firstLine = getFirstLineOfFile(filename);
337339
return {
338340
columns: firstLine.split(','),
339-
*rows() {
341+
rows: function* () {
340342
const contents = fs.readFileSync(filename, 'utf8');
341343
for (const line of contents.split('\n')) {
342344
yield line.split(',');

docs/integer.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ db.prepare('SELECT isInt(?)').pluck().get(10); // => "false"
5252
db.prepare('SELECT isInt(?)').pluck().get(10n); // => "true"
5353
```
5454

55-
Likewise, [user-defined aggregates](./api.md#aggregatename-options---this) and [virtual tables](#tablename-definition---this) can also receive `BigInts` as arguments:
55+
Likewise, [user-defined aggregates](./api.md#aggregatename-options---this) and [virtual tables](./api.md#tablename-definition---this) can also receive `BigInts` as arguments:
5656

5757
```js
5858
db.aggregate('addInts', {
@@ -67,7 +67,7 @@ db.table('sequence', {
6767
safeIntegers: true,
6868
columns: ['value'],
6969
parameters: ['length', 'start'],
70-
*rows(length, start = 0n) {
70+
rows: function* (length, start = 0n) {
7171
const end = start + length;
7272
for (let n = start; n < end; ++n) {
7373
yield { value: n };

0 commit comments

Comments
 (0)