Fix sql errors
This commit is contained in:
parent
72b531d216
commit
bdf651b40c
1 changed files with 13 additions and 10 deletions
|
|
@ -41,7 +41,7 @@ impl FromSql for Time {
|
||||||
pub struct EuphMsg {
|
pub struct EuphMsg {
|
||||||
id: Snowflake,
|
id: Snowflake,
|
||||||
parent: Option<Snowflake>,
|
parent: Option<Snowflake>,
|
||||||
time: DateTime<Utc>,
|
time: Time,
|
||||||
nick: String,
|
nick: String,
|
||||||
content: String,
|
content: String,
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ impl Msg for EuphMsg {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn time(&self) -> DateTime<Utc> {
|
fn time(&self) -> DateTime<Utc> {
|
||||||
self.time
|
self.time.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nick(&self) -> String {
|
fn nick(&self) -> String {
|
||||||
|
|
@ -347,7 +347,7 @@ impl EuphRequest {
|
||||||
let last_msg_id = msgs.first().unwrap().id;
|
let last_msg_id = msgs.first().unwrap().id;
|
||||||
|
|
||||||
let mut stmt = tx.prepare("
|
let mut stmt = tx.prepare("
|
||||||
INSERT INTO euph_msgs (
|
INSERT OR REPLACE INTO euph_msgs (
|
||||||
room, id, parent, previous_edit_id, time, content, encryption_key_id, edited, deleted, truncated,
|
room, id, parent, previous_edit_id, time, content, encryption_key_id, edited, deleted, truncated,
|
||||||
user_id, name, server_id, server_era, session_id, is_staff, is_manager, client_address, real_client_address
|
user_id, name, server_id, server_era, session_id, is_staff, is_manager, client_address, real_client_address
|
||||||
)
|
)
|
||||||
|
|
@ -397,12 +397,14 @@ impl EuphRequest {
|
||||||
let path = conn
|
let path = conn
|
||||||
.prepare(
|
.prepare(
|
||||||
"
|
"
|
||||||
WITH RECURSIVE path (room, id) = (
|
WITH RECURSIVE
|
||||||
|
path (room, id) AS (
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
UNION
|
UNION
|
||||||
SELECT (room, parent)
|
SELECT room, parent
|
||||||
FROM euph_msgs
|
FROM euph_msgs
|
||||||
JOIN path USING (room, id)
|
JOIN path USING (room, id)
|
||||||
|
WHERE parent IS NOT NULL
|
||||||
)
|
)
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM path
|
FROM path
|
||||||
|
|
@ -425,24 +427,25 @@ impl EuphRequest {
|
||||||
let msgs = conn
|
let msgs = conn
|
||||||
.prepare(
|
.prepare(
|
||||||
"
|
"
|
||||||
WITH RECURSIVE tree (room, id) = (
|
WITH RECURSIVE
|
||||||
|
tree (room, id) AS (
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
UNION
|
UNION
|
||||||
SELECT (euph_msgs.room, euph_msgs.id)
|
SELECT euph_msgs.room, euph_msgs.id
|
||||||
FROM euph_msgs
|
FROM euph_msgs
|
||||||
JOIN tree
|
JOIN tree
|
||||||
ON tree.room = euph_msgs.room
|
ON tree.room = euph_msgs.room
|
||||||
AND tree.id = euph_msgs.parent
|
AND tree.id = euph_msgs.parent
|
||||||
)
|
)
|
||||||
SELECT (id, parent, time, name, content)
|
SELECT id, parent, time, name, content
|
||||||
FROM euph_msg
|
FROM euph_msgs
|
||||||
JOIN tree USING (room, id)
|
JOIN tree USING (room, id)
|
||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
",
|
",
|
||||||
)?
|
)?
|
||||||
.query_map(params![room, root], |row| {
|
.query_map(params![room, root], |row| {
|
||||||
Ok(EuphMsg {
|
Ok(EuphMsg {
|
||||||
id: Snowflake(row.get(0)?),
|
id: row.get(0)?,
|
||||||
parent: row.get(1)?,
|
parent: row.get(1)?,
|
||||||
time: row.get(2)?,
|
time: row.get(2)?,
|
||||||
nick: row.get(3)?,
|
nick: row.get(3)?,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue