From 1e8a183d6c1af0775f63b784ed0a33fa2e70b651 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Tue, 28 May 2024 20:59:42 +0200 Subject: [PATCH] Implement limit --- crates/lavina-core/src/repo/room.rs | 33 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/crates/lavina-core/src/repo/room.rs b/crates/lavina-core/src/repo/room.rs index b60cb56..08ccc42 100644 --- a/crates/lavina-core/src/repo/room.rs +++ b/crates/lavina-core/src/repo/room.rs @@ -35,22 +35,27 @@ impl Storage { let res = sqlx::query_as( " select - messages.id as id, - content, - created_at, - users.name as author_name - from - messages - join - users - on messages.author_id = users.id - where - room_id = ? + * + from ( + select + messages.id as id, + content, + created_at, + users.name as author_name + from + messages + join + users + on messages.author_id = users.id + where + room_id = ? + order by + messages.id desc + limit ? + ) order by - messages.id - limit ?; + id asc; ", - // todo: implement limit ) .bind(room_id) .bind(limit)