Pagination in TypeORM (Find Options & QueryBuilder)

May 20, 2022 Pennywise

This short and straight-to-the-point article shows you how to paginate data in TypeORM. Using Find(), FindAndCount() methods If you use a find method, you can implement pagination with the skip and take options: skip: offset from…

TypeORM: Entity with Decimal Data Type

May 20, 2022 Pennywise

In TypeORM, you can add a column with decimal data type like this: Where: precision: The number of digits in the decimal scale: The number of digits to the right of the decimal point Full example:…

TypeORM: Selecting Rows Between 2 Dates

May 3, 2022 A Goodman

The examples below show you how to select records between two given dates in TypeORM. The first one uses the find() function and the second uses query builder. Here’s the user entity that will have a…

TypeORM: Selecting Rows with Null Values

May 2, 2022 A Goodman

This succinct article is for people working with TypeORM who want to select records containing Null values. We’ll examine two examples. The first one uses the find() method, and the second uses Query Builder. Here’s the…

TypeORM: AND & OR operators

April 26, 2022 A Goodman

This concise, straight-to-the-point article gives a few quick examples of using AND and OR operators in TypeORM. No more rambling; let’s get our hands dirty by writing some code. Creating a sample entity In the coming…

TypeORM: How to store BIGINT correctly

April 22, 2022 Napoleon

If you’re using TypeORM to work with PostgreSQL or MySQL and want to save BIGINT (from -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)) to your database, you have to define your column as follows: The important thing here…

TypeORM: How to Limit Query Execution Time

April 23, 2022 Pennywise

When performing CRUD operations with TypeORM, you can set timeout (maximum execution time) for a certain query like so: If the query above takes more than 3000 milliseconds, it will be dropped to avoid crashing the…

TypeORM: 2 Ways to Exclude a Column from being Selected

April 23, 2022 Napoleon

When working with TypeORM, there might be cases where you want to exclude one or multiple columns (fields) from being selected. This succinct article will show you two different ways to do that. Make a column…

PostgreSQL: How to Rename a Column of a Table

February 25, 2022 A Goodman

In PostgreSQL, you can change the name of a column in a table by using the ALTER TABLE statement, like so: For example, I have a table called users and I want to change the name…

TypeORM: Adding Fields with Nullable/Default Data

February 25, 2022 A Goodman

By default, every field (column) of a TypeORM entity is NOT NULL. You can make a specific field become nullable by setting the nullable option to true, like this: In case you want to add the…

2 Ways to View the Structure of a Table in PostgreSQL

February 7, 2022 A Goodman

This concise article walks you through a couple of different ways to show the structure (schema) of a table in a PostgreSQL database. Without any further ado, let’s see the things that matter. Using psql 1….

Using ENUM Type in TypeORM

February 7, 2022 A Goodman

If you’re working with PostgreSQL or MySQL and making use of TypeORM in your code then you can add a column with the ENUM (enumerated) data type like so: This entity will create a table named…

1 2 3