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.
yarn idocker-compose up -d dbyarn pg-migrateyarn joist-codegen(if you've made migration/schema changes)yarn test
A typical workflow for adding a new entity looks like:
- Run
npm run pg-new-migration "add book review" - Edit the
migrations/...add-book-review.tsfile and addcreateEntityTable(pgm, "book_reviews", { book_id: foreignKey("books"), rating: { type: "integer", notNull: true }, });
- Run
yarn pg-migrate- If you change your migration, and want to re-apply it from scratch, run
docker-compose exec db ./reset.sh
- If you change your migration, and want to re-apply it from scratch, run
- Run
yarn joist-codegen - Copy/paste the
Author.test.tsand write a test forPublisher
TODO: Automate this with more, probably with mrm.
-
Install basic prettier/TypeScript/jest.
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-codegentopackage.json -
Copy/paste
.env, changed port -
Add
tsx,env-cmdtopackage.json- Should come from
mrm?
- Should come from
-
Add
pg-migratescript, run it -
Add
joist-codegenscript, run it -
Add
Author.test.ts -
Add
dotenvtopackage.json -
Add
pg-new-migrationtopackage.json -
Add
.gitattributesto suppress diffs on generated files