internal/db: commandGet() support both sqlite and postgres

This commit is contained in:
nicksherron 2020-02-07 12:51:11 -05:00
parent 910144816a
commit 8ea0bea9be

View file

@ -126,16 +126,18 @@ func (cmd Command) commandGet() []Query {
if connectionLimit != 1 {
// postgres
rows, err = DB.Query(`SELECT DISTINCT on ("command") command, "uuid", "created" from commands
where "user_id" in (select "id" from users where "token" = $1) limit $2`, cmd.Token, cmd.Limit)
where "user_id" in (select "id" from users where "token" = $1)
order by "command", "created" desc limit $2`, cmd.Token, cmd.Limit)
}else {
// sqlite
rows, err = DB.Query(`SELECT "command", "uuid", "created" from commands
where "user_id" in (select "id" from users where "token" = $1)
group by "command" limit $2`, cmd.Token, cmd.Limit)
group by "command" order by "created" desc limit $2`, cmd.Token, cmd.Limit)
}
} else {
rows, err = DB.Query(`SELECT "command", "uuid", "created" from commands
where "user_id" in (select "id" from users where "token" = $1) limit $2`, cmd.Token, cmd.Limit)
where "user_id" in (select "id" from users where "token" = $1)
order by "created" desc limit $2`, cmd.Token, cmd.Limit)
}
if err != nil {