TypeORM: How to Execute Raw SQL Queries
In TypeORM, you can execute raw SQL queries by calling the query() method (you can access this method via your data source or the entity manager). You can do everything from CRUD data (create, read, update,…
TypeORM: ORDER BY Multiple Columns
In TypeORM, you can order your results by multiple columns. The 2 examples below show you how to do that. The first example uses the find() method whilst the second one uses a query builder. In…
TypeORM: Get Raw SQL Query from QueryBuilder
When communicating with databases through TypeORM, you can get raw SQL queries produced by query builders by using the getQuery() or getSql() methods (you can use them synchronously without the await keyword). Example: Output: If you…
TypeORM: How to Use Column Alias when Querying Data
This succinct tutorial shows you how to use column aliases to assign temporary names to columns when selecting data with TypeORM. The point here is the AS keyword. Let’s study a couple of examples for more…
TypeORM: Selecting DISTINCT Values
In real life, it’s possible that a column contains many duplicate values. However, there might be occasions when you only want to get different (unique) values. If you’ve worked with MySQL or PostgreSQL, you are very…
TypeORM: Counting Records in One-To-Many Relation
When communicating with the database through TypeORM, there will be many cases where you need to count records in a one-to-many relationship, such as: You want to list the users and the number of photos belonging…
Aggregation Operations in TypeORM (Sum, Avg, Min, Max, Count)
This short and straightforward article shows you how to perform aggregation operations in TypeORM. We’ll use a query builder and aggregate functions to calculate the following: Sum: The sum of the values Avg: The average value…
TypeORM: Select the Most Recent Record (2 Examples)
This short article walks you through 2 examples of selecting the latest record from a table using TypeORM. The first example uses the findOne() method, while the second one uses a query builder. Using the findOne()…
TypeORM: Using LIKE Operator (2 Examples)
In TypeORM, the Like operator (with the percent sign %) is used to search for a specified pattern in a column. This concise article walks you through 2 examples of selecting data with the Like operator…
TypeORM Upsert: Update If Exists, Create If Not Exists
Upsert (this term is combined from two words: update and insert) is a database operation that updates a record it already exists in a table. Otherwise, insert a new row if that record doesn’t exist. This…
TypeORM: Check Whether a Row Exists or Not
The 2 examples below demonstrate how to check if a record exists or not by using TypeORM findOne() method and query builder, respectively. Using the findOne() method Suppose we need to find a product named KatherineCode.com,…
Dart: Get Host, Path, and Query Params from a URL
In Dart, you can extract useful information from a given URL string by following the steps below: 1. Construct a Uri object from your URL string: 2. Now, you can get what you want through various…