Skip to content

Commit

Permalink
internal/db: #9 add case insensitive search
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksherron committed Feb 19, 2020
1 parent 66a5dc5 commit eeb43df
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions internal/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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 != "" {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)

Expand All @@ -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 {
Expand Down

0 comments on commit eeb43df

Please sign in to comment.