packages/sql-semantics-postgres/src/Statement/Invocation/FrameBoundKind.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\PostgreSql\Statement\Invocation;
6
7/**
8 * Where a window frame starts or ends.
9 *
10 * Source: https://www.postgresql.org/docs/17/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS.
11 *
12 * @visibility public
13 * @example Telling which bounds take an offset
14 *     \SqlSemantics\Platform\PostgreSql\Statement\Invocation\FrameBoundKind::OffsetPreceding->offset() // => true
15 */
16enum FrameBoundKind: string
17{
18    case UnboundedPreceding = 'UNBOUNDED PRECEDING';
19    case OffsetPreceding = 'PRECEDING';
20    case CurrentRow = 'CURRENT ROW';
21    case OffsetFollowing = 'FOLLOWING';
22    case UnboundedFollowing = 'UNBOUNDED FOLLOWING';
23
24    /**
25     * Tells whether the bound is an offset expression before PRECEDING or FOLLOWING.
26     */
27    public function offset(): bool
28    {
29        return $this === self::OffsetPreceding || $this === self::OffsetFollowing;
30    }
31}
32