Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Cannot chain methods to type db.select() #2573

Open
ridhwaans opened this issue Jul 1, 2024 · 0 comments
Open

[BUG]: Cannot chain methods to type db.select() #2573

ridhwaans opened this issue Jul 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ridhwaans
Copy link

ridhwaans commented Jul 1, 2024

What version of drizzle-orm are you using?

^0.30.10

What version of drizzle-kit are you using?

^0.21.4

Describe the Bug

let query = db
        .select()
        .from(postsTable)
        .leftJoin(...
        
        
     const whereConditions = [];
        if (input?.genreName) {
          whereConditions.push(eq(genresTable.name, input.genreName));
        }
        if (input?.keyword) {
          whereConditions.push(eq(keywordsTable.name, input.keyword));
        }
    
        if (whereConditions.length > 0) {
          query = query.where(or(...whereConditions)); // error
        }

if you need to conditionally include certain where filters, its not easy to build a select query

Property 'where' is missing in type 'Omit<import("/node_modules/drizzle-orm/sqlite-core/query-builders/select").SQLiteSelectBase<"movies", "async", import("/node_modules/@libsql/core/lib-esm/api").ResultSet, Record<"movies", { id: import("/node_modules/drizzle-orm/sqlit...' but required in type 'Omit<import("/node_modules/drizzle-orm/sqlite-core/query-builders/select").SQLiteSelectBase<"movies", "async", import("/node_modules/@libsql/core/lib-esm/api").ResultSet, Record<"movies", { id: import("/node_modules/drizzle-orm/sqlit...'.ts(2741)
select.d.ts(379, 5): 'orderBy' is declared here.
let query: Omit<SQLiteSelectBase<"posts", "async", ResultSet, Record<"posts", {
    id: SQLiteColumn<{
        name: "id";
        tableName: "posts";
        dataType: "number";
        columnType: "SQLiteInteger";
        data: number;
        driverParam: number;
        notNull: true;
        hasDefault: true;
        enumValues: undefined;
        baseColumn: never;
    }, object>;
    ... 20 more ...;
    ...

Also, it would be beneficial if combining filters accepts a list structure

.where(
or(
[eq(...),..]
))

Expected behavior

It should not produce an error when building a select query. Or support nested filters in findMany

Environment & setup

node

@ridhwaans ridhwaans added the bug Something isn't working label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant