Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to restart identity on truncate #42

Merged
merged 6 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/syntax/delete.ne
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ delete_delete -> (kw_delete %kw_from)
});
} %}

delete_truncate -> (kw_truncate %kw_table:?) array_of[table_ref] {% x => track(x, {
delete_truncate -> (kw_truncate %kw_table:?) array_of[table_ref] (kw_restart kw_identity):? {% x => track(x, {
type: 'truncate table',
tables: x[1],
}) %}
Copy link
Owner

@oguimbal oguimbal Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, that parses, but the fact that restart identity is present should influence the generated AST.

In another hand, when it is NOT present, the generated AST should be the same as previously.

Moreover, if you implement restart identity, you should also implement continue identity ... see the spec.

Meaning something like:

delete_truncate ->  (kw_truncate %kw_table:?) array_of[table_ref] ((kw_restart | kw_continue) kw_identity):? {% x => track(x, {
                            type: 'truncate table',
                            tables: x[1],
                            ...x[2] && { identity: toStr(x[2][0]) },
                        })

and modify the corresponding AST typing definition:

export interface TruncateStatement {
     type: 'truncate table',
    //  [.....]
    identity?: 'restart' | 'continue';
}

}) %}
6 changes: 5 additions & 1 deletion src/syntax/delete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ describe('Delete', () => {
type: 'truncate table',
tables: [{ name: 'test' }]
});
checkStatement([`truncate test restart identity`, `truncate table test restart identity`], {
type: 'truncate table',
tables: [{ name: 'test' }]
});

checkStatement([`truncate ta, "tb"`, `truncate table "ta","tb"`], {
type: 'truncate table',
Expand All @@ -37,4 +41,4 @@ describe('Delete', () => {
expr: { type: 'ref', name: '*' }
}]
});
});
});