Skip to content

Commit 63abefd

Browse files
committed
docs/architecture: split out client section
1 parent c90dbfd commit 63abefd

File tree

4 files changed

+69
-64
lines changed

4 files changed

+69
-64
lines changed

docs/architecture/client.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Client
2+
3+
The toyDB client is in the [`client`](https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs)
4+
module. It uses the same Bincode-based protocol that we saw in the server section, sending
5+
`toydb::Request` and receiving `toydb::Response`.
6+
7+
## Client Library
8+
9+
The main client library `toydb::Client` is used to connect to a toyDB server:
10+
11+
https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs#L15-L24
12+
13+
When initialized, it connects to a toyDB server over TCP:
14+
15+
https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs#L27-L33
16+
17+
It can then send Bincode-encoded `toydb::Request` to the server, and receive `toydb::Response`
18+
back.
19+
20+
https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs#L35-L40
21+
22+
23+
In particular, `Client::execute` can be used to execute arbitrary SQL statements in the client's
24+
current session:
25+
26+
https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs#L42-L56
27+
28+
## `toysql` Binary
29+
30+
However, `toydb::Client` is a programmatic API, and we want a more convenient user interface.
31+
The `toysql` client in [`src/bin/toysql.rs`](https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs)
32+
provides a typical [REPL](https://en.wikipedia.org/wiki/Read–eval–print_loop) (read-evaluate-print loop) where users can enter SQL statements and view the results.
33+
34+
Like `toydb`, `toysql` is a tiny [`clap`](https://docs.rs/clap/latest/clap/) command that takes a
35+
toyDB server address to connect to and starts an interactive shell:
36+
37+
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L29-L53
38+
39+
This first attempts to connect to the toyDB server using the `toydb::Client` client, and then starts
40+
an interactive shell using the [Rustyline](https://docs.rs/rustyline/latest/rustyline/) library.
41+
42+
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L55-L81
43+
44+
The shell is simply a loop that prompts the user to input a SQL statement:
45+
46+
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L216-L250
47+
48+
Each statement is the executed against the server via `toydb::Client::execute`, and the response
49+
is formatted and printed as output:
50+
51+
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L83-L92
52+
53+
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L175-L204
54+
55+
And with that, we have a fully functional SQL database system and can run queries to our heart's
56+
content. Have fun!
57+
58+
---
59+
60+
<p align="center">
61+
← <a href="server.md">Server</a>
62+
</p>

docs/architecture/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ to the actual source code.
5656
* [Execution](sql-execution.md)
5757
* [Plan Executor](sql-execution.md#plan-executor)
5858
* [Session Management](sql-execution.md#session-management)
59-
* [Server and Client](server.md)
60-
* [Server](server.md#server)
59+
* [Server](server.md)
6160
* [Raft Routing](server.md#raft-routing)
6261
* [SQL Service](server.md#sql-service)
6362
* [`toydb` Binary](server.md#toydb-binary)
64-
* [Client Library](server.md#client-library)
65-
* [`toysql` Binary](server.md#toysql-binary)
63+
* [Client](client.md)
64+
* [Client Library](client.md#client-library)
65+
* [`toysql` Binary](client.md#toysql-binary)
6666

6767
---
6868

docs/architecture/server.md

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# Server and Client
22

3-
Now that we've gone over the individual components, we'll tie them all together with the server and
4-
client.
5-
6-
## Server
7-
8-
in the toyDB
3+
Now that we've gone over the individual components, we'll tie them all together in the toyDB
94
server `toydb::Server`, located in the [`server`](https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/server.rs) module.
105

116
The server wraps an inner Raft node `raft::Node`, which manages the SQL state machine, and is
@@ -113,60 +108,8 @@ https://github.com/erikgrinaker/toydb/blob/8f8eae0dcf70b1a0df2e853b1f6600e0c7075
113108

114109
toyDB is now up and running!
115110

116-
## Client Library
117-
118-
The main client library `toydb::Client` in the [`client`](https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs)
119-
module is used to connect to a toyDB server:
120-
121-
https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs#L15-L24
122-
123-
When initialized, it connects to a toyDB server over TCP:
124-
125-
https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs#L27-L33
126-
127-
It can then send Bincode-encoded `toydb::Request` to the server, and receives `toydb::Response`
128-
back.
129-
130-
https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs#L35-L40
131-
132-
133-
In particular, `Client::execute` can be used to execute arbitrary SQL statements in the client's
134-
session:
135-
136-
https://github.com/erikgrinaker/toydb/blob/213e5c02b09f1a3cac6a8bbd0a81773462f367f5/src/client.rs#L42-L56
137-
138-
## `toysql` Binary
139-
140-
However, `toydb::Client` is a programmatic API, and we want a more convenient user interface.
141-
The `toysql` client in [`src/bin/toysql.rs`](https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs)
142-
provides a typical [REPL](https://en.wikipedia.org/wiki/Read–eval–print_loop) (read-evaluate-print loop) where users can enter SQL statements and view the results.
143-
144-
Like `toydb`, `toysql` is a tiny [`clap`](https://docs.rs/clap/latest/clap/) command that takes a
145-
toyDB server address to connect to and starts an interactive shell:
146-
147-
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L29-L53
148-
149-
This first attempts to connect to the toyDB server using the `toydb::Client` client, and then starts
150-
an interactive shell using the [Rustyline](https://docs.rs/rustyline/latest/rustyline/) library.
151-
152-
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L55-L81
153-
154-
The shell is simply a loop that prompts the user to input a SQL statement:
155-
156-
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L216-L250
157-
158-
Each statement is the executed against the server via `toydb::Client::execute`, and the response
159-
is formatted and printed as output:
160-
161-
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L83-L92
162-
163-
https://github.com/erikgrinaker/toydb/blob/0839215770e31f1e693d5cccf20a68210deaaa3f/src/bin/toysql.rs#L175-L204
164-
165-
And with that, we have a fully functional SQL database system and can run queries to our heart's
166-
content. Have fun!
167-
168111
---
169112

170113
<p align="center">
171-
← <a href="sql-execution.md">SQL Execution</a>
114+
← <a href="sql-execution.md">SQL Execution</a> &nbsp; | &nbsp; <a href="client.md">Client</a> →
172115
</p>

docs/architecture/sql-execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,5 @@ And with that, we have a fully functional SQL engine!
115115
---
116116

117117
<p align="center">
118-
← <a href="sql-optimizer.md">SQL Optimization</a> &nbsp; | &nbsp; <a href="server.md">Server and Client</a> →
118+
← <a href="sql-optimizer.md">SQL Optimization</a> &nbsp; | &nbsp; <a href="server.md">Server</a> →
119119
</p>

0 commit comments

Comments
 (0)