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 aTypeError: for a JSON value use tableHelperjson/jsonText. A @CalculatedColumn selected withaddSelectCalculatedgoes in under the aliasorderByTypedorders it by, as DISTINCT ON has to match the leading ORDER BY; one not selected yet throws aTypeError.
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
)