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 The Plumber

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 The Plumber

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…

TypeORM: Property ‘id’ has no initializer and is not definitely assigned in the constructor

February 6, 2022 A Goodman

When defining entities with TypeORM and TypeScript, you may encounter an annoying issue as follows: The warnings are present not only in the id field but also in all other fields in my classes entity: The…

TypeORM: Adding created_at and updated_at columns

February 6, 2022 A Goodman

In TypeORM, you can add a created_at column and a updated_at column by making use of the CreateDateColumn and UpdateDateColumn decorators, respectively. These columns will be automatically initialized and updated to the current date and time…

1 2 3