fix: 使用最新版 vitess sqlparser 解析 SQL 语句

解决 xwb1989/sqlparser 不支持 current_timestamp() 的问题
This commit is contained in:
kanzihuang
2023-09-26 22:47:19 +08:00
parent 7544288451
commit b4ddbbd38f
7 changed files with 239 additions and 149 deletions

View File

@@ -3,7 +3,6 @@ package api
import (
"github.com/stretchr/testify/require"
"mayfly-go/internal/db/domain/entity"
"strings"
"testing"
)
@@ -54,37 +53,3 @@ func Test_escapeSql(t *testing.T) {
})
}
}
func Test_SplitSqls(t *testing.T) {
tests := []struct {
name string
input string
want string
}{
{
name: "create table with current_timestamp",
input: "create table tbl (\n\tcreate_at datetime default current_timestamp()\n)",
},
{
name: "create table with current_date",
input: "create table tbl (\n\tcreate_at date default current_date()\n)",
},
{
name: "select with ';\n'",
input: "select 'the first line;\nthe second line;\n'",
// SplitSqls split statements by ';\n'
want: "select 'the first line;\n",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
scanner := SplitSqls(strings.NewReader(test.input))
require.True(t, scanner.Scan())
got := scanner.Text()
if len(test.want) == 0 {
test.want = test.input
}
require.Equal(t, test.want, got)
})
}
}