TypeORM: Create case-insensitive search functionality

Creating a basic search feature where the records are as follows:

AB CD
A BCD
ABC D
ABD C

If the search term is "BCD", the expected output should be:

AB CD
A BCD
ABC D

The current query looks like this:

await connection.manager
.createQueryBuilder(RefTransaction, 'rt')
.where('rt.key LIKE :searchText',
{searchText: '%' + <searchText> + '%' })
.getRawMany();

How can we modify this to incorporate the MySQL replace function in TypeORM?

Answer №1

const transactions = await connection.manager
.createQueryBuilder(RefTransaction, 'rt')
.where('replace(rt.key, " ", "") LIKE :searchText',
      {searchText: '%' + <searchText>.replace(" ","") + '%' })
.getRawMany();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The variable 'data' is not a property of the type 'any[]'

I am currently facing an issue with a dummy service I created to fetch dummy data. When calling this service from a component ts file, I encountered the following error. After searching through some similar posts, I still haven't been able to resolve ...

Error in Angular Apollo V3: Jest unable to locate module 'apollo-angular'

After recently updating angular apollo from version 2.6.0 to v3.0.0, my tests have been broken. I use jest for unit testing, and although the application compiles and runs without any issues, my tests cannot import any dependencies from 'apollo-angul ...

Creating a timer that counts down and executing a SQL query with PHP upon completion

I've implemented a jQuery script that counts down the time until the variable $end, displaying "completed" when it reaches zero. However, I've noticed that changing the time on your computer also affects the countdown. I want my countdown to be ...

Tips for merging two distinct filters

I've developed a basic filter for date intervals and different levels (0, 1, 2). Here is the code that I have implemented: if(isset($_POST['filtersubmit'])){ $datex = str_replace('/', '-', $_POST['firstdate&apos ...

Creating an NPM package using Visual Studio 2017: A Step-by-Step Guide

I enjoy developing and publishing NPM packages using Visual Studio 2017. My preferred method is using TypeScript to generate the JavaScript files. Which project template would be best suited for this particular project? ...

Using React with Typescript and ie18next to fetch translations from an external API

In the past, I have experience working with i18next to load translations from static json files. However, for my current project, I need to load all translations from an API. How can I achieve this? Additionally, how can I implement changing the translat ...

Eliminate elements from an array using a specific key for filtering

My Array is called MainArray MainArray=[{ {First Name: "First Name"}, {Last Name: "Contact"}, {Last Name: "Contact"} ] I am trying to trim the key-value pair from this array like this: if (key == 'First Name') { del ...

The filtering feature in the Row Group table of PrimeNG controls is malfunctioning and causing issues with the Dropdown

Within my Angular project, I have integrated PrimeNG controls version 11.4.4. Utilizing the Table control, I've structured tabular data to display rows in a grouped fashion with collapsible functionality. I've recently introduced a textbox and d ...

Looking for assistance with MySQL DISTINCT functionality

I need to extract unique names from a mysql table to use in an autocomplete feature with jQuery UI. However, there are duplicate names in the table and I want to avoid displaying them in the suggestions. Additionally, I also require selecting other colum ...

Issues with the POST API functionality in an express / node.js application when using mysql database

Recently, I have been diving into learning nodejs and experimenting with creating a post API that interacts with static data stored in a MySQL database. Let me briefly share the configuration setup I am working on: const mysql = require('mysql') ...

Loading a view in Ionic2 with Angular2 after a successful subscription

After completing an http post request, I want to navigate to the next view in my app. Here is a breakdown of the three services I am using: The server service handles generic http calls such as get and post requests. The city service stores a list of ...

What is the best way to retrieve data from within a for loop in javascript?

Seeking assistance in Typescript (javascript) to ensure that the code inside the for loop completes execution before returning I have a text box where users input strings, and I'm searching for numbers following '#'. I've created a fun ...

Is CORS necessary when using npm, and is Putty a viable tool for web application development?

Currently, I am immersed in a web application project that relies on the following technologies: Express.js + Node.js MySQL Angular 4 PM2 (Process manager) Here are the libraries utilized on the backend: express body-parser jsonwebtoken bcrypt-nodejs ...

Oops! The program encountered an issue on the production environment, but it's running smoothly

When I execute Webpack using the command node node_modules/webpack/bin/webpack. js --env. prod An error message is displayed below. However, when running in --env. dev mode, the command executes without any issues. Can't resolve './../$$_gen ...

What techniques can I use to adjust the size of an image through zooming in and out?

In my custom gallery component, the crucial code section looks like this: <Gallery> <Header> <img src={galleryIcon} alt='Galley icon' /> <h1>My Gallery</h1> </Header> ...

"I am looking for a way to incorporate animation into my Angular application when the data changes. Specifically, I am interested in adding animation effects to

Whenever I click on the left or right button, the data should come with animation. However, it did not work for me. I tried adding some void animation in Angular and placed a trigger on my HTML element. The animation worked when the page was refreshed, bu ...

The issue arises when attempting to use the `HAVING` clause in conjunction

I'm currently analyzing the average sale price during a specific time frame. Here is a summary of the dataset: *products* productID name 1 Beef Burger 2 Crispy Chicken Burger *sale_products* productID sale_price quantity created ...

The error message "React is not defined" is commonly encountered when using React Native Storybook with

While attempting to configure React Native with Storybook, I encountered an issue when importing a .tsx component. The error displayed was: React is not defined ...

The file isn't located in 'rootDir', even though all the details seem to be accurate

I'm currently troubleshooting an issue with one package in my nx monorepo that is causing the error code "TS6059". Interestingly, all other packages are functioning correctly in previous builds. After reviewing my index.ts files, it appears that all ...

Encountering an issue while trying to import the instanceMethods function within Sequelize

In a file, I have written a function and exported it like this: export function foo(params...) { // do something } When initializing the model, I imported the function in the following manner: import { foo } from "../path/..." instanceMethods: { foo ...