This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createCustomer = async (prisma: PrismaClient) => { | |
| await prisma.customer.create({ | |
| data: { | |
| username: 'Customer1', | |
| email: 'Customer1@gmail.com', | |
| products: { | |
| connect: [ | |
| { | |
| name: 'Car', | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const nestedWrite = async (prisma: PrismaClient) => { | |
| await prisma.company.create({ | |
| data: { | |
| name: 'Globex', | |
| products: { | |
| create: { | |
| name: 'Car', | |
| description: 'A fine automobile', | |
| customers: { | |
| connect: { username: 'Customer1' }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const findCompanyByName = async (prisma: PrismaClient) => { | |
| return prisma.company.findOne({ | |
| where: { | |
| name: 'Globex', | |
| }, | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const findCustomerUsernamesForCompany = async (prisma: PrismaClient) => { | |
| return prisma.customer.findMany({ | |
| select: { | |
| username: true, | |
| }, | |
| orderBy: { | |
| username: 'desc', | |
| }, | |
| where: { | |
| products: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const findCompaniesThatMakeCarsOrDynamite = async (prisma: PrismaClient) => { | |
| return prisma.company.findMany({ | |
| where: { | |
| OR: [ | |
| { | |
| products: { | |
| some: { | |
| name: 'Car', | |
| }, | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const deleteCustomer = async (prisma: PrismaClient) => { | |
| return prisma.customer.delete({ | |
| where: { | |
| username: 'Customer4', | |
| }, | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "type": "postgres", | |
| "host": "localhost", | |
| "port": 5432, | |
| "username": "admin", | |
| "password": "password", | |
| "database": "postgres", | |
| "synchronize": true, | |
| "entities": [ | |
| "dist/**/*.entity.js" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity() | |
| export class Company { | |
| @PrimaryGeneratedColumn() | |
| id: number; | |
| @Column({ unique: true }) | |
| name: string; | |
| @CreateDateColumn() | |
| createdAt: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity() | |
| export class Product { | |
| @PrimaryGeneratedColumn() | |
| id: number; | |
| @Column({ unique: true }) | |
| name: string; | |
| @Column({ nullable: true }) | |
| description?: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity() | |
| export class Customer { | |
| @PrimaryGeneratedColumn() | |
| id: number; | |
| @Column({ unique: true }) | |
| username: string; | |
| @Column({ unique: true }) | |
| email: string; |