Skip to content

Commit ecc4120

Browse files
committed
Minor: a few more coffee tutorial tweaks.
1 parent a7af9ee commit ecc4120

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

docs/src/content/docs/getting-started/first-ui-app.mdx

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ title: >
66
import { Code } from "@astrojs/starlight/components";
77
import { Aside } from "@astrojs/starlight/components";
88

9-
In this tutorial, we'll set up a coffee database, implement a custom TypeScript
10-
HTTP handler for performing vector searches, and a simple production-ready web app
11-
all in ~100 lines of code.
12-
9+
This tutorial is a short introduction to TrailBase and some of its features.
10+
We'll bootstrap a database with coffee data, implement a custom TypeScript HTTP
11+
handler for finding the best coffee matches using vector search, and deploy a
12+
simple production-ready web app all in ~100 lines of code.
1313

1414
<div class="flex justify-center">
1515
<div class="w-[80%] shadow-lg ">
@@ -19,8 +19,8 @@ all in ~100 lines of code.
1919

2020
<div class="h-[24px]" />
2121

22-
This introductory tutorial is part of the main TrailBase code repository, which
23-
you can download to follow along running:
22+
This introductory tutorial is part of TrailBase's main code repository, which
23+
can be downloaded to follow along by running:
2424

2525
```bash
2626
$ git clone https://github.com/trailbaseio/trailbase.git
@@ -36,7 +36,8 @@ import GettingTrailBase from "./_getting_trailbase.md";
3636
## Importing Data
3737

3838
We'll use the `sqlite3` CLI directly to import
39-
`examples/coffeesearch/arabica_data_cleaned.csv` with the following SQL script[^1]:
39+
`examples/coffeesearch/arabica_data_cleaned.csv` with the following SQL
40+
script[^1]:
4041

4142
```sql
4243
-- First create the strictly typed "coffee" table.
@@ -72,47 +73,47 @@ FROM temporary;
7273
DROP TABLE temporary;
7374
```
7475

75-
Note that we didn't initialize the vector `embedding`. This is because the
76-
`sqlite3` CLI doesn't have the necessary extensions built-in.
77-
We'll update the entries to add the embedding later as part of a TrailBase
78-
migration.
76+
Note that we didn't initialize the vector `embedding`. This is merely because
77+
`sqlite3` doesn't have the necessary extensions built-in.
78+
We'll update the entries to add the embedding later as part of our initial
79+
database migrations shortly[^2].
7980

80-
While in `example/coffeesearch`, you can run
81+
From within the `example/coffeesearch` directory, you can execute the script
82+
above and import the coffee data by running:
8183

8284
```bash
8385
$ cat import.sql | sqlite3 traildepot/data/main.db -
8486
```
8587

86-
to execute above script.
87-
88-
After the initial data import and still in the same directory, let's start the
89-
`trail` binary for the first time:
88+
After importing the data while still in the same directory, we can start the
89+
`trail` server:
9090

9191
```bash
9292
$ trail run
9393
```
9494

95-
This will apply the migrations under `examples/coffeesearch/traildepot/migrations`, basically
95+
Because `trail` starts for the first time the migrations in
96+
`traildepot/migrations` will be applied, which are essentially:
9697

9798
```sql
9899
UPDATE coffee SET embedding = VECTOR(FORMAT("[%f, %f, %f, %f]", Aroma, Flavor, Acidity, Sweetness));
99100
```
100101

101-
to initialize the previously missing `coffee.embedding` for all records.
102+
initializing the previously skipped `coffee.embedding` for all records.
102103

103104

104105
## Custom TypeScript Endpoint
105106

106-
Starting `trail` also executes JavaScript and TypeScript files under
107-
`traildepot/scripts`.
107+
Any time you start `trail run`[^3], JavaScript and TypeScript files under
108+
`traildepot/scripts` will be executed.
108109

109110
<Aside type="note">
110111
TrailBase will automatically transpile TypeScript to JavaScript which can
111112
then execute on the underlying V8 engine. You don't need a separate build
112113
step.
113114
</Aside>
114115

115-
We can use this to register custom HTTP endpoints among other things.
116+
We can use this to register custom HTTP API routes among other things.
116117
Let's have a quick look at `examples/coffeesearch/traildepot/scripts/main.ts`,
117118
which defines a `/search` API route we'll later use in our application to
118119
find coffees most closely matching our desired coffee notes:
@@ -200,7 +201,7 @@ You can now check out your fuly self-contained app under
200201
[http://localhost:4000/](http://localhost:4000/) or browse the coffee data in
201202
the [admin dashboard](http://localhost:4000/_/admin).
202203

203-
All we need to serve our application in production is[^2]:
204+
All[^4] we need to serve our application in production is:
204205

205206
- the static `trail` binary,
206207
- the `traildepot` folder containing the data and endpoints,
@@ -221,9 +222,11 @@ $ docker build -t coffee . && docker run -p 4000:4000 coffee
221222
will speed-run this entire tutorial by building and starting the app listening
222223
at [http://localhost:4000/](http://localhost:4000/).
223224

224-
That's it. We hope this was a fun little introduction showcasing some of
225-
TrailBase's features. If you have any feedback, don't hesitate and reach
226-
out on [GitHub](https://github.com/trailbaseio/trailbase).
225+
That's it. We hope this was a fun little intro to some of TrailBase's features.
226+
There's more we haven't touched on: CRUD APIs, auth, admin dash, file uploads,
227+
just to name a few.
228+
If you have any feedback, don't hesitate and reach out on
229+
[GitHub](https://github.com/trailbaseio/trailbase).
227230

228231
<div class="h-[50px]" />
229232

@@ -235,6 +238,17 @@ out on [GitHub](https://github.com/trailbaseio/trailbase).
235238
[download](https://www.sqlite.org/download.html) pre-built binaries
236239

237240
[^2]:
241+
Migrations are versioned SQL scripts that will be executed by the database
242+
on first encounter to programmatically and consistently evolve your database
243+
schema and data along with your code.
244+
For example, when you add a new column you'll likely want all your
245+
integration tests, development setups, and production deployments to add
246+
the column so your application logic has a consistent schema to target.
247+
248+
[^3]:
249+
Unless explicitly disabled.
250+
251+
[^4]:
238252
To serve HTTPS you'll either need a reverse proxy in front to terminate TLS
239253
or if you don't require end-to-end encryption (e.g. you're not using auth
240254
or handling sensitive data) you can fall back to TLS termination via a CDN

0 commit comments

Comments
 (0)