Skip to content

Instantly share code, notes, and snippets.

View nmchenry01's full-sized avatar

Nicholas McHenry nmchenry01

  • Boulder, CO
View GitHub Profile
@nmchenry01
nmchenry01 / app.module.ts
Created July 6, 2020 19:54
Root Module for "Why you should use NestJS for your next project" Blog
import { Module } from '@nestjs/common';
import { TaskModule } from './modules/task/task.module';
import { UserModule } from './modules/user/user.module';
@Module({
imports: [TaskModule, UserModule],
})
export class AppModule {}
@nmchenry01
nmchenry01 / task.module.ts
Created July 6, 2020 19:56
Task Module for "Why you should use NestJS for your next project" Blog
import { Module } from '@nestjs/common';
import { TaskService } from './task.service';
import { TaskController } from './task.controller';
@Module({
controllers: [TaskController],
providers: [TaskService],
})
export class TaskModule {}
@nmchenry01
nmchenry01 / task.controller.ts
Created July 6, 2020 19:59
Task Controller V1 for "Why you should use NestJS for your next project" Blog
import { Controller, Get, Post } from '@nestjs/common';
@Controller('task')
export class TaskController {
@Post()
createTask(): string {
return 'This action adds a new task';
}
@Get()
@nmchenry01
nmchenry01 / task.controller.ts
Created July 6, 2020 20:02
Task Controller V2 for "Why you should use NestJS for your next project" Blog
import { Controller, Get, Post } from '@nestjs/common';
import { TaskService } from './task.service';
import { Task } from './models/task.entity';
@Controller('task')
export class TaskController {
constructor(private taskService: TaskService) {}
@Post()
createTask(@Body() task: Task): void {
@nmchenry01
nmchenry01 / task.service.ts
Created July 6, 2020 20:05
Task Service for "Why you should use NestJS for your next project" Blog
import { Injectable } from '@nestjs/common';
import { Task } from './models/task.entity';
@Injectable()
export class TaskService {
private readonly tasks: Task[] = [];
createTask(task: Task): void {
this.tasks.push(task);
@nmchenry01
nmchenry01 / schema.prisma
Created August 11, 2020 23:13
An example Prisma schema for "Prisma vs. TypeORM"
generator client {
provider = "prisma-client-js"
previewFeatures = ["transactionApi"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
@nmchenry01
nmchenry01 / .env
Created August 11, 2020 23:36
An example Prisma .env file for "Prisma vs. TypeORM"
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables
# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="postgresql://admin:password@localhost:5432/admin?schema=public"
@nmchenry01
nmchenry01 / createCompany.ts
Last active August 13, 2020 22:48
The first Prisma create example for "Prisma vs. TypeORM"
const createCompany = async (prisma: PrismaClient) => {
await prisma.company.create({
data: {
name: 'Acme',
},
});
};
@nmchenry01
nmchenry01 / index.d.ts
Created August 13, 2020 14:37
The company type definition example for "Prisma vs. TypeORM"
/**
* Company create
*/
export type CompanyCreateArgs = {
/**
* Select specific fields to fetch from the Company
**/
select?: CompanySelect | null
/**
* Choose, which related nodes to fetch as well.
@nmchenry01
nmchenry01 / createProduct.ts
Last active August 13, 2020 22:48
Create product example for "Prisma vs. TypeORM"
const createProduct = async (prisma: PrismaClient) => {
await prisma.product.create({
data: {
name: 'Dynamite',
description: 'It goes "boom"',
company: {
connect: {
name: 'Acme',
},
},