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…

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

August 20, 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…

Unsigned (non-negative) Integer in PostgreSQL

February 5, 2022 A Goodman

In PostgreSQL, you can add a constraint that enforces a column to have only non-negative integers by using the CHECK keyword. Example A product can have a price greater or equal to 0 (e.g. a free…

2 Ways to Rename a Table in PostgreSQL

February 5, 2022 A Goodman

This short article shows you 2 different ways to rename a table in a PostgreSQL database. The first approach is to execute the ALTER TABLE statement with the RENAME keyword and the second one is to…

1 2 3 4 5