From eeb43dfbbe93642f05fad996eb3a3658f6261d00 Mon Sep 17 00:00:00 2001 From: nicksherron Date: Wed, 19 Feb 2020 12:32:10 -0500 Subject: [PATCH] internal/db: #9 add case insensitive search --- internal/db.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/db.go b/internal/db.go index 78eee46..b189fbc 100644 --- a/internal/db.go +++ b/internal/db.go @@ -66,7 +66,7 @@ func dbInit(dbPath string) { } // sqlite regex function regex := func(re, s string) (bool, error) { - b, e := regexp.MatchString(re, s) + b, e := regexp.MatchString(fmt.Sprintf(`(?i)%v`, re), s) return b, e } @@ -247,10 +247,10 @@ func (cmd Command) commandGet() ([]Query, error) { SELECT * FROM ( SELECT DISTINCT ON ("command") command, "uuid", "created" FROM commands - WHERE "user_id" = '%v' - AND "path" = '%v' - AND "system_name" = '%v' - AND "command" ~ '%v' + WHERE "user_id" = '%v' + AND "path" = '%v' + AND "system_name" = '%v' + AND "command" ~* '%v' ) c ORDER BY "created" DESC limit '%v';`, cmd.User.ID, cmd.Path, cmd.SystemName, cmd.Query, cmd.Limit) @@ -261,7 +261,7 @@ func (cmd Command) commandGet() ([]Query, error) { FROM commands WHERE "user_id" = '%v' AND "path" = '%v' - AND "command" ~ '%v' + AND "command" ~* '%v' ) c ORDER BY "created" DESC limit '%v';`, cmd.User.ID, cmd.Path, cmd.Query, cmd.Limit) @@ -271,7 +271,7 @@ func (cmd Command) commandGet() ([]Query, error) { FROM commands WHERE "user_id" = '%v' AND "system_name" = '%v' - AND "command" ~ '%v' + AND "command" ~* '%v' ORDER BY "created" DESC limit '%v';`, cmd.User.ID, cmd.SystemName, cmd.Query, cmd.Limit) } else if cmd.Path != "" && cmd.Query != "" { @@ -280,7 +280,7 @@ func (cmd Command) commandGet() ([]Query, error) { FROM commands WHERE "user_id" = '%v' AND "path" = '%v' - AND "command" ~ '%v' + AND "command" ~* '%v' ORDER BY "created" DESC limit '%v';`, cmd.User.ID, cmd.Path, cmd.Query, cmd.Limit) } else if cmd.SystemName != "" && cmd.Unique { @@ -309,7 +309,7 @@ func (cmd Command) commandGet() ([]Query, error) { SELECT DISTINCT ON ("command") command, "uuid", "created" FROM commands WHERE "user_id" = '%v' - AND "command" ~ '%v' + AND "command" ~* '%v' ) c ORDER BY "created" DESC limit '%v';`, cmd.User.ID, cmd.Query, cmd.Limit) @@ -318,7 +318,7 @@ func (cmd Command) commandGet() ([]Query, error) { SELECT "command", "uuid", "created" FROM commands WHERE "user_id" = '%v' - AND "command" ~ '%v' + AND "command" ~* '%v' ORDER BY "created" DESC limit '%v';`, cmd.User.ID, cmd.Query, cmd.Limit) } else {