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 createCompany = async () => { | |
| const companyRepository = getRepository(Company); | |
| const acme = companyRepository.create({ name: 'Acme' }); | |
| await companyRepository.save(acme); | |
| }; |
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 createProduct = async () => { | |
| const productRepository = getRepository(Product); | |
| const companyRepository = getRepository(Company); | |
| const acme = await companyRepository.findOne({ where: { name: 'Acme' } }); | |
| const dynamite = productRepository.create({ | |
| name: 'Dynamite', | |
| description: 'It goes "boom"', | |
| company: acme, |
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 createCustomer = async () => { | |
| const customerRepository = getRepository(Customer); | |
| const productRepository = getRepository(Product); | |
| const dynamite = await productRepository.findOne({ | |
| where: { name: 'Dynamite' }, | |
| }); | |
| const car = await productRepository.findOne({ | |
| where: { | |
| 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 findCompanyByName = async () => { | |
| const companyRepository = getRepository(Company); | |
| return companyRepository.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
| const findCustomersForCompany = () => { | |
| const customerRepository = getRepository(Customer); | |
| return customerRepository | |
| .createQueryBuilder('customer') | |
| .innerJoinAndSelect('customer.products', 'products') | |
| .innerJoinAndSelect('products.company', 'company') | |
| .andWhere('company.name = :name', { name: 'Acme' }) | |
| .select('customer.username') | |
| .orderBy('customer.username', 'DESC') |
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 () => { | |
| const companyRepository = getRepository(Company); | |
| return companyRepository | |
| .createQueryBuilder('company') | |
| .innerJoinAndSelect('company.products', 'product') | |
| .andWhere('product.name IN (:...names)', { names: ['Car', 'Dynamite'] }) | |
| .getMany(); | |
| }; |
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 updateProductDescription = async (prisma: PrismaClient) => { | |
| return prisma.product.update({ | |
| where: { | |
| name: 'Printer', | |
| }, | |
| data: { | |
| description: 'It works sometimes', | |
| }, | |
| }); | |
| }; |
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 updateProductDescription = async () => { | |
| const productRepository = getRepository(Product); | |
| return productRepository.update( | |
| { name: 'Printer' }, | |
| { description: 'It works sometimes' }, | |
| ); | |
| }; |
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 () => { | |
| const customerRepository = getRepository(Customer); | |
| return customerRepository.delete({ username: 'User4' }); | |
| }; |
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 experimentalTransaction = async (prisma: PrismaClient) => { | |
| const createCompany = prisma.company.create({ data: { name: 'Umbrella' } }); | |
| const createCustomer = prisma.customer.create({ | |
| data: { username: 'User5', email: 'User5@gmail.com' }, | |
| }); | |
| return prisma.transaction([createCompany, createUser]); | |
| }; |