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

feat: keep string literal quote in table default #43

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 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