Skip to content

describe an unsafe insert stmt is being executed #424

@Newbie012

Description

@Newbie012

Given the following code:

await sql`create table tester (name text unique, age int)`
const r1 = await sql`insert into tester (name, age) values ('postgres', 1)`.describe()
const r2 = await sql`insert into tester (name, age) values ('postgres', 1)`.describe()

everything seems to work fine

But, changing it to use .unsafe instead, will actually run these inserts into the database, and in this specific case - will fail on the second run due to a unique constraint.

Reproduction:

t('Describe an unsafe insert statement with unique constraint', async() => {
  const q = "insert into tester (name, age) values ('postgres', 1)";
  await sql`create table tester (name text unique, age int)`
  await sql.unsafe(q).describe()
  await sql.unsafe(q).describe()
  return [undefined, undefined, await sql`drop table tester`]
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions