Skip to content

Commit

Permalink
separate index matches
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
  • Loading branch information
timvaillancourt committed Oct 29, 2024
1 parent 836e60d commit d7e7280
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions go/vt/external/golib/sqlutils/sqlite_dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ var sqlite3GeneralConversions = []regexpMap{
rmap(`(?i)\bconcat[(][\s]*([^,)]+)[\s]*,[\s]*([^,)]+)[\s]*,[\s]*([^,)]+)[\s]*[)]`, `($1 || $2 || $3)`),

rmap(`(?i) rlike `, ` like `),
}

var sqlite3CreateIndexConversions = []regexpMap{
rmap(`(?i)create index([\s\S]+)[(][\s]*[0-9]+[\s]*[)]([\s\S]+)`, `create index ${1}${2}`),
}

var sqlite3DropIndexConversions = []regexpMap{
rmap(`(?i)drop index ([\S]+) on ([\S]+)`, `drop index if exists $1`),
}

Expand Down Expand Up @@ -115,6 +120,14 @@ func ToSqlite3CreateTable(statement string) string {
return applyConversions(statement, sqlite3CreateTableConversions)
}

func ToSqlite3CreateIndex(statement string) string {
return applyConversions(statement, sqlite3CreateIndexConversions)
}

func ToSqlite3DropIndex(statement string) string {
return applyConversions(statement, sqlite3DropIndexConversions)
}

func ToSqlite3Insert(statement string) string {
statement = applyConversions(statement, sqlite3GeneralConversions)
return applyConversions(statement, sqlite3InsertConversions)
Expand All @@ -130,6 +143,12 @@ func ToSqlite3Dialect(statement string) (translated string) {
if IsInsert(statement) {
return ToSqlite3Insert(statement)
}
if IsCreateIndex(statement) {
return ToSqlite3CreateIndex(statement)
}
if IsDropIndex(statement) {
return ToSqlite3DropIndex(statement)
}
if IsCreateTable(statement) {
return ToSqlite3CreateTable(statement)
}
Expand Down

0 comments on commit d7e7280

Please sign in to comment.