Where clause as string in Find/FindOne TypeOrm

Henrique Assis

I was searching and reading the docs, but coundn't find a solution.

Is there a way to set the where param as string in find/findOne method in TypeOrm?

Because, it seens that TypeOrm doens't accepts private attributes as a param in find/findOne methods, and I understand why.

Example, this is the class used:

import { Column } from 'typeorm';

@Entity()
export default class Client extends BaseEntity{
    ...

    @Column({ name: 'email', type: 'varchar', length: 64, unique: true })
    private _email: string;

    ...
}

This is the controller function:

...

async function testing(request: Request, response: Response, next: NextFunction) {
    const { name, email, password } = request.body;
    
    const existingClient = await Client.findOne({ _email: email });

    console.log(existingClient);
}

...

I thought creating something like:

await Client.findOne({`email = [email protected]`});

Is there a way to do this?

sandrooco

I would recommend to simply use it as public.

When you really want to use private, you probably need to use the entitymanager:

entityManager
    .createQueryBuilder(Client, "client")
    .where("client._email = :email", { email: '[email protected]' })
    .getOne();

What is and how to add entityManager: https://typeorm.io/#/working-with-entity-manager

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

typeOrm using condition in where clause

TypeORM query builder conditional where clause

TypeORM find where clause, how to add where in multiple parameter

What is wrong with the parameters in my Typeorm WHERE clause for the QueryBuilder?

After common Typeorm query builder instance, where clause not working

Optimal search string in the where clause

Append string in where clause in SQL

MySQL Where Clause By Last String

Parsing where clause as string in Java

TypeORM, add condition in `where` if value is presented and not empty string

using a string of values in WHERE clause - mysql

Prepare WHERE Clause string for given values

String based Dynamic Linq - Nested Where clause

MySQL automatic string to integer casting in where clause?

migrating to dbcontext LINQ where clause string parameter

Rails: Cast string field to integer in where clause

How to pass string to where clause - mySQL

Passing a string in where clause in Rails is always quoted

How to compare int with string in linq where clause

using a string value as boolean in WHERE clause

including array of string into "where GTID in (arrayname)" clause

Converting string to array and using in where clause

SAS Macro, passing value as string to where clause

Regex to match the date from string with where clause

Laravel get values that contains string in where clause

DataTable.Select string function in where clause

Linq query with string array in where clause

PHP variable string in Where clause is empty

Typeorm find with and & or where block