Coder Social home page Coder Social logo

penberg / future-frontend-sqlite-demo Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 2.07 MB

Future Frontend January 2024 meetup SQLite demo app

HTML 3.54% JavaScript 74.52% CSS 2.61% TypeScript 19.33%
drizzle drizzle-orm edge edge-computing libsql sqlite sqlite3

future-frontend-sqlite-demo's Introduction

Future Frontend: SQLite Demo

This is the source repository for the SQLite demo app presented at Future Frontend January 2024 meetup.

Backend (Bun)

The app in backend/bun-todo-api directory is an API server implemented with Bun and Stric.

First install dependencies:

bun i

Configure local SQLite:

echo "DATABASE_URL=file:todo.db" > .env

Generate migrations:

bun x drizzle-kit generate:sqlite --out migrations --schema db/schema.ts

Push the migrations to the database:

bun x drizzle-kit push:sqlite

Inspect the database with Drizzle studio:

bun x drizzle-kit studio

Or in the shell:

sqlite3 todo.db

And start the server:

bun run index.ts

The REST API server is now running on http://localhost:3000.

Frontend

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 i

Start the server:

bun run serve

Open the application in your browser.

Moving your database to Turso

You can import a SQLite database file with the following command:

turso db create --from-file todo.db todo

Run 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 .env

Run 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 .env

Backend (Cloudflare Workers)

The app in backend/workers-todo-api directory an API server implemented with Cloudflare Workers.

Start the server locally:

npm start

To 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_TOKEN

Finally, deploy to the Workers platform:

npm run deploy

future-frontend-sqlite-demo's People

Contributors

penberg avatar

Stargazers

Duc-Thien Bui avatar Juho Vepsäläinen avatar John (Kanary Hong) avatar flow avatar rok avatar 底なし沼の魔女 avatar azu avatar Tai Groot avatar

Watchers

 avatar  avatar

Forkers

aca

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.