grouping mail archive by year-month
This commit is contained in:
@@ -143,11 +143,14 @@ public class Database {
|
||||
* finalize sql, save sql and arguments as compiled request
|
||||
* @return
|
||||
*/
|
||||
public CompiledRequest compile(){
|
||||
public CompiledRequest compile(Object ...additionalArgs){
|
||||
var args = new ArrayList<>();
|
||||
applyValues(args);
|
||||
applyConditions(args);
|
||||
applySorting();
|
||||
if (additionalArgs != null) {
|
||||
for (Object arg : additionalArgs) args.add(arg);
|
||||
}
|
||||
return new CompiledRequest(sql.toString(),args);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,11 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.Array;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.srsoftware.widerhall.Constants.*;
|
||||
@@ -98,8 +97,14 @@ public class Post {
|
||||
return new File(filename);
|
||||
}
|
||||
|
||||
public static ArrayList<Post> find(MailingList list) throws SQLException {
|
||||
var rs = Database.open().select(TABLE_NAME).where(LIST,list.email()).sort(DATE).compile().exec();
|
||||
public static ArrayList<Post> find(MailingList list, String month) throws SQLException {
|
||||
var rs = Database.open()
|
||||
.select(TABLE_NAME,"*","strftime('%Y-%m',date/1000,'unixepoch') as month")
|
||||
.where(LIST,list.email())
|
||||
.where(MONTH,month)
|
||||
.sort(DATE)
|
||||
.compile()
|
||||
.exec();
|
||||
try {
|
||||
var result = new ArrayList<Post>();
|
||||
while (rs.next()) result.add(Post.from(rs));
|
||||
@@ -160,7 +165,7 @@ public class Post {
|
||||
LIST,list.name(),
|
||||
FROM_NAME,fromName,
|
||||
SUBJECT,Util.dropEmail(subject),
|
||||
DATE,timestamp);
|
||||
DATE, new Timestamp(timestamp).toString());
|
||||
}
|
||||
|
||||
private Post save() throws SQLException {
|
||||
@@ -168,6 +173,15 @@ public class Post {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> summarize(MailingList list) throws SQLException {
|
||||
var sql = new StringBuilder("SELECT count(*) as count,strftime('%Y-%m',date/1000,'unixepoch') as month FROM Posts WHERE list = ? GROUP BY month ORDER BY month;");
|
||||
var map = new HashMap<String,Object>();
|
||||
var rs = Database.open().query(sql).compile(list.email()).exec();
|
||||
while (rs.next()) map.put(rs.getString("month"),rs.getInt("count"));
|
||||
rs.close();
|
||||
return map;
|
||||
}
|
||||
|
||||
public long timestamp(){
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user