Dec 07

w4sql sqlite and duckdb expose

I tested exposing an existing sqlite database I have through a web service which worked well. This is some details on my setup.

from docker compose file

  ws4sql_sqlite:
    image: ghcr.io/proofrock/ws4sql:latest
    container_name: ws4sql_sqlite_container
    ports:
      # Map the container's default port (12321) to the host machine's port 12321
      - "12321:12321"
    volumes:
      # Mount a local directory './data' to the container's '/data' volume
      - /stacks/ws_sqlite_data:/data
    restart: unless-stopped
    command: ["-db", "/data/students.yaml"]
    #command: ["--file", "/data/students.sqlite"]

config file

$ cat ../ws_sqlite_data/students.yaml 
database:
  type: SQLITE          # SQLITE or DUCKDB. If omitted, defaults to SQLITE      
  inMemory: false       # If type = SQLITE|DUCKDB. The db is a memory one? If omitted, defaults to false
  path: "/data/students.sqlite"   # If type = SQLITE|DUCKDB. The db file path.
  id: students   # If omitted and !inMemory, calculates it from the file name (if type = SQLITE|DUCKDB)
  disableWALMode: false # If type = SQLITE. Same as before, but moved here.
  readOnly: false       # Same as before, but moved here.

running container

$ docker compose ps
NAME                      IMAGE                             COMMAND                  SERVICE         CREATED             STATUS                       PORTS
...
ws4sql_sqlite_container   ghcr.io/proofrock/ws4sql:latest   "/ws4sql -db /data/s…"   ws4sql_sqlite   10 minutes ago      Up 2 minutes                 0.0.0.0:12321->12321/tcp, [::]:12321->12321/tcp

container log

                __ __             __
 _      _______/ // / _________ _/ /
| | /| / / ___/ // /_/ ___/ __ `/ /
| |/ |/ (__  )__  __(__  ) /_/ / /
|__/|__/____/  /_/ /____/\__, /_/
                           /_/ v0.17dev7
+ sqlite v3.50.3
+ duckdb v0.0.1
- Parsing config file: /data/students.yaml
  + Serving database 'students'
  + Using WAL
- Web Service listening on 0.0.0.0:12321

example select

$ cat /tmp/students.json
{
    "transaction": [
        {
            "query": "SELECT * FROM students"
        }
    ]
}

$ curl -s -X POST -H "Content-Type: application/json" -d @/tmp/students.json http://localhost:12321/students | jq
    {
    "results": [
        {
        "success": true,
        "resultHeaders": [
            "id",
            "first_name",
            "last_name",
            "age"
        ],
        "resultSet": [
            {
            "id": 101,
            "first_name": "John",
            "last_name": "Doe",
            "age": 20
            }
        ]
        }
    ]
    }

multiple transactions

    $ cat /tmp/students.json 
    {
        "transaction": [
        {
                "statement": "INSERT INTO students (id, first_name, last_name, age) VALUES (:id, :val1, :val2, :val3)",
                "values": { "id": 1, "val1": "Jane", "val2": "Doe", "val3": 40 }
            },
            {
                "query": "SELECT * FROM students"
            }
        ]
    }

    $ curl -s -X POST -H "Content-Type: application/json" -d @/tmp/students.json http://localhost:12321/students | jq
    {
    "results": [
        {
        "success": true,
        "rowsUpdated": 1
        },
        {
        "success": true,
        "resultHeaders": [
            "id",
            "first_name",
            "last_name",
            "age"
        ],
        "resultSet": [
            {
            "id": 1,
            "first_name": "Jane",
            "last_name": "Doe",
            "age": 40
            },
            {
            "id": 101,
            "first_name": "John",
            "last_name": "Doe",
            "age": 20
            }
        ]
        }
    ]
    }

references

Comments Off on w4sql sqlite and duckdb expose
comments

Comments are closed.