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

This commit is contained in:
nicksherron 2020-02-07 12:55:02 -05:00
parent 8ea0bea9be
commit 8c8f87960e

View file

@ -127,17 +127,17 @@ func (cmd Command) commandGet() []Query {
// postgres // postgres
rows, err = DB.Query(`SELECT DISTINCT on ("command") command, "uuid", "created" from commands rows, err = DB.Query(`SELECT DISTINCT on ("command") command, "uuid", "created" from commands
where "user_id" in (select "id" from users where "token" = $1) where "user_id" in (select "id" from users where "token" = $1)
order by "command", "created" desc limit $2`, cmd.Token, cmd.Limit) order by "command", "created" limit $2`, cmd.Token, cmd.Limit)
}else { } else {
// sqlite // sqlite
rows, err = DB.Query(`SELECT "command", "uuid", "created" from commands rows, err = DB.Query(`SELECT "command", "uuid", "created" from commands
where "user_id" in (select "id" from users where "token" = $1) where "user_id" in (select "id" from users where "token" = $1)
group by "command" order by "created" desc limit $2`, cmd.Token, cmd.Limit) group by "command" order by "created" limit $2`, cmd.Token, cmd.Limit)
} }
} else { } else {
rows, err = DB.Query(`SELECT "command", "uuid", "created" from commands rows, err = DB.Query(`SELECT "command", "uuid", "created" from commands
where "user_id" in (select "id" from users where "token" = $1) where "user_id" in (select "id" from users where "token" = $1)
order by "created" desc limit $2`, cmd.Token, cmd.Limit) order by "created" limit $2`, cmd.Token, cmd.Limit)
} }
if err != nil { if err != nil {
@ -187,4 +187,4 @@ func (sys System) systemGet() (SystemQuery, error) {
//SELECT DISTINCT on ("command"), "uuid", "created" from commands //SELECT DISTINCT on ("command"), "uuid", "created" from commands
//where "user_id" in (select "id" from users where "token" = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJZCI6Im5pY') //where "user_id" in (select "id" from users where "token" = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJZCI6Im5pY')
//desc limit 1; //desc limit 1;