mirror of
https://github.com/nicksherron/bashhub-server.git
synced 2024-11-10 09:02:54 +08:00
internal/db: commandGet() support both sqlite and postgres
This commit is contained in:
parent
8ea0bea9be
commit
8c8f87960e
1 changed files with 5 additions and 5 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue