Bridge - SQLite

Bridge - SQLite

Register a bridge to sqlite3

Register a bridge that connects to the SQLite.

bridge add -t sqlite sqlitedb file:/data/sqlite.db;

SQLite supports memory only mode like below.

bridge add -t sqlite mem file::memory:?cache=shared

Test the bridge’s connectivity

machbase-neo» bridge test mem;
Test bridge mem connectivity... success 11.917µs

Create table

Open machbase-neo shell and execute the command below which creates a mem_example table via the mem bridge.

bridge exec mem CREATE TABLE IF NOT EXISTS mem_example(
    id         INTEGER NOT NULL PRIMARY KEY,
    company    TEXT,
    employee   INTEGER,
    discount   REAL,
    code       TEXT,
    valid      BOOLEAN,
    memo       BLOB,
    created_on DATETIME NOT NULL
);

TQL writing on the SQLite

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
FAKE( json({
    ["COMPANY", "EMPLOYEE"],
    ["NovaWave", 10],
    ["Sunflower", 20]
}))

DROP(1) // skip header
MAPVALUE(2, time("now"))

INSERT(bridge("mem"), table("mem_example"), "company", "employee", "created_on")
machbase-neo» bridge query mem select * from mem_example;
╭────┬─────────┬──────────┬──────────┬───────┬───────┬──────┬──────────────────────────────────────╮
│ ID │ COMPANY │ EMPLOYEE │ DISCOUNT │ CODE  │ VALID │ MEMO │ CREATED_ON                           │
├────┼─────────┼──────────┼──────────┼───────┼───────┼──────┼──────────────────────────────────────┤
│  1 │ acme    │       10 │ <nil>    │ <nil> │ <nil> │ []   │ 2023-08-10 14:33:08.667491 +0900 KST │
╰────┴─────────┴──────────┴──────────┴───────┴───────┴──────┴──────────────────────────────────────╯

TQL reading from the SQLite

Save the code below as sqlite.tql.

SQL(bridge('mem'), "select company, employee, created_on from mem_example")
CSV()

And call the endpoint with curl command or open the browser.

curl -o - http://127.0.0.1:5654/db/tql/sqlite.tql
NovaWave,10,1704866777160399000
Sunflower,20,1704866777160407000
Last updated on