This is the source repository for the SQLite demo app presented at Future Frontend January 2024 meetup.
The app in backend/bun-todo-api directory is an API server implemented with Bun and Stric.
First install dependencies:
bun iConfigure local SQLite:
echo "DATABASE_URL=file:todo.db" > .envGenerate migrations:
bun x drizzle-kit generate:sqlite --out migrations --schema db/schema.tsPush the migrations to the database:
bun x drizzle-kit push:sqliteInspect the database with Drizzle studio:
bun x drizzle-kit studioOr in the shell:
sqlite3 todo.dbAnd start the server:
bun run index.tsThe REST API server is now running on http://localhost:3000.
The app in frontend/react directory is the frontend for a Todo app, forked from https://github.com/tastejs/todomvc/tree/master/examples/react
To get started, install dependencies:
bun iStart the server:
bun run serveOpen the application in your browser.
You can import a SQLite database file with the following command:
turso db create --from-file todo.db todoRun the following to generate configuration to access a remote Turso database:
echo "DATABASE_URL=$(turso db show --url todo)" > .env.remote
echo "DATABASE_AUTH_TOKEN=$(turso db tokens create todo)" >> .env.remote
cp .env.remote .envRun the following to access an embedded database with offline sync:
echo "DATABASE_URL=file:local.db" > .env.sync
echo "SYNC_URL=$(turso db show --url todo)" >> .env.sync
echo "DATABASE_AUTH_TOKEN=$(turso db tokens create todo)" >> .env.sync
cp .env.sync .envThe app in backend/workers-todo-api directory an API server implemented with Cloudflare Workers.
Start the server locally:
npm startTo deploy it on Workers platform, you first configure database access credentials.
Update the wrangler.toml with a DATABASE_URL variable:
[vars]
DATABASE_URL = "<YOUR_DATABASE_URL>"Then configure database access token in .dev.vars:
.dev.vars
DATABASE_AUTH_TOKEN="<YOUR_AUTH_TOKEN>"
and configure it as a secret:
npx wrangler secret put DATABASE_AUTH_TOKENFinally, deploy to the Workers platform:
npm run deploy