grammar: add unique column constraint

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-07 22:07:50 +03:00
parent cc6fa3e0f7
commit 98c15a25dc
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 1878 additions and 1443 deletions

View file

@ -55,7 +55,13 @@ module.exports = grammar({
choice( choice(
$._not_null, $._not_null,
$.keyword_null, $.keyword_null,
seq($.keyword_default, $._expression) seq($.keyword_default, $._expression),
seq(
$.keyword_unique,
optional(
seq($.keyword_nulls, optional($.keyword_not), $.keyword_distinct)
)
)
// TODO: CHECK // TODO: CHECK
// TODO: GENERATED // TODO: GENERATED
// TODO: UNIQUE // TODO: UNIQUE
@ -102,6 +108,9 @@ module.exports = grammar({
keyword_default: (_) => mkKeyword("default"), keyword_default: (_) => mkKeyword("default"),
keyword_true: (_) => mkKeyword("true"), keyword_true: (_) => mkKeyword("true"),
keyword_false: (_) => mkKeyword("false"), keyword_false: (_) => mkKeyword("false"),
keyword_nulls: (_) => mkKeyword("nulls"),
keyword_distinct: (_) => mkKeyword("distinct"),
keyword_unique: (_) => mkKeyword("unique"),
// References: https://www.postgresql.org/docs/15/datatype.html // References: https://www.postgresql.org/docs/15/datatype.html
_type: ($) => _type: ($) =>

View file

@ -242,6 +242,48 @@
"name": "_expression" "name": "_expression"
} }
] ]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_unique"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_nulls"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "keyword_not"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "keyword_distinct"
}
]
},
{
"type": "BLANK"
}
]
}
]
} }
] ]
} }
@ -406,6 +448,18 @@
"type": "PATTERN", "type": "PATTERN",
"value": "false|FALSE" "value": "false|FALSE"
}, },
"keyword_nulls": {
"type": "PATTERN",
"value": "nulls|NULLS"
},
"keyword_distinct": {
"type": "PATTERN",
"value": "distinct|DISTINCT"
},
"keyword_unique": {
"type": "PATTERN",
"value": "unique|UNIQUE"
},
"_type": { "_type": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [

View file

@ -57,6 +57,10 @@
"type": "keyword_default", "type": "keyword_default",
"named": true "named": true
}, },
{
"type": "keyword_distinct",
"named": true
},
{ {
"type": "keyword_not", "type": "keyword_not",
"named": true "named": true
@ -65,6 +69,14 @@
"type": "keyword_null", "type": "keyword_null",
"named": true "named": true
}, },
{
"type": "keyword_nulls",
"named": true
},
{
"type": "keyword_unique",
"named": true
},
{ {
"type": "literal", "type": "literal",
"named": true "named": true
@ -560,6 +572,10 @@
"type": "keyword_default", "type": "keyword_default",
"named": true "named": true
}, },
{
"type": "keyword_distinct",
"named": true
},
{ {
"type": "keyword_exists", "type": "keyword_exists",
"named": true "named": true
@ -596,6 +612,10 @@
"type": "keyword_null", "type": "keyword_null",
"named": true "named": true
}, },
{
"type": "keyword_nulls",
"named": true
},
{ {
"type": "keyword_numeric", "type": "keyword_numeric",
"named": true "named": true
@ -628,6 +648,10 @@
"type": "keyword_true", "type": "keyword_true",
"named": true "named": true
}, },
{
"type": "keyword_unique",
"named": true
},
{ {
"type": "keyword_unlogged", "type": "keyword_unlogged",
"named": true "named": true

File diff suppressed because it is too large Load diff

View file

@ -174,7 +174,7 @@ Create a table with column constraints
create table foo ( create table foo (
c1 text not null, c1 text not null,
c2 text null, c2 text null,
c2 text not null default 'hello' c3 text not null default 'hello'
); );
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -225,7 +225,8 @@ Create a table with named column constraints
create table foo ( create table foo (
c1 text constraint strong_c1 not null, c1 text constraint strong_c1 not null,
c2 text constraint weak_c2 null, c2 text constraint weak_c2 null,
c3 text constraint "c3 with power" not null constraint "c2 set default hello" default 'hello' c3 text constraint "c3 with power" not null constraint "c2 set default hello" default 'hello',
c4 text constraint "c4 unique" unique nulls not distinct
); );
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -273,6 +274,18 @@ create table foo (
(literal) (literal)
) )
) )
(column_definition
name: (identifier)
datatype: (keyword_text)
(column_constraint
(keyword_constraint)
name: (identifier)
(keyword_unique)
(keyword_nulls)
(keyword_not)
(keyword_distinct)
)
)
) )
) )
) )

Binary file not shown.