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 / createCustomer.ts
Last active August 13, 2020 22:47
Create customer example for "Prisma vs. TypeORM"
const createCustomer = async (prisma: PrismaClient) => {
await prisma.customer.create({
data: {
username: 'Customer1',
email: 'Customer1@gmail.com',
products: {
connect: [
{
name: 'Car',
},
@nmchenry01
nmchenry01 / nestedWrite.ts
Last active August 13, 2020 22:47
Nested write example for "Prisma vs. TypeORM"
const nestedWrite = async (prisma: PrismaClient) => {
await prisma.company.create({
data: {
name: 'Globex',
products: {
create: {
name: 'Car',
description: 'A fine automobile',
customers: {
connect: { username: 'Customer1' },
@nmchenry01
nmchenry01 / findCompanyByName.ts
Last active August 13, 2020 22:46
Find company by name example for "Prisma vs. TypeORM"
export const findCompanyByName = async (prisma: PrismaClient) => {
return prisma.company.findOne({
where: {
name: 'Globex',
},
});
};
@nmchenry01
nmchenry01 / findConsumersForCompany.ts
Last active August 13, 2020 23:04
Find customer usernames for a specific company example for "Prisma vs. TypeORM"
export const findCustomerUsernamesForCompany = async (prisma: PrismaClient) => {
return prisma.customer.findMany({
select: {
username: true,
},
orderBy: {
username: 'desc',
},
where: {
products: {
@nmchenry01
nmchenry01 / multipleFilters.ts
Created August 13, 2020 23:22
Multiple filters example for "Prisma vs. TypeORM"
const findCompaniesThatMakeCarsOrDynamite = async (prisma: PrismaClient) => {
return prisma.company.findMany({
where: {
OR: [
{
products: {
some: {
name: 'Car',
},
},
@nmchenry01
nmchenry01 / deleteCustomer.ts
Created August 13, 2020 23:35
Delete customer example for "Prisma vs. TypeORM"
const deleteCustomer = async (prisma: PrismaClient) => {
return prisma.customer.delete({
where: {
username: 'Customer4',
},
});
};
@nmchenry01
nmchenry01 / ormconfig.json
Last active August 18, 2020 12:25
ormconfig example for "Prisma vs. TypeORM"
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "admin",
"password": "password",
"database": "postgres",
"synchronize": true,
"entities": [
"dist/**/*.entity.js"
@nmchenry01
nmchenry01 / company.entity.ts
Created August 20, 2020 10:38
Company entity for "Prisma vs. TypeORM"
@Entity()
export class Company {
@PrimaryGeneratedColumn()
id: number;
@Column({ unique: true })
name: string;
@CreateDateColumn()
createdAt: string;
@nmchenry01
nmchenry01 / product.entity.ts
Created August 20, 2020 10:42
Product entity for "Prisma vs. TypeORM"
@Entity()
export class Product {
@PrimaryGeneratedColumn()
id: number;
@Column({ unique: true })
name: string;
@Column({ nullable: true })
description?: string;
@nmchenry01
nmchenry01 / customer.entity.ts
Created August 20, 2020 10:43
Customer entity for "Prisma vs. TypeORM"
@Entity()
export class Customer {
@PrimaryGeneratedColumn()
id: number;
@Column({ unique: true })
username: string;
@Column({ unique: true })
email: string;