github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/parsers/sqlparse.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package parsers 16 17 import ( 18 "context" 19 "github.com/matrixorigin/matrixone/pkg/common/moerr" 20 "github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect" 21 "github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect/mysql" 22 "github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect/postgresql" 23 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 24 ) 25 26 func Parse(ctx context.Context, dialectType dialect.DialectType, sql string) ([]tree.Statement, error) { 27 switch dialectType { 28 case dialect.MYSQL: 29 return mysql.Parse(ctx, sql) 30 case dialect.POSTGRESQL: 31 return postgresql.Parse(ctx, sql) 32 default: 33 return nil, moerr.NewInternalError(ctx, "type of dialect error") 34 } 35 } 36 37 func ParseOne(ctx context.Context, dialectType dialect.DialectType, sql string) (tree.Statement, error) { 38 switch dialectType { 39 case dialect.MYSQL: 40 return mysql.ParseOne(ctx, sql) 41 case dialect.POSTGRESQL: 42 return postgresql.ParseOne(ctx, sql) 43 default: 44 return nil, moerr.NewInternalError(ctx, "type of dialect error") 45 } 46 }