Skip to main content

url

The first and the only required hidden column is the url column. Use this to specify the endpoint of the server you are fetching from. By "required", I mean that it needs to be set equal to a value in each SELECT query.

So to query the albums table from above, we need to specify the url value in the WHERE clause:

SELECT * FROM albums
WHERE url = 'https://jsonplaceholder.typicode.com/albums';

VTTP will throw an error if you forget to set url:

sqlite> SELECT * FROM albums;
Parse error: (vttp) Missing `WHERE url = ...` (no default URL).

You don't need to specify WHERE url = ... if you provide a DEFAULT value for url in the create virtual table statement:

DROP TABLE IF EXISTS albums;

CREATE VIRTUAL TABLE albums USING vttp (
url TEXT DEFAULT 'https://jsonplaceholder.typicode.com/albums',
id INT,
"userId" INT,
title TEXT
);

SELECT * FROM albums LIMIT 3;

Then you won't need to filter by url each time:

sqlite> SELECT * FROM albums LIMIT 3;
┌────┬────────┬──────────────────────────────────┐
│ id │ userId │ title │
├────┼────────┼──────────────────────────────────┤
11 │ quidem molestiae enim │
21 │ sunt qui excepturi placeat culpa │
31 │ omnis laborum odio │
└────┴────────┴──────────────────────────────────┘

If you set a DEFAULT value and specify a url in a WHERE clause, the WHERE url = ... value will be used over the default:

DROP TABLE IF EXISTS todos;

CREATE VIRTUAL TABLE todos USING vttp (
url TEXT default 'https://jsonplaceholder.typicode.com/todos',
"userId" INT,
id INT,
title TEXT,
completed TEXT
);

SELECT * FROM todos
WHERE url = 'https://dummy-json.mock.beeceptor.com/todos';

This will select the todos from the https://dummy-json.mock.beeceptor.com/todos url instead of the DEFAULT typicode api:

sqlite> SELECT * FROM todos 
WHERE url = 'https://dummy-json.mock.beeceptor.com/todos';
┌────────┬────┬──────────────────┬───────────┐
│ userId │ id │ title │ completed │
├────────┼────┼──────────────────┼───────────┤
31 │ Buy groceries │ false
52 │ Go for a walk │ true
13 │ Finish homework │ false
74Read a book │ true
25 │ Pay bills │ false
46Call a friend │ true
67 │ Clean the house │ false
98 │ Go to the gym │ true
89Write a report │ false
210 │ Cook dinner │ true
111 │ Study for exams │ false
312Do laundry │ true
513 │ Practice guitar │ false
714Plan a trip │ true
915 │ Attend a meeting │ false
616 │ Water the plants │ true
417 │ Fix the car │ false
818 │ Watch a movie │ true
1019 │ Visit the museum │ false
120 │ Send an email │ true
└────────┴────┴──────────────────┴───────────┘