-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add method to clear index (#24)
This adds `indexer.deleteAll()`, which deletes all rows from the docs table and the backlinks table. Addresses #22.
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// @ts-check | ||
import test from 'tape' | ||
import { create } from './utils.js' | ||
|
||
test('deleting everything', (t) => { | ||
const { indexer, db, cleanup } = create() | ||
|
||
const docCount = db.prepare('SELECT COUNT(*) FROM docs').pluck() | ||
const backlinkCount = db.prepare('SELECT COUNT(*) FROM backlinks').pluck() | ||
|
||
const updatedAt = new Date().toISOString() | ||
indexer.batch([ | ||
{ docId: 'A', versionId: '1', links: [], updatedAt }, | ||
{ docId: 'A', versionId: '2', links: ['1'], updatedAt }, | ||
{ docId: 'B', versionId: '3', links: [], updatedAt }, | ||
]) | ||
|
||
t.equal(docCount.get(), 2, 'Test setup expected 2 documents') | ||
t.equal(backlinkCount.get(), 1, 'Test setup expected 1 backlink') | ||
|
||
indexer.deleteAll() | ||
|
||
t.equal(docCount.get(), 0, 'Expected all documents to be deleted') | ||
t.equal(backlinkCount.get(), 0, 'Expected all backlinks to be deleted') | ||
|
||
cleanup() | ||
|
||
t.end() | ||
}) |