Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Feb 3, 2025
1 parent 9cfa3a5 commit 9e29722
Showing 1 changed file with 32 additions and 0 deletions.
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

0 comments on commit 9e29722

Please sign in to comment.