Giter Site home page Giter Site logo

rozenmd / d1-northwind Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudflare/d1-northwind

0.0 0.0 0.0 6.4 MB

Northwind Traders D1 Demo

Home Page: https://northwind.d1sql.com/

License: MIT License

JavaScript 67.82% TypeScript 18.30% Makefile 1.30% HTML 1.90% SCSS 10.68%

d1-northwind's Introduction

D1 Northwind Demo

This repo has the code for https://northwind.d1sql.com/

What we use

Get the demo running

Requirements:

Clone this repo

[email protected]:cloudflare/d1-northwind.git

Install packages

npm install

Creating the database

npx wrangler d1 create d1-northwind
npx wrangler d1 create d1-northwind-staging

Get the output database id and add it to wrangler.toml

[[d1_databases]]
binding = "DB"
database_name = "d1-northwind"
database_id = "..."

Importing the database

npx wrangler d1 execute d1-northwind --file db/schema.sql
npx wrangler d1 execute d1-northwind --file db/data.sql

Do the same for northwind-staging if you need the staging environment.

Create KV namespaces

KV is used to store the React application

npx wrangler kv:namespace create assets
npx wrangler kv:namespace create assets --preview

Add the ids to wrangler.toml

React application

Northwind is a React/Redux/Tailwind CSS application. The source code is in the app folder folder.

To build a new version run:

npx rollup -c rollup.app.config.js

Worker backend

Worker serves both the React app bundles from KV, and the Database API endpoints. The source code is in the worker folder.

To build it run:

npx rollup -c rollup.worker.config.js

Or run:

make build

Which will build both the React app, and the Worker. Running wrangler also watches and rebuilds the worker.

Local development

Wrangler D1 has support for local development:

npx wrangler d1 execute d1-northwind --file db/schema.sql --local
npx wrangler d1 execute d1-northwind --file db/data.sql --local
npx wrangler dev --local --persist --env local --assets local-assets --ip 0.0.0.0

Wrangler will persist a local SQLite compatible sql file which you can access to with other clients:

sqlite3 .wrangler/state/d1/DB.sqlite3
.tables

Dev environment

You can test things in the developer environment, remotely.

npx wrangler kv:key put app.js --path ./dist/app.js --binding assets --env dev --preview
npx wrangler kv:key put app.css --path ./dist/app.css --binding assets --env dev --preview
npx wrangler dev --env dev

Or just run

make dev

Deploying

Deploy to production when you're done.

npx wrangler kv:key put app.js --path ./dist/app.js --binding assets --env production
npx wrangler kv:key put app.css --path ./dist/app.css --binding assets --env production
npx wrangler publish --env production

Or simply

make publish

Adding something like this will bind the worker to a specific route/domain.

[env.production]
route = "northwind.d1sql.com/*"

d1-northwind's People

Contributors

dotjs avatar

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.