1
0
Fork 0
forked from fun/fun
fun/examples/sqlited
2026-01-19 23:24:36 +01:00
..
client.fun Added a basic TCP server that provides access to an sqlite database. (0.37.58) 2026-01-19 23:24:36 +01:00
protocol.md Added a basic TCP server that provides access to an sqlite database. (0.37.58) 2026-01-19 23:24:36 +01:00
README.md Added a basic TCP server that provides access to an sqlite database. (0.37.58) 2026-01-19 23:24:36 +01:00
server.fun Added a basic TCP server that provides access to an sqlite database. (0.37.58) 2026-01-19 23:24:36 +01:00

Fun SQL TCP Demo (sqlited)

This example provides a minimal TCP server that executes SQL against a local SQLite database and a matching client.

Files

  • server.fun — TCP server daemon
  • client.fun — simple CLI client
  • protocol.md — wire protocol specification (line-based TSV)

Prerequisites

  • Build Fun with SQLite support enabled: configure with -DFUN_WITH_SQLITE=ON
  • Ensure the sqlite3 development headers and runtime are installed

Create a sample database

  • A schema is provided at examples/data/database.sql
  • Create ./database.sqlite at the repository root using the sqlite3 CLI: sqlite3 ./database.sqlite < ./examples/data/database.sql

Run the server

  • Set FUN_LIB_DIR to the repos lib directory or install Fun libs system-wide
  • Example (Debug profile path may differ): FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/sqlited/server.fun 127.0.0.1 5555

Run the client

  • Query: FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/sqlited/client.fun 127.0.0.1 5555 "SELECT id, title FROM tasks;"
  • Exec/DDL: FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/sqlited/client.fun 127.0.0.1 5555 "UPDATE tasks SET done=1 WHERE id=1;"

Protocol summary

  • Client sends one line with SQL ended by a newline (\n)
  • Server responds with either:
    • RESULT block (header + rows as TSV) ending with END
    • OK rc (for exec/DDL)
    • ERROR message (on error) See protocol.md for details.

Notes and limitations

  • Demo only; do not expose to untrusted networks (no auth/TLS; arbitrary SQL)
  • BLOBs and binary data are not specially handled in this v1
  • Very long SQL lines are capped at 64 KiB
  • The server handles one client at a time (simple model); extend with threads if desired