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

Discrepancy between InsertObject and Insertable #1265

Open
shoooe opened this issue Nov 18, 2024 · 0 comments
Open

Discrepancy between InsertObject and Insertable #1265

shoooe opened this issue Nov 18, 2024 · 0 comments

Comments

@shoooe
Copy link

shoooe commented Nov 18, 2024

I have a ts vector column and I'm trying to populate it via a raw sql tag but if I do it directly in an insertInto statement then it compiles correctly:

await db
    .insertInto("entities")
    .values({
        // ...
        searchVector: sql`...`,
    })
.returningAll()
.execute();

but if I extract the values into a variable:

const x: Insertable<Entities> = {
    // ...
    searchVector: sql`...`,
}

then it complains that the expected type for searchVector is string.

I've looked at the code and it seems that for Insertable this is the accepted input:

export type Insertable<R> = DrainOuterGeneric<{
    [K in NonNullableInsertKeys<R>]: InsertType<R[K]>;
} & {
    [K in NullableInsertKeys<R>]?: InsertType<R[K]>;
}>;

while for values the input type is:

export type InsertObject<DB, TB extends keyof DB> = {
    [C in NonNullableInsertKeys<DB[TB]>]: ValueExpression<DB, TB, InsertType<DB[TB][C]>>;
} & {
    [C in NullableInsertKeys<DB[TB]>]?: ValueExpression<DB, TB, InsertType<DB[TB][C]>> | undefined;
};

which apparently accepts raw sql.

I would have expected the two types to be equivalent. Is there a practical reason for not accepting raw sql in Insertable? Or am I missing something?

Thanks ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant