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

test(sql) add more tests #16918

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test/js/sql/sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,38 @@ if (isDockerEnabled()) {
expect(result[0]?.x).toBe(1);
});

test("should be able to execute different queries in the same connection #16774", async () => {
const sql = postgres({ ...options, max: 1, fetch_types: false });
const random_table_name = `test_user_${Math.random().toString(36).substring(2, 15)}`;
await sql`CREATE TEMPORARY TABLE IF NOT EXISTS ${sql(random_table_name)} (id int, name text)`;

const promises: Array<Promise<any>> = [];
// POPULATE TABLE
for (let i = 0; i < 1_000; i++) {
promises.push(sql`insert into ${sql(random_table_name)} values (${i}, ${`test${i}`})`.execute());
}
await Promise.all(promises);

// QUERY TABLE using execute() to force executing the query immediately
{
for (let i = 0; i < 1_000; i++) {
// mix different parameters
switch (i % 3) {
case 0:
promises.push(sql`select "id", "name" from ${sql(random_table_name)} where "id" = ${i}`.execute());
break;
case 1:
promises.push(sql`select "id" from ${sql(random_table_name)} where "id" = ${i}`.execute());
break;
case 2:
promises.push(sql`select 1, "id", "name" from ${sql(random_table_name)} where "id" = ${i}`.execute());
break;
}
}
await Promise.all(promises);
}
});

// test("Prepared transaction", async () => {
// await sql`create table test (a int)`;

Expand Down