Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Objection
  • Loading branch information
rychkog committed Jun 9, 2019
1 parent 53a52e3 commit 5644b32
Show file tree
Hide file tree
Showing 27 changed files with 1,975 additions and 61 deletions.
1 change: 1 addition & 0 deletions .env
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:docker@localhost:5432/postgres
14 changes: 14 additions & 0 deletions README.md
@@ -1,13 +1,25 @@
# Reducing mental fatigue: NestJS + Objection.js

This is a companion repository for my article.

Practical part of this article shows how to use NestJS with Objection.js ORM.
There I've developed a toy API, which purpose is to show concepts I've described.

## Prerequisites

## Hot to run

- `npm i`
- `npm run run:pg-docker`
- `npm run migrate && npm run seed`
- `npm run start`

API is accessible at `http://localhost:3001`

## Example API requests

### Themes

```bash
# findAll
curl http://localhost:3001/api/themes
Expand All @@ -26,6 +38,7 @@ curl -X DELETE http://localhost:3001/api/themes/6
```

### Tags

```bash
# findAll
curl http://localhost:3001/api/tags
Expand All @@ -44,6 +57,7 @@ curl -X DELETE http://localhost:3001/api/tags/6
```

### Notes

```bash
# findAll
curl http://localhost:3001/api/notes
Expand Down
17 changes: 17 additions & 0 deletions knexfile.ts
@@ -0,0 +1,17 @@
import 'dotenv/config';
import * as Knex from 'knex';
import { knexSnakeCaseMappers } from 'objection';

module.exports = {
client: 'pg',
connection: process.env.DATABASE_URL,
migrations: {
directory: './src/database/migrations',
stub: './src/database/migration.stub',
},
seeds: {
directory: './src/database/seeds',
stub: './src/database/seed.stub'
},
...knexSnakeCaseMappers()
} as Knex.Config;

0 comments on commit 5644b32

Please sign in to comment.