Template
Wire up Drizzle (MySQL), Redis, and Swagger docs for coursework
This commit is contained in:
@@ -1,15 +1,35 @@
|
||||
# Elysia with Bun runtime
|
||||
# ElysiaJS Boilerplate
|
||||
|
||||
## Getting Started
|
||||
To get started with this template, simply paste this command into your terminal:
|
||||
```bash
|
||||
bun create elysia ./elysia-example
|
||||
```
|
||||
Starter for the ElysiaJS coursework workspace: Bun + ElysiaJS + TypeScript,
|
||||
with MySQL (Drizzle ORM) and Redis wired up to the shared course databases.
|
||||
|
||||
## Development
|
||||
To start the development server run:
|
||||
```bash
|
||||
bun install
|
||||
bun run db:push # creates the `notes` table from src/db/schema.ts
|
||||
bun run dev
|
||||
```
|
||||
|
||||
Open http://localhost:3000/ with your browser to see the result.
|
||||
Open http://localhost:3000/swagger for interactive API docs (auto-generated
|
||||
from the routes in `src/index.ts`).
|
||||
|
||||
## What's here
|
||||
- `src/index.ts` - the app: a couple of example routes showing MySQL reads/
|
||||
writes via `src/db` and Redis reads/writes via `src/redis.ts`. Delete the
|
||||
examples once you understand the pattern and start building your own.
|
||||
- `src/db/schema.ts` - your Drizzle table definitions. Add tables here, then
|
||||
run `bun run db:push` to sync them to MySQL (no migration files needed for
|
||||
coursework - `push` just diffs your schema against the live database).
|
||||
- `src/db/index.ts` / `src/redis.ts` - pre-configured clients, reading
|
||||
connection details from environment variables. In your Coder workspace
|
||||
these are already set for you (`MYSQL_*`, `REDIS_*`) - you never need to
|
||||
type a password into code.
|
||||
- `.env.example` - only needed if you want to run this outside your Coder
|
||||
workspace, against your own local MySQL/Redis.
|
||||
|
||||
## Notes
|
||||
- Your Redis user can only touch keys under `student:<your-username>:*`
|
||||
(enforced by the server) - that's why `src/index.ts` prefixes cache keys
|
||||
with `REDIS_USERNAME`. Keys outside that prefix will be rejected.
|
||||
- Your MySQL user only has access to your own database - no need to specify
|
||||
it beyond what's already in `MYSQL_DATABASE`.
|
||||
|
||||
Reference in New Issue
Block a user