Skip to content

Commit 38ad82b

Browse files
committed
test
1 parent 892764e commit 38ad82b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: test/js/sql/sql.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,38 @@ if (isDockerEnabled()) {
594594
expect(result[0]?.x).toBe(1);
595595
});
596596

597+
test("should be able to execute different queries in the same connection #16774", async () => {
598+
const sql = postgres({ ...options, max: 1, fetch_types: false });
599+
const random_table_name = `test_user_${Math.random().toString(36).substring(2, 15)}`;
600+
await sql`CREATE TEMPORARY TABLE IF NOT EXISTS ${sql(random_table_name)} (id int, name text)`;
601+
602+
const promises: Array<Promise<any>> = [];
603+
// POPULATE TABLE
604+
for (let i = 0; i < 1_000; i++) {
605+
promises.push(sql`insert into ${sql(random_table_name)} values (${i}, ${`test${i}`})`.execute());
606+
}
607+
await Promise.all(promises);
608+
609+
// QUERY TABLE using execute() to force executing the query immediately
610+
{
611+
for (let i = 0; i < 1_000; i++) {
612+
// mix different parameters
613+
switch (i % 3) {
614+
case 0:
615+
promises.push(sql`select "id", "name" from ${sql(random_table_name)} where "id" = ${i}`.execute());
616+
break;
617+
case 1:
618+
promises.push(sql`select "id" from ${sql(random_table_name)} where "id" = ${i}`.execute());
619+
break;
620+
case 2:
621+
promises.push(sql`select 1, "id", "name" from ${sql(random_table_name)} where "id" = ${i}`.execute());
622+
break;
623+
}
624+
}
625+
await Promise.all(promises);
626+
}
627+
});
628+
597629
// test("Prepared transaction", async () => {
598630
// await sql`create table test (a int)`;
599631

0 commit comments

Comments
 (0)