Skip to content

Commit

Permalink
Added week 10 assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
harkirat singh authored and harkirat singh committed Feb 5, 2024
1 parent 05eff6f commit 2807e70
Show file tree
Hide file tree
Showing 16 changed files with 7,040 additions and 7 deletions.
23 changes: 22 additions & 1 deletion week-10/1-postgres-simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,25 @@ and put it in config.ts
You are supposed to write the `database` part of an full stack app.
Specifically, you need to fill the functions in
- src/db/user.ts
- src/db/todo.ts
- src/db/todo.ts

## Testing
Run `npm run test` to run all the tests

## Call out
The schema of the tables looks like this -
```
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL
);
CREATE TABLE IF NOT EXISTS todos (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id),
title VARCHAR(255) NOT NULL,
description TEXT,
done BOOLEAN DEFAULT false
);
```
6 changes: 0 additions & 6 deletions week-10/1-postgres-simple/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ import { DB_URL } from './config';
export const client = new Client({
connectionString: DB_URL
});

function seed() {

}

seed();
3 changes: 3 additions & 0 deletions week-10/2-prisma-simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
14 changes: 14 additions & 0 deletions week-10/2-prisma-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Prisma Assignment
Same as the last assignment, but you need to use `prisma` as the ORM.

## Pre-requisites
1. Checkout `prisma/schema.prisma` and see the initial schema that has been created.
2. Replace `db.url` with your database URL.
3. Run the following commands to migrate your database -
```js
npx prisma migrate dev
npx prisma generate
```

## Assignment
You need to fill the db/user.ts and db/todos.ts using the `prisma` client to put in the data
14 changes: 14 additions & 0 deletions week-10/2-prisma-simple/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
// Optionally, set up paths to match your project structure
roots: ['<rootDir>/src'],
// Transform settings if you have custom needs, but this is optional since ts-jest is preset
transform: {
'^.+\\.ts$': 'ts-jest',
},
// Module file extensions for importing
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};

Loading

0 comments on commit 2807e70

Please sign in to comment.