-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: always start clean and update running instructions. (#2045)
I've been working with the examples quite a lot and I've commonly experienced stale database and disk state from running `docker compose up` in the foreground followed by `ctl+c` to stop and also from forgetting to run `pnpm backend:down`. So ... as a systemic solution, I've updated the `example-backend:up` script in the root package.json to always run `example-backend:down` first. This means that examples always start with a clean slate and no weird / stuck table and or disk state. I also then did a pass through the example READMEs, explaining this and re-formatting the instructions a touch.
- Loading branch information
Showing
13 changed files
with
343 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,60 @@ | ||
# Basic example | ||
|
||
This is an example of a basic ElectricSQL app using React. The Electric-specific code is in [`./src/Example.tsx`](./src/Example.tsx). | ||
|
||
## Setup | ||
|
||
1. Make sure you've installed all dependencies for the monorepo and built packages | ||
This example is part of the [ElectricSQL monorepo](../..) and is designed to be built and run as part of the [pnpm workspace](https://pnpm.io/workspaces) defined in [`../../pnpm-workspace.yaml`](../../pnpm-workspace.yaml). | ||
|
||
Navigate to the root directory of the monorepo, e.g.: | ||
|
||
```shell | ||
cd ../../ | ||
``` | ||
|
||
Install and build all of the workspace packages and examples: | ||
|
||
```shell | ||
pnpm install | ||
pnpm run -r build | ||
``` | ||
|
||
Navigate back to this directory: | ||
|
||
```shell | ||
cd examples/basic-example | ||
``` | ||
|
||
Start the example backend services using [Docker Compose](https://docs.docker.com/compose/): | ||
|
||
```shell | ||
pnpm backend:up | ||
``` | ||
|
||
> Note that this always stops and deletes the volumes mounted by any other example backend containers that are running or have been run before. This ensures that the example always starts with a clean database and clean disk. | ||
Now start the dev server: | ||
|
||
From the root directory: | ||
```shell | ||
pnpm dev | ||
``` | ||
|
||
- `pnpm i` | ||
- `pnpm run -r build` | ||
You should see three items listed in the page. These are created when first running the [`./db/migrations`](./db/migrations). | ||
|
||
2. Start the docker containers | ||
Now let's connect to Postgres, e.g.: using `psql`: | ||
|
||
`pnpm run backend:up` | ||
```shell | ||
psql "postgresql://postgres:password@localhost:54321/electric" | ||
``` | ||
|
||
3. Start the dev server | ||
Insert new data and watch it sync into the page in real time: | ||
|
||
`pnpm run dev` | ||
```sql | ||
insert into items (id) values (gen_random_uuid()); | ||
``` | ||
|
||
4. When done, tear down the backend containers so you can run other examples | ||
When you're done, stop the backend services using: | ||
|
||
`pnpm run backend:down` | ||
```shell | ||
pnpm backend:down | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,46 @@ | ||
# Linearlite | ||
|
||
This is an example Linear clone developed using ElectricSQL. | ||
|
||
## Setup | ||
|
||
1. Make sure you've installed all dependencies for the monorepo and built packages | ||
This example is part of the [ElectricSQL monorepo](../..) and is designed to be built and run as part of the [pnpm workspace](https://pnpm.io/workspaces) defined in [`../../pnpm-workspace.yaml`](../../pnpm-workspace.yaml). | ||
|
||
Navigate to the root directory of the monorepo, e.g.: | ||
|
||
```shell | ||
cd ../../ | ||
``` | ||
|
||
Install and build all of the workspace packages and examples: | ||
|
||
```shell | ||
pnpm install | ||
pnpm run -r build | ||
``` | ||
|
||
Navigate back to this directory: | ||
|
||
From the root directory: | ||
```shell | ||
cd examples/linearlite | ||
``` | ||
|
||
- `pnpm i` | ||
- `pnpm run -r build` | ||
Start the example backend services using [Docker Compose](https://docs.docker.com/compose/): | ||
|
||
2. Start the docker containers | ||
```shell | ||
pnpm backend:up | ||
``` | ||
|
||
`pnpm run backend:up` | ||
> Note that this always stops and deletes the volumes mounted by any other example backend containers that are running or have been run before. This ensures that the example always starts with a clean database and clean disk. | ||
3. Start the dev server | ||
Now start the dev server: | ||
|
||
`pnpm run dev` | ||
```shell | ||
pnpm dev | ||
``` | ||
|
||
4. When done, tear down the backend containers so you can run other examples | ||
When you're done, stop the backend services using: | ||
|
||
`pnpm run backend:down` | ||
```shell | ||
pnpm backend:down | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,46 @@ | ||
# Basic Next.js example | ||
|
||
This is an example Next.js application developed using ElectricSQL. | ||
|
||
## Setup | ||
|
||
1. Make sure you've installed all dependencies for the monorepo and built packages | ||
This example is part of the [ElectricSQL monorepo](../..) and is designed to be built and run as part of the [pnpm workspace](https://pnpm.io/workspaces) defined in [`../../pnpm-workspace.yaml`](../../pnpm-workspace.yaml). | ||
|
||
Navigate to the root directory of the monorepo, e.g.: | ||
|
||
```shell | ||
cd ../../ | ||
``` | ||
|
||
Install and build all of the workspace packages and examples: | ||
|
||
```shell | ||
pnpm install | ||
pnpm run -r build | ||
``` | ||
|
||
Navigate back to this directory: | ||
|
||
From the root directory: | ||
```shell | ||
cd examples/nextjs-example | ||
``` | ||
|
||
- `pnpm i` | ||
- `pnpm run -r build` | ||
Start the example backend services using [Docker Compose](https://docs.docker.com/compose/): | ||
|
||
2. Start the docker containers | ||
```shell | ||
pnpm backend:up | ||
``` | ||
|
||
`pnpm run backend:up` | ||
> Note that this always stops and deletes the volumes mounted by any other example backend containers that are running or have been run before. This ensures that the example always starts with a clean database and clean disk. | ||
3. Start the dev server | ||
Now start the dev server: | ||
|
||
`pnpm run dev` | ||
```shell | ||
pnpm dev | ||
``` | ||
|
||
4. When done, tear down the backend containers so you can run other examples | ||
When you're done, stop the backend services using: | ||
|
||
`pnpm run backend:down` | ||
```shell | ||
pnpm backend:down | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.