How come the combination of "where" and "take" doesn't function properly with Query Builder in TypeORM?

Recently, I've been utilizing the query builder feature provided by typeorm.

It has been functioning perfectly with my use of the where function as well as the take function. When using the where function alone, it correctly retrieves 5 items and when the first value is set to 3, it retrieves 3 items as expected. However, an issue arises when using both functions simultaneously. In this scenario, it only returns one item consistently. Can anyone pinpoint what mistake I might be making?

public async search(first?: number): Promise<Item[]> {
    const findConditions: FindConditions<Item> = {
        deleted: IsNull(),
    };

    return this.itemRepository
        .createQueryBuilder()
        .select("item")
        .from(Item, "item")
        .where(findConditions)
        .take(first)
        .getMany();
}

Answer №1

My current issue stems from incorrect syntax usage. Since I am utilizing the query builder in conjunction with my itemRepository, there is no need to employ the select and from functions, as they can result in an erroneous FROM statement.

The following implementation resolves this:

public async search(first?: number): Promise<Item[]> {
    const findConditions: FindConditions<Item> = {
        deleted: IsNull(),
    };

    return this.itemRepository
        .createQueryBuilder()
        .where(findConditions)
        .take(first)
        .getMany();
}

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

Jest v29 Upgrade Issue: Test environment jest-environment-jsdom not found

Are there any success stories of upgrading to the newest version of Jest, specifically version 29? I keep encountering an error message: Error: Test environment jest-environment-jsdom cannot be found. Please ensure that the testEnvironment configuration ...

Discovering routes in Angular2

I'm attempting to replicate something similar to this example here: AngularJS show div based on url/condition <span id="page-locator" *ngIf="location.path() == '/overview'">test</span> Unfortunately, it's not working as ex ...

Guide to dynamically resizing the Monaco editor component using react-monaco-editor

Currently, I am integrating the react-monaco-editor library into a react application for viewing documents. The code snippet below showcases how I have set specific dimensions for height and width: import MonacoEditor from 'react-monaco-editor'; ...

Join the Observable and formControl in Angular 4 by subscribing

My goal is to display the data retrieved from FireStore in the screen fields upon loading. However, the buildForm() function is being called before subscribing to the data, resulting in the failure to populate the screen fields with the FireStore data. pe ...

I am unable to utilize useContext in my React app with TypeScript

I am a beginner in TypeScript and I'm currently working on developing a Todo application using the 'useContext' hook in TypeScript-React. I'm facing an issue while trying to pass the TodoContextProviderProps as a prop below to my Provi ...

Exploring the Limitations of TypeScript Type Inference Using Recursive Typing

Exploring the world of Advanced Type definitions in TypeScript has been quite the challenging journey for me, as I try to experiment with different approaches. One concept I am keen on exploring is a "wizard-step-by-step" method: function fillWizardOptio ...

Newest preact and typescript packages causing issues with type validation

Despite my efforts to integrate preact with TypeScript, I have encountered a problem where incorrect types can be passed without any error being raised. I am in the process of transitioning our codebase from plain JavaScript to preact with type scripting. ...

Retrieving data from a callback function in node.js

Here is a function implemented in the following way: function con(){ database.connect(con, (err, con) => { conn.query("select * from person", (err, rs) => { console.log(rs)--->result return rs ...

What is the appropriate data type for the children in React when using a function?

When using a function to pass children and return React.ReactNode into a Provider HOC, the code looks like this: <Provider variables={{ id: "qwerty" }}> {data => ( <ExampleComponent data={data} /> )} </Provider> An example of ...

The Angular 5 keyup event is being triggered twice

My app is incredibly simple, just a basic hello world. To enhance its appearance, I incorporated bootstrap for the design and ng-bootstrap for the components. Within one of my TS files, you will find the following code: showMeTheKey(event: KeyboardEvent) ...

Differences between Typescript React.ReactElement and JSX.Element

Simple Inquiry: I'm curious about the contrast between React.ReactElement and JSX.Element. Can you clarify if they are interchangeable, and advise on when to opt for one over the other? ...

How can I create and utilize a nested array within an ngFor loop?

*ngFor="let arr = ['foo', 'bar', 'sla']; let item of arr; let i = index;" Why does setting the instantiation of arr before let item of arr; result in an exception displaying [object Object]? Why am I unable to structure it th ...

Filling out Modal Forms with angular

My issue is with using ngFor to generate and display data within a modal form. When clicking on any element, only the data of the first element on the page appears in the modal form. How can I make it so that the data changes for each element clicked? He ...

How can I pass an anonymous type into angle brackets in TypeScript?

Illustration: class CustomComponent extends React.Component< {propertyItem: number}, {statusItem: boolean} > { constructor(properties: ???) { // what is the proper way to specify the property type? } render() { } } I am aware that one a ...

Updating variable in a higher-level component in Angular 7

Currently, I am utilizing Angular 7. Within my child component displayed in the Stackblitz example below, I have encountered an obstacle. Although I can access my variable on the parent control by using @Input, I am unable to change it. Could you provide g ...

What could be the reason for receiving the error message "NgModule' is not found" even after executing the command "npm i @types/node --global"?

Even though I tried following the suggestions provided in this Stack Overflow thread, I am still encountering the error "TypeScript error in Angular2 code: Cannot find name 'module'". My development environment consists of Angular 5 and npm versi ...

Is it possible to incorporate regular React JSX with Material UI, or is it necessary to utilize TypeScript in this scenario?

I'm curious, does Material UI specifically require TypeScript or can we use React JSX code instead? I've been searching for an answer to this question without any luck, so I figured I'd ask here. ...

Deep copying arrays in Typescript using the spread operator

I'm really struggling to grasp the concept of the spread operator in TypeScript. Every time I try to use it to duplicate object1. let object2 = { ...object1, }; I end up with a brand new object2 that contains all the items from object1, even if t ...

Achieving the incorporation of multiple components within a parent component using Angular 6

Within parent.component.html The HTML code I have implemented is as follows: <button type="button" class="btn btn-secondary (click)="AddComponentAdd()">Address</button> <app-addresse *ngFor="let addres of collOfAdd" [add]="addres">< ...

Having trouble locating the error in my Angular and Spring Security application

I am currently working on a project that involves integrating Spring Security with an Angular client. I have encountered an issue where, despite checking for null values in the login form on the Angular side before sending it to the Java application, the J ...