Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
feat: keep string literal quote in table default
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaiba committed Nov 21, 2023
1 parent a9e67ca commit 0d9e665
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kfparser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ func TestParse_valid_syntax(t *testing.T) {
genOneTableOneCol(schema.ColText),
},
{"table with text column with all attrs",
`database td1; table tt1 { tc1 text minlen(3) maxlen(30) default(3) notnull primary unique }`,
`database td1; table tt1 { tc1 text minlen(3) maxlen(30) default('3') notnull primary unique }`,
genOneTableOneColWithAttrs(schema.ColText,
schema.Attribute{Type: schema.AttrMinLength, Value: "3"},
schema.Attribute{Type: schema.AttrMaxLength, Value: "30"},
schema.Attribute{Type: schema.AttrDefault, Value: "3"},
schema.Attribute{Type: schema.AttrDefault, Value: "'3'"},
schema.Attribute{Type: schema.AttrNotNull},
schema.Attribute{Type: schema.AttrPrimaryKey},
schema.Attribute{Type: schema.AttrUnique}),
Expand Down
3 changes: 1 addition & 2 deletions kfparser/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ func (c *KFVisitor) VisitColumn_constraint(ctx *kfgrammar.Column_constraintConte
attr.Type = schema.AttrUnique
case ctx.DEFAULT_() != nil:
attr.Type = schema.AttrDefault
// remove the single quote
attr.Value = strings.Trim(ctx.Literal_value().GetText(), "'")
attr.Value = ctx.Literal_value().GetText()
case ctx.MIN_() != nil:
attr.Type = schema.AttrMin
attr.Value = ctx.Number_value().GetText()
Expand Down

0 comments on commit 0d9e665

Please sign in to comment.