Skip to content

v33.0.0

Compare
Choose a tag to compare
@github-actions github-actions released this 09 Nov 20:01
· 377 commits to main since this release
d2f62c8
Distinguish between SQL query and fragment (#429)

BREAKING CHANGE:

### Replaces `sql` tagged template literal with `sql.fragment`.

Before:

```ts
const where = sql`WHERE bar = 1`

sql`
  SELECT 1
  FROM foo
  ${where}
`
```

After:

```ts
const where = sql.fragment`WHERE bar = 1`

sql.fragment`
  SELECT 1
  FROM foo
  ${where}
`
```

### SQL fragments cannot be used as queries; use `sql.type` instead

Before:

```ts
connection.query(sql`
  SELECT 1
  FROM foo
`)
```

After:

```ts
connection.query(sql.type({
  id: z.object({
    id: z.number(),
  })
})`
  SELECT 1 AS id
  FROM foo
`)
```

### Adds `sql.unsafe` (shortcut to `sql.type(z.any())`)

Before:

```ts
connection.query(sql`
  SELECT 1
  FROM foo
`)
```

After:

```ts
connection.query(sql.unsafe`
  SELECT 1
  FROM foo
`)
```

### Query methods can no longer by typed, i.e. `connection.one<Row>()` needs to be replaced with `connection.one(sql.type()``)`.

Before:

```ts
connection.oneFirst<number>(sql`
  SELECT 1
  FROM foo
`)
```

After:

```ts
connection.oneFirst(sql.typeAlias('id')`
  SELECT 1 AS id
  FROM foo
`)
```