Skip to main content

distinctOnTyped

Description​

distinctOnTyped is a method that applies typesafe distinctOn to a query in Postgres.

Signature​

distinctOnTyped(
...distinctOn: Array<KeyProxyCallback<Entity>>
): SelectQueryBuilder<Entity>

Arguments​

  • distinctOn: KeyProxyCallback<Entity>: The callbacks which select fields of entity for the DISTINCT ON rule. PostgreSQL only. A path into a JSON column (user => user.metadata.role) throws a TypeError: for a JSON value use tableHelper json / jsonText. A @CalculatedColumn selected with addSelectCalculated goes in under the alias orderByTyped orders it by, as DISTINCT ON has to match the leading ORDER BY; one not selected yet throws a TypeError.

Usage​

// same as `query.distinctOn(['user.name'])`
query.distinctOnTyped(user => user.name)
// same as `query.distinctOn(['user.createdAt', 'user.name'])`
query.distinctOnTyped(user => [
user.createdAt,
user.name,
])
// same as `query.distinctOn(['user.createdAt', 'user.name'])`
query.distinctOnTyped(
user => user.createdAt,
user => user.name
)