Skip to content

Conversation

@OlivierCavadenti
Copy link
Collaborator

  • Updating returning doc (#4471)

@kibertoad kibertoad merged commit ff93634 into knex:gh-pages Jan 13, 2022
Pl217 added a commit to UN-OCHA/hpc-api-core that referenced this pull request Aug 23, 2024
This is latest Knex version v1.x.x

https://github.com/knex/knex/blob/176151d8048b2a7feeb89a3d649a5580786d4f4e/CHANGELOG.md#107---13-april-2022
The only thing from Migration guide (linked above)
that looks like it can affect us is:
> `RETURNING` operations now always return an object with column names;

But looking at PR which added this feature -
knex/knex#4471
and PR that updated documentation -
knex/documentation#378
we can see that we're not affected, since
we always use `returning` as `returning('*')`

Changes to type definitions have one important change,
since `QueryCallback` was defined like this in `v0.95.15`
https://github.com/knex/knex/blob/0.95/types/index.d.ts#L1782

```ts
type QueryCallback<TRecord = any, TResult = unknown[]> = (
  ...
) => void;
```

which has changed to this in `v1.0.7`
https://github.com/knex/knex/blob/1.0.7/types/index.d.ts#L1842

```ts
type QueryCallback<TRecord extends {} = any, TResult = unknown[]> = (
  ...
) => void;
```

We can see that `extends {}` was added to `TRecord`,
so we need to make the same adjustment, otherwise
we get an error "Type `InstanceData` does not satisfy the constraint `{}`"

After this change, we can also reduce type assertions
in query building
Pl217 added a commit to UN-OCHA/hpc-api-core that referenced this pull request Aug 23, 2024
This is latest Knex version v1.x.x

https://github.com/knex/knex/blob/176151d8048b2a7feeb89a3d649a5580786d4f4e/CHANGELOG.md#107---13-april-2022
The only thing from Migration guide (linked above)
that looks like it can affect us is:
> `RETURNING` operations now always return an object with column names;

But looking at PR which added this feature -
knex/knex#4471
and PR that updated documentation -
knex/documentation#378
we can see that we're not affected, since
we always use `returning` as `returning('*')`

Changes to type definitions have one important change,
since `QueryCallback` was defined like this in `v0.95.15`
https://github.com/knex/knex/blob/0.95/types/index.d.ts#L1782

```ts
type QueryCallback<TRecord = any, TResult = unknown[]> = (
  ...
) => void;
```

which has changed to this in `v1.0.7`
https://github.com/knex/knex/blob/1.0.7/types/index.d.ts#L1842

```ts
type QueryCallback<TRecord extends {} = any, TResult = unknown[]> = (
  ...
) => void;
```

We can see that `extends {}` was added to `TRecord`,
so we need to make the same adjustment, otherwise
we get an error "Type `InstanceData` does not satisfy the constraint `{}`"

After this change, we can also reduce type assertions
in query building
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants