Wasswa  Meagan

Wasswa Meagan

1631768400

Learn About Range Types in PostgreSQL and TypeORM

Sometimes when working with databases, we need to represent a range of values. For example, we might want to define a set of available numbers or a range of dates. One way to do that would be to create two columns that hold the bound values.

#typeorm #postgresql 


 

Learn About Range Types in PostgreSQL and TypeORM
Wasswa  Meagan

Wasswa Meagan

1631765982

How to Define Constraints with PostgreSQL and TypeORM

In this article, we use constraints to have even more control of our data. With constraints, we can reject the data that doesn’t match our guidelines. By doing so, we can ensure the integrity of our data to a greater extent than by doing that through the application logic.
#postgresql #typeorm 

How to Define Constraints with PostgreSQL and TypeORM
Alfie Mellor

Alfie Mellor

1630339154

The Active Record and Data Mappers of ORM Pattern

TypeORM: ORM Patterns. Active Record vs Data Mapper.

Timestamps:

Intro - 0:00
Creating User Entity - 0:20
Setting up a User repository to show Data Mapper approach - 1:30
User Entity as an Active Record - 3:36
Outro - 6:04

➥ Repo: https://github.com/pragmatic-reviews/typeormexample/tree/mapperactiverecord

#typeorm #orm 

The Active Record and Data Mappers of ORM Pattern
Veronica  Roob

Veronica Roob

1626050400

Setting Up TypeORM with MySQL | Microservices Chat App Part 2

Follow us on Instagram! https://www.instagram.com/bettercodingacademy/

Get a A$100,000/year job as a web developer!

https://codebetter.com.au

Source code: https://github.com/lucaschen/microservices-chat-demo

#typeorm #mysql #microservices #react

Setting Up TypeORM with MySQL | Microservices Chat App Part 2
Miguel  Cormier

Miguel Cormier

1625988008

TypeORM Crash Course - TypeScript & Node ORM

TypeORM is a great node ORM that allows you to create tables and perform CRUD operations with TypeScript & JavaScript. You can use it with multiple databases like MySQL, Postgres or MongoDB.

Postgres install:
https://www.postgresql.org/download/

Postico install:
https://eggerapps.at/postico/

GitHub Repo:
https://github.com/harblaith7/typeorm-crash-course

Timeline:

  • 0:00 - Intro
  • 5:35 - Setup
  • 8:30 - Connecting to the DB
  • 22:06 - Entities
  • 43:45 - Relationships
  • 1:01:30 - Inserting Data
  • 1:15:15 - Forming Relationships
  • 1:34:49 - Deleting Data
  • 1:43:10 - Fetching Data

#typeorm #typescript #node

TypeORM Crash Course - TypeScript & Node ORM
Eva  Murphy

Eva Murphy

1625823600

Nestjs | User Registration and Password Hash with Bcrypt With TypeORM Hooks - 15

#nestjs #node #typeorm

In this video, we are going to look at how we can structure our code so that users can register for the application. We will relook at the core concepts, look at how user requests will be handled.

And, we will also look at how we can use bcrypt along with TypeOrm hooks to save a hashed password into the database.

Github code: https://my-lnk.com/r/2188012324

#nestjs #typeorm #node #typeorm #bcrypt

Nestjs | User Registration and Password Hash with Bcrypt With TypeORM Hooks - 15
Eva  Murphy

Eva Murphy

1625812440

Loading Quiz with Questions - Query, Joins and Nested Relations in TypeORM 12

In this video, we are going to look at how we can work with TypeORM and use joins to load other relations.

The idea is to have an API that will take the quiz ID and return a JSON object containing the Quiz data along with the questions and options for that particular quiz.

Github code: https://my-lnk.com/r/2233233755

#typeorm #nest #nestjs #query #nested

Loading Quiz with Questions - Query, Joins and Nested Relations in TypeORM 12
Eva  Murphy

Eva Murphy

1625801340

Entity Relation with TypeORM and Saving Questions 08

#nestjs #node #javascript #postgres #typeorm

Now that our quiz entity is ready, let’s look at how we can set up our question entity so that we can start saving them to DB using a simple POST API.

In this lesson, we are going to use the concepts which we have learned so far and try to create the Create API.

The idea is to get the entity ready so that in the next lesson we will look at our first relation in TypeORM.

Code: https://my-lnk.com/r/2233233755

#entity #node #javascript #postgres #typeorm #typeorm

Entity Relation with TypeORM and Saving Questions 08
Eva  Murphy

Eva Murphy

1625797620

Creating the Question entity for Quiz 07

#nestjs #node #javascript #postgres #typeorm

Now that our quiz entity is ready, let’s look at how we can set up our question entity so that we can start saving them to DB using a simple POST API.

In this lesson, we are going to use the concepts which we have learned so far and try to create the Create API.

The idea is to get the entity ready so that in the next lesson we will look at our first relation in TypeORM.

Code: https://my-lnk.com/r/2233233755

#nestjs #javascript #node #postgres #typeorm #quiz

Creating the Question entity for Quiz 07
Eva  Murphy

Eva Murphy

1625793480

Creating the Question entity for Quiz 07

#nestjs #node #javascript #postgres #typeorm

Now that our quiz entity is ready, let’s look at how we can set up our question entity so that we can start saving them to DB using a simple POST API.

In this lesson, we are going to use the concepts which we have learned so far and try to create the Create API.

The idea is to get the entity ready so that in the next lesson we will look at our first relation in TypeORM.

Code: https://my-lnk.com/r/2233233755

#nestjs #javascript #node #postgres #typeorm

Creating the Question entity for Quiz 07
Torrey  Kuphal

Torrey Kuphal

1621738273

TypeORM Relations Tutorial - FULL details!

In this video we’re going to go deep into the fundamentals of creating relationships between tables in an application which uses TypeORM.
We’ll review a target schema which we’ll represent in code. We’re going to cover all the typical table relationships you might have, like One-to-One, One-to-Many, Many-to-One, and Many-to-Many, as well as things like how to configure ON DELETE behavior, working with foreign keys, etc. Then we’ll discuss the different ways to query records with their related data!

  • 00:00 - Intro and ERD
  • 03:39 - Employee Entity
  • 04:49 - Contact Info Entity
  • 05:33 - One-to-One example
  • 10:45 - On Delete CASCADE
  • 11:54 - Task Entity
  • 12:16 - One-to-Many / Many-to-One
  • 13:28 - On Delete SET NULL
  • 14:42 - Self referencing: manager/direct reports
  • 17:31 - Meeting entity and Many-to-Many
  • 23:05 - Various examples of inserting records and relating them to each other
  • 36:00 - Querying entities with their relations using the Find API
  • 39:34 - Querying entities with their relations using the Query Builder API
  • 42:17 - Testing behavior of what happens when related things are deleted
  • 45:12 - The Cascade option
  • 47:08 - Eager and Lazy Relations
  • 48:40 - Outro

#typeorm #typescript

TypeORM Relations Tutorial - FULL details!
Torrey  Kuphal

Torrey Kuphal

1615962026

TypeORM Tutorial: Migrations, queries, and more! | NestJS

Quite possibly one of the best ORMs you can use with NodeJS (and even more so with NestJS) is TypeORM! In this video I’ll walk you through how to set it up, connect to your database, generate and run migrations for production use, use the Repository API, create custom queries, database relationships, and so much more! If you’re looking to get started with TypeORM to create some CRUD APIs you’re on the right video!

  • 00:00 - Intro
  • 02:14 - Part I: Setup & Install
  • 08:12 - Part II: Creating an entity
  • 11:36 - Migrations for production
  • 20:48 - Part III: Injecting Repositories into Providers
  • 22:48 - Part IV: Repository API & querying
  • 35:35 - Testing our CRUD queries
  • 39:19 - Part V: Relationships
  • 45:01 - Conclusion
  • 45:14 - Outro

#typeorm #nestjs #nodejs #database

TypeORM Tutorial: Migrations, queries, and more! | NestJS
Gordon  Matlala

Gordon Matlala

1615264090

The Most Convenient Ways of Writing Transactions Within the Nest.js + TypeORM Stack

In many cases, developers must use transactions when performing various operations on the server. For example - a transfer of money, or other measurable value, and much more.

With such operations, I really do not want to receive an error that will interrupt the process and violate the data integrity.

What is a “transaction” anyway? Wikipedia  says:

“A database transaction symbolizes a unit of work performed within a database management system (or similar system) against a database, and treated in a coherent and reliable way independent of other transactions. A transaction generally represents any change in a database.”

Transactions in a database environment have two main purposes:

  1. To provide reliable units of work that allow correct recovery from failures and keep a database consistent even in cases of system failure, when execution stops (completely or partially) and many operations upon a database remain uncompleted, with unclear status.
  2. To provide isolation between programs accessing a database concurrently. If this isolation is not provided, the programs’ outcomes are possibly erroneous.

Now, consider a situation where an error can occur, leading to very unpleasant consequences if you do not use transactions.

I made a small  project in which there are two entities:

  • User
  • Purse

Users can transfer money to each other. When transferring, the sufficiency of the amount on the balance of the sender is checked, as well as many other checks. If a situation occurs when the money has been debited from the sender’s balance but not transferred to the recipient’s account, or vice versa, we will see either a very sad, angry person, or we will not see a very happy one (depends on the transfer amount).

#nodejs #nestjs #typescript #npm #typeorm

The Most Convenient Ways of Writing Transactions Within the Nest.js + TypeORM Stack
Lawrence  Lesch

Lawrence Lesch

1614829740

Combine GraphQL with TypeORM and NestJS using Perch Query Builder

Unrestricted normalization depth, arguments, filtering, sorting, and paginating without special logic custom to each ORM Entity

This article assumes you have a basic grasp of  NestJS as well as how it is implemented with TypeORM and the  NestJS GraphQL package. If you are looking for how to get a basic project up and running take a look the the docs posted in the links. This article also uses a Code-First approach, if you aren’t sure what that means this is a good rundown of benefits and differences over a Schema-First approach.

What, why, and for whom

GraphQL is quickly becoming a staple of the future API, it provides a new and much more dynamic perspective on how the data layer of your application(s) should be consumed and developed. Using a GraphQL-First approach, every feature revolves around a GraphQL schema, allowing your front-end team and your API team work independently knowing that the two pieces will work together when they are ready. Rather than simple REST API endpoints that resolve the same object structure (and potentially just look-ups to other endpoints in lieu of actual children) we can provide all the properties and relationships we want in a single request.

In my experience with NestJS and TypeORM the integration of GraphQL is a little funky. First of all, the structure and depth of the query is only provided to your custom resolver in a semi-enigmatic object (@Info() info: GraphQLResolveInfo), and there are no clear pathways to handling the selected attributes inside of a query which is a problem if we want to structure the TypeORM query to meet the depth requirements of the incoming GraphQL query.

This package’s goal is to bridge the gap between your GraphQL and TypeORM implementation. Rather than writing a custom tailored resolver that can only go _n _layers deep or writing your own custom sorting, filtering, and pagination handling, PerchQueryBuilder provides all of those features ignorant of the literal structure of your entity, allowing you easy and simple integration with GraphQL. Since this package is merely an attempt to translate GraphQL into TypeORM, the queries are handled as though they are a direct translation to your ORM entities property and relationship names, since it relies on TypeORM’s definitions of your entities. For instance, if you had an entity named Book, with a many-to-one relationship to an Author entity called author you would need to specify _author _as a selected attribute (as well as any of the properties beneath Author) to the query in order to retrieve it.

#graphql #typeorm #programming #typescript #nestjs

Combine GraphQL with TypeORM and NestJS using Perch Query Builder
Dexter  Goodwin

Dexter Goodwin

1614738314

Solve Database Concurrency Issues with TypeOrm

I use a pattern in my services where I have methods that always return an Entity but it is up to that method whether to retrieve it from the database or create it newly. I call these methods

getOrCreate*methods.

An example. Users can add a

Tagto aPost. When a user enters a tag “JavaScript”, I have a method in theTagServicecalledgetOrCreateTag(name: string). In that method I lower-case the name and try to fetch tags from the data base with that homogenized name. In case it finds it, it retrieves it, otherwise it will create a new Tag Entity and retrieve that.

This can lead to a problem. When two requests to the backend occur at the exact same time, with the exact same string, two tags with the same name are inserted. (You think it is unlikely? Please read the note below the article!)

What happens in slow-mo:

  1. Request A: asks whether that Tag exists
  2. Doesn’t find it
  3. Decides to create it
  4. Request B meanwhile asks whether that Tag exists
  5. Doesn’t find it
  6. Decides to create it
  7. Request A creates it
  8. Request B creates it

You may prevent that easily by a unique key constraint. But you only shift the issue. Because then step 8. will just fail with an exception leaving the application crashing.

One way to fix it, I will describe here implemented with TypeOrm.

Pessimistic lock

A lock of the database is always created during writing to the database. For example, step 7. and 8. both create a super short-living write lock. However, the issue was, that in step 2. and 5. respectively both requests couldn’t find it and **already **decided they are gonna write it to the database.

A pessimistic read lock is something you create manually. In TypeOrm you need the database connection for that.

#typeorm #typescript #concurrency

Solve Database Concurrency Issues with TypeOrm