docs/architecture/client.md
The toyDB client is in the client
module. It uses the same Bincode-based protocol that we saw in the server section, sending
toydb::Request and receiving toydb::Response.
The main client library toydb::Client is used to communicate with a toyDB server:
When initialized, it connects to a toyDB server over TCP, which establishes a SQL session for it:
It can then send Bincode-encoded toydb::Request to the server, and receive toydb::Response
back.
In particular, Client::execute can be used to execute arbitrary SQL statements in the client's
current session:
toysql BinaryHowever, toydb::Client is a programmatic API, and we want a more convenient user interface.
The toysql client in src/bin/toysql.rs
provides a typical REPL (read-evaluate-print loop) where users can enter SQL statements and view the results.
Like toydb, toysql is a tiny clap command that takes a
toyDB server address to connect to and starts an interactive shell:
It first attempts to connect to the toyDB server using the toydb::Client client, and then starts
an interactive shell using the Rustyline library.
The shell is simply a loop that prompts the user to input a SQL statement:
Each statement is the executed against the server via toydb::Client::execute, and the response
is formatted and printed as output:
And with that, we have a fully functional SQL database system and can run queries to our heart's content. Have fun!