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

Db raw queries should not reuse/cache types #619

Open
lionelhorn opened this issue Dec 5, 2024 · 0 comments
Open

Db raw queries should not reuse/cache types #619

lionelhorn opened this issue Dec 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@lionelhorn
Copy link
Contributor

//packages/sqlite/tests/sqlite.spec.ts

// new test
test('raw > return types from separate queries should not be reused', async () => {
    const database = await databaseFactory([]);

    const q1 = await database.raw<{ count1: number }>(sql`SELECT 42 AS count1`);
    const r1 = await q1.findOne();

    const q2 = await database.raw(sql`SELECT 42 AS count2`);
    const r2 = await q2.findOne();
    //^^^^^^^^^^^^^^^^^^^^^^
    // this call incorrectly tries to deserialize the query return value using the type passed at the previous query ({ count1: number })
    // and will consequently throw

    // @ts-ignore
    expect(r1.count1).toEqual(r2.count2)
});

when running the test, error message is
Validation error for type {count1: number}: count1(type): Not a number ValidationError: Validation error for type {count1: number}:

@marcj marcj added the bug Something isn't working label Dec 5, 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

2 participants