Skip to content

Commit

Permalink
Add Fetch and Move PG AST nodes (#40)
Browse files Browse the repository at this point in the history
* Add Fetch and Move PG AST nodes

* Fix missing exports for SetConfigurationParameter and SetTimeZone

* Simplify direction AST for Fetch and Move

Replace `'Forward'` with `Forward({count: 1})` and `ForwardAll` with
`Forward({count: 'All'})`. Ditto with `Backward`.
  • Loading branch information
mulias authored May 17, 2024
1 parent 3d0b1fc commit 6cf3abb
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions packages/sij-dialect-postgresql/src/ast/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Ident, IsolationLevel, StringLit, NumLit, Interval } from 'sij-core/ast
import { Tagged, UnTag, tag } from 'sij-core/util';

type PgUtil =
| Fetch
| Move
| SetConfigurationParameter
| SetTimeZone
| SetConstraints
| SetRole
| ResetRole
Expand All @@ -13,6 +17,79 @@ type PgUtil =
| Unlisten
| Vacuum;

/*
FETCH [ direction ] [ FROM | IN ] cursor_name
*/
interface Fetch
extends Tagged<
'Fetch',
{
readonly direction: DirectionOption;
readonly cursorName: Ident;
}
> {}
const Fetch = (args: UnTag<Fetch>): Fetch => tag('Fetch', args);

/*
MOVE [ direction ] [ FROM | IN ] cursor_name
*/
interface Move
extends Tagged<
'Move',
{
readonly direction: DirectionOption;
readonly cursorName: Ident;
}
> {}
const Move = (args: UnTag<Move>): Move => tag('Move', args);

type DirectionOption =
| 'Next'
| 'Prior'
| 'First'
| 'Last'
| 'All'
| Absolute
| Relative
| Forward
| Backward

interface Absolute
extends Tagged<
'Absolute',
{
readonly count: NumLit;
}
> {}
const Absolute = (args: UnTag<Absolute>): Absolute => tag('Absolute', args);

interface Relative
extends Tagged<
'Relative',
{
readonly count: NumLit;
}
> {}
const Relative = (args: UnTag<Relative>): Relative => tag('Relative', args);

interface Forward
extends Tagged<
'Forward',
{
readonly count: NumLit | 'All' | null;
}
> {}
const Forward = (args: UnTag<Forward>): Forward => tag('Forward', args);

interface Backward
extends Tagged<
'Backward',
{
readonly count: NumLit | 'All' | null;
}
> {}
const Backward = (args: UnTag<Backward>): Backward => tag('Backward', args);

/*
SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | 'value' | DEFAULT }
*/
Expand Down Expand Up @@ -260,6 +337,10 @@ const Size = (args: UnTag<Size>): Size => tag('Size', args);

export {
PgUtil,
Fetch,
Move,
SetConfigurationParameter,
SetTimeZone,
SetConstraints,
SetRole,
ResetRole,
Expand Down

0 comments on commit 6cf3abb

Please sign in to comment.