github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/simulator/sqlgen/sqlgen.go (about) 1 // Copyright 2022 PingCAP, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 // Package sqlgen is the logic for generating different kinds of SQL statements. 15 package sqlgen 16 17 import ( 18 "github.com/pingcap/tiflow/dm/simulator/config" 19 "github.com/pingcap/tiflow/dm/simulator/mcp" 20 ) 21 22 // SQLGenerator contains all the operations for generating SQLs. 23 type SQLGenerator interface { 24 // GenTruncateTable generates a TRUNCATE TABLE SQL. 25 GenTruncateTable() (string, error) 26 // GenLoadUniqueKeySQL generates a SELECT SQL fetching all the uniques of a table. 27 // The column definitions of the returned data is also provided, 28 // so that the values can be stored to different variables. 29 GenLoadUniqueKeySQL() (string, []*config.ColumnDefinition, error) 30 // GenInsertRow generates an INSERT SQL. 31 // The new row's unique key is also provided, 32 // so that it can be further added into an MCP. 33 GenInsertRow() (string, *mcp.UniqueKey, error) 34 // GenUpdateRow generates an UPDATE SQL for the given unique key. 35 GenUpdateRow(*mcp.UniqueKey) (string, error) 36 // GenDeleteRow generates a DELETE SQL for the given unique key. 37 GenDeleteRow(*mcp.UniqueKey) (string, error) 38 // GenCreateTable generates a CreateTable SQL by table config. 39 GenCreateTable() string 40 }