@@ -15,6 +15,8 @@ pub struct Stream {
15
15
key : String ,
16
16
created : DateTime < Utc > ,
17
17
updated : DateTime < Utc > ,
18
+ last_insert : DateTime < Utc > ,
19
+ last_payload : Value ,
18
20
}
19
21
20
22
#[ derive( Debug , Deserialize , Serialize ) ]
@@ -47,7 +49,19 @@ pub fn create_table(conn: Connection) -> Result<(), Error> {
47
49
}
48
50
49
51
pub fn list_streams ( conn : Connection ) -> Result < Vec < Stream > , Error > {
50
- let mut stmt = conn. prepare ( "SELECT id, key, created, updated FROM streams" ) ?;
52
+ let mut stmt = conn. prepare (
53
+ "SELECT
54
+ streams.id,
55
+ streams.key,
56
+ streams.created,
57
+ streams.updated,
58
+ max(data.updated) as last_insert,
59
+ max(data.payload) as last_payload
60
+ FROM streams
61
+ INNER JOIN data on data.stream_id = streams.id
62
+ GROUP BY streams.id
63
+ ORDER BY data.created DESC, data.id DESC" ,
64
+ ) ?;
51
65
52
66
let results = stmt
53
67
. query_map ( NO_PARAMS , |row| {
@@ -56,6 +70,8 @@ pub fn list_streams(conn: Connection) -> Result<Vec<Stream>, Error> {
56
70
key : row. get ( 1 ) ?,
57
71
created : row. get ( 2 ) ?,
58
72
updated : row. get ( 3 ) ?,
73
+ last_insert : row. get ( 4 ) ?,
74
+ last_payload : row. get ( 5 ) ?,
59
75
} )
60
76
} )
61
77
. and_then ( |mapped_rows| Ok ( mapped_rows. map ( |row| row. unwrap ( ) ) . collect :: < Vec < Stream > > ( ) ) ) ?;
@@ -70,7 +86,7 @@ pub fn list_data(conn: Connection, key: String) -> Result<Vec<Data>, Error> {
70
86
FROM data
71
87
INNER JOIN streams ON streams.id = data.stream_id
72
88
WHERE streams.key = ?
73
- ORDER BY data.updated DESC, data.id DESC" ,
89
+ ORDER BY data.created DESC, data.id DESC" ,
74
90
) ?;
75
91
76
92
let results = stmt
0 commit comments