Skip to content

Commit a44f86c

Browse files
committed
deno example
Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent fe0086b commit a44f86c

File tree

5 files changed

+130
-0
lines changed

5 files changed

+130
-0
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ if db_lib.needs_update():
227227
228228
Refer to the [readme](./contrib/mcp-server-vdb/README.md)
229229
230+
## Read .vdb6 files in other languages
231+
232+
.vdb6 files are standard SQLite database files. Use any modern sqlite library to read and query them. There is a mini [deno example](./contrib/deno-vdb/README.md) in this repo for demonstration.
233+
230234
## License
231235
232236
MIT

Diff for: contrib/deno-vdb/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Introduction
2+
3+
Mini example to read sqlite data in deno.
4+
5+
## Pre-requisites
6+
7+
```shell
8+
export VDB_HOME=$HOME/vdb
9+
vdb --download-image
10+
```
11+
12+
## Usage
13+
14+
```shell
15+
deno run --allow-read --allow-write --allow-env --allow-net --allow-ffi main.ts
16+
```

Diff for: contrib/deno-vdb/deno.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"tasks": {
3+
"dev": "deno run --watch main.ts"
4+
},
5+
"imports": {
6+
"@std/assert": "jsr:@std/assert@1",
7+
"@db/sqlite": "jsr:@db/[email protected]"
8+
}
9+
}

Diff for: contrib/deno-vdb/deno.lock

+73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: contrib/deno-vdb/main.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Database } from "@db/sqlite";
2+
import * as path from "jsr:@std/path";
3+
4+
const vdbHome = Deno.env.get("VDB_HOME");
5+
const indexDBFile = path.join(vdbHome, "data.index.vdb6");
6+
const cveDBFile = path.join(vdbHome, "data.vdb6");
7+
8+
const indexDB = new Database(indexDBFile);
9+
const cveDB = new Database(cveDBFile);
10+
11+
if (import.meta.main) {
12+
const [indexCount] = indexDB.prepare("SELECT count(*) FROM cve_index").value<number>()!;
13+
const [cveDBCount] = cveDB.prepare("SELECT count(*) FROM cve_data").value<number>()!;
14+
console.log(`Index count: ${indexCount}, VDB count: ${cveDBCount}`);
15+
16+
console.log("Index Data");
17+
const rows = indexDB.prepare("SELECT cve_id, type, namespace, name, vers, purl_prefix FROM cve_index LIMIT 10").all();
18+
for (const row of rows) {
19+
console.log(row);
20+
}
21+
22+
// Use json(source_data) to read jsonb columns
23+
console.log("CVE Data");
24+
const vrows = cveDB.prepare("SELECT cve_id, type, namespace, name, json(source_data) as source_data, source_data_hash FROM cve_data LIMIT 10").all();
25+
for (const row of vrows) {
26+
console.log(row);
27+
}
28+
}

0 commit comments

Comments
 (0)