https://github.com/joist-orm/joist-sample
https://github.com/joist-orm/joist-sample
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/joist-orm/joist-sample
- Owner: joist-orm
- Created: 2021-11-23T22:07:28.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-16T13:05:29.000Z (about 2 years ago)
- Last Synced: 2025-03-09T05:02:59.511Z (over 1 year ago)
- Language: TypeScript
- Size: 1.85 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# Joist Sample App
This is a bare minimum sample app using Joist as an ORM.
There are two domain objects, `Author` and `Book`, and a single test, `Author.test.ts`.
There are no examples of business logic or Joist's various features; for those see the docs.
## Setup
- `yarn`
- `yarn db`
- `yarn test`
## Example Workflow
A typical workflow for adding a new entity looks like:
- Run `yarn pg-new-migration "add publisher"`
- Edit the `migrations/...add-publisher.ts` file and add
```typescript
createEntityTable(pgm, "publishers", {
name: { type: "text", notNull: true },
});
```
- Run `yarn joist-migrate`
- If you change your migration, and want to re-apply it from scratch, run `docker-compose exec db ./reset.sh`
- Run `yarn joist-codegen`
- Copy/paste the `Author.test.ts` and write a test for `Publisher`
## Steps Taken to Setup This Repo
TODO: Automate this with more, probably with mrm.
- Install basic prettier/TypeScript/jest.
```shell
npm install -g mrm
npm install -g \
@homebound/mrm-tasks-prettier \
@homebound/mrm-tasks-gitignore \
@homebound/mrm-tasks-typescript
mrm @homebound/mrm-tasks-prettier \
@homebound/mrm-tasks-gitignore \
@homebound/mrm-tasks-typescript
```
- Copy/paste `migrations/...author.ts`
- Add `joist-orm`, `joist-migration-utils`, `joist-codegen` to `package.json`
- Copy/paste `run.sh`
- Copy/paste `env/local.env`, changed port
- Add `ts-node` to `package.json`
- Should come from `mrm`?
- Add `joist-migrate` script, run it
- Add `joist-codegen` script, run it
- Add `Author.test.ts`
- Add `env-cmd` to `package.json`
- Add `pg-migration` to `package.json`
- Add `.gitattributes` to suppress diffs on generated files