fix: postgres feature
This commit is contained in:
parent
a11a70d3e7
commit
dcd5f359c6
13 changed files with 79 additions and 105 deletions
|
@ -13,7 +13,7 @@
|
||||||
Everything Tetratto needs will be built into the main binary. You can build Tetratto with the following command:
|
Everything Tetratto needs will be built into the main binary. You can build Tetratto with the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo build -r --no-default-features features=redis,sqlite
|
cargo build -r --no-default-features --features=redis,sqlite
|
||||||
```
|
```
|
||||||
|
|
||||||
You can replace `sqlite` in the above command with `postgres`, if you'd like. It's also acceptable to remove the `redis` part if you don't want to use a cache. <sup>I wouldn't recomment removing cache, though</sup>
|
You can replace `sqlite` in the above command with `postgres`, if you'd like. It's also acceptable to remove the `redis` part if you don't want to use a cache. <sup>I wouldn't recomment removing cache, though</sup>
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::cache::Cache;
|
use crate::cache::Cache;
|
||||||
use crate::model::{
|
use crate::model::{Error, Result, auth::User, moderation::AuditLogEntry, permissions::FinePermission};
|
||||||
Error, Result, auth::User, moderation::AuditLogEntry, permissions::FinePermission,
|
|
||||||
};
|
|
||||||
use crate::{auto_method, execute, get, query_row, query_rows};
|
use crate::{auto_method, execute, get, query_row, query_rows};
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
#[cfg(feature = "sqlite")]
|
||||||
|
@ -18,9 +16,9 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> AuditLogEntry {
|
) -> AuditLogEntry {
|
||||||
AuditLogEntry {
|
AuditLogEntry {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
moderator: get!(x->2(isize)) as usize,
|
moderator: get!(x->2(i64)) as usize,
|
||||||
content: get!(x->3(String)),
|
content: get!(x->3(String)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +43,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM audit_log ORDER BY created DESC LIMIT $1 OFFSET $2",
|
"SELECT * FROM audit_log ORDER BY created DESC LIMIT $1 OFFSET $2",
|
||||||
&[&(batch as isize), &((page * batch) as isize)],
|
&[&(batch as i64), &((page * batch) as i64)],
|
||||||
|x| { Self::get_audit_log_entry_from_row(x) }
|
|x| { Self::get_audit_log_entry_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> User {
|
) -> User {
|
||||||
User {
|
User {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
username: get!(x->2(String)),
|
username: get!(x->2(String)),
|
||||||
password: get!(x->3(String)),
|
password: get!(x->3(String)),
|
||||||
salt: get!(x->4(String)),
|
salt: get!(x->4(String)),
|
||||||
|
@ -34,10 +34,10 @@ impl DataManager {
|
||||||
tokens: serde_json::from_str(&get!(x->6(String)).to_string()).unwrap(),
|
tokens: serde_json::from_str(&get!(x->6(String)).to_string()).unwrap(),
|
||||||
permissions: FinePermission::from_bits(get!(x->7(u32))).unwrap(),
|
permissions: FinePermission::from_bits(get!(x->7(u32))).unwrap(),
|
||||||
is_verified: if get!(x->8(i8)) == 1 { true } else { false },
|
is_verified: if get!(x->8(i8)) == 1 { true } else { false },
|
||||||
notification_count: get!(x->9(isize)) as usize,
|
notification_count: get!(x->9(i64)) as usize,
|
||||||
follower_count: get!(x->10(isize)) as usize,
|
follower_count: get!(x->10(i64)) as usize,
|
||||||
following_count: get!(x->11(isize)) as usize,
|
following_count: get!(x->11(i64)) as usize,
|
||||||
last_seen: get!(x->12(isize)) as usize,
|
last_seen: get!(x->12(i64)) as usize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ impl DataManager {
|
||||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = execute!(&conn, "DELETE FROM users WHERE id = $1", &[&(id as isize)]);
|
let res = execute!(&conn, "DELETE FROM users WHERE id = $1", &[&(id as i64)]);
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
return Err(Error::DatabaseError(e.to_string()));
|
return Err(Error::DatabaseError(e.to_string()));
|
||||||
|
@ -160,7 +160,7 @@ impl DataManager {
|
||||||
let res = execute!(
|
let res = execute!(
|
||||||
&conn,
|
&conn,
|
||||||
"DELETE FROM communities WHERE owner = $1",
|
"DELETE FROM communities WHERE owner = $1",
|
||||||
&[&(id as isize)]
|
&[&(id as i64)]
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
@ -172,7 +172,7 @@ impl DataManager {
|
||||||
let res = execute!(
|
let res = execute!(
|
||||||
&conn,
|
&conn,
|
||||||
"DELETE FROM memberships WHERE owner = $1",
|
"DELETE FROM memberships WHERE owner = $1",
|
||||||
&[&(id as isize)]
|
&[&(id as i64)]
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
@ -183,7 +183,7 @@ impl DataManager {
|
||||||
let res = execute!(
|
let res = execute!(
|
||||||
&conn,
|
&conn,
|
||||||
"DELETE FROM notifications WHERE owner = $1",
|
"DELETE FROM notifications WHERE owner = $1",
|
||||||
&[&(id as isize)]
|
&[&(id as i64)]
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
@ -195,7 +195,7 @@ impl DataManager {
|
||||||
let res = execute!(
|
let res = execute!(
|
||||||
&conn,
|
&conn,
|
||||||
"DELETE FROM reactions WHERE owner = $1",
|
"DELETE FROM reactions WHERE owner = $1",
|
||||||
&[&(id as isize)]
|
&[&(id as i64)]
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
@ -203,11 +203,7 @@ impl DataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete posts
|
// delete posts
|
||||||
let res = execute!(
|
let res = execute!(&conn, "DELETE FROM posts WHERE owner = $1", &[&(id as i64)]);
|
||||||
&conn,
|
|
||||||
"DELETE FROM posts WHERE owner = $1",
|
|
||||||
&[&(id as isize)]
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
return Err(Error::DatabaseError(e.to_string()));
|
return Err(Error::DatabaseError(e.to_string()));
|
||||||
|
|
|
@ -38,7 +38,7 @@ macro_rules! auto_method {
|
||||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = query_row!(&conn, $query, &[&(id as isize)], |x| {
|
let res = query_row!(&conn, $query, &[&(id as i64)], |x| {
|
||||||
Ok(Self::$select_fn(x))
|
Ok(Self::$select_fn(x))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ macro_rules! auto_method {
|
||||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = query_row!(&conn, $query, &[&(id as isize)], |x| {
|
let res = query_row!(&conn, $query, &[&(id as i64)], |x| {
|
||||||
Ok(Self::$select_fn(x))
|
Ok(Self::$select_fn(x))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -26,19 +26,19 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> Community {
|
) -> Community {
|
||||||
Community {
|
Community {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
title: get!(x->2(String)),
|
title: get!(x->2(String)),
|
||||||
context: serde_json::from_str(&get!(x->3(String))).unwrap(),
|
context: serde_json::from_str(&get!(x->3(String))).unwrap(),
|
||||||
owner: get!(x->4(isize)) as usize,
|
owner: get!(x->4(i64)) as usize,
|
||||||
read_access: serde_json::from_str(&get!(x->5(String))).unwrap(),
|
read_access: serde_json::from_str(&get!(x->5(String))).unwrap(),
|
||||||
write_access: serde_json::from_str(&get!(x->6(String))).unwrap(),
|
write_access: serde_json::from_str(&get!(x->6(String))).unwrap(),
|
||||||
join_access: serde_json::from_str(&get!(x->7(String))).unwrap(),
|
join_access: serde_json::from_str(&get!(x->7(String))).unwrap(),
|
||||||
// likes
|
// likes
|
||||||
likes: get!(x->8(isize)) as isize,
|
likes: get!(x->8(i64)) as isize,
|
||||||
dislikes: get!(x->9(isize)) as isize,
|
dislikes: get!(x->9(i64)) as isize,
|
||||||
// counts
|
// counts
|
||||||
member_count: get!(x->10(isize)) as usize,
|
member_count: get!(x->10(i64)) as usize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ impl DataManager {
|
||||||
let res = query_row!(
|
let res = query_row!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM communities WHERE id = $1",
|
"SELECT * FROM communities WHERE id = $1",
|
||||||
&[&(id as isize)],
|
&[&(id as i64)],
|
||||||
|x| { Ok(Self::get_community_from_row(x)) }
|
|x| { Ok(Self::get_community_from_row(x)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ impl DataManager {
|
||||||
let res = query_row!(
|
let res = query_row!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM communities WHERE title = $1",
|
"SELECT * FROM communities WHERE title = $1",
|
||||||
&[id],
|
&[&id],
|
||||||
|x| { Ok(Self::get_community_from_row(x)) }
|
|x| { Ok(Self::get_community_from_row(x)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ impl DataManager {
|
||||||
) -> IpBan {
|
) -> IpBan {
|
||||||
IpBan {
|
IpBan {
|
||||||
ip: get!(x->0(String)),
|
ip: get!(x->0(String)),
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
reason: get!(x->2(String)),
|
reason: get!(x->2(String)),
|
||||||
moderator: get!(x->3(isize)) as usize,
|
moderator: get!(x->3(i64)) as usize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM ipbans ORDER BY created DESC LIMIT $1 OFFSET $2",
|
"SELECT * FROM ipbans ORDER BY created DESC LIMIT $1 OFFSET $2",
|
||||||
&[&(batch as isize), &((page * batch) as isize)],
|
&[&(batch as i64), &((page * batch) as i64)],
|
||||||
|x| { Self::get_ipban_from_row(x) }
|
|x| { Self::get_ipban_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ impl DataManager {
|
||||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = execute!(&conn, "DELETE FROM ipbans WHERE ip = $1", &[ip]);
|
let res = execute!(&conn, "DELETE FROM ipbans WHERE ip = $1", &[&ip]);
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
return Err(Error::DatabaseError(e.to_string()));
|
return Err(Error::DatabaseError(e.to_string()));
|
||||||
|
|
|
@ -24,10 +24,10 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> CommunityMembership {
|
) -> CommunityMembership {
|
||||||
CommunityMembership {
|
CommunityMembership {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
owner: get!(x->2(isize)) as usize,
|
owner: get!(x->2(i64)) as usize,
|
||||||
community: get!(x->3(isize)) as usize,
|
community: get!(x->3(i64)) as usize,
|
||||||
role: CommunityPermission::from_bits(get!(x->4(u32))).unwrap(),
|
role: CommunityPermission::from_bits(get!(x->4(u32))).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ impl DataManager {
|
||||||
let res = query_row!(
|
let res = query_row!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM memberships WHERE owner = $1 AND community = $2",
|
"SELECT * FROM memberships WHERE owner = $1 AND community = $2",
|
||||||
&[&(owner as isize), &(community as isize)],
|
&[&(owner as i64), &(community as i64)],
|
||||||
|x| { Ok(Self::get_membership_from_row(x)) }
|
|x| { Ok(Self::get_membership_from_row(x)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ impl DataManager {
|
||||||
&conn,
|
&conn,
|
||||||
// 33 = banned, 65 = pending membership
|
// 33 = banned, 65 = pending membership
|
||||||
"SELECT * FROM memberships WHERE owner = $1 AND role IS NOT 33 AND role IS NOT 65 ORDER BY created DESC",
|
"SELECT * FROM memberships WHERE owner = $1 AND role IS NOT 33 AND role IS NOT 65 ORDER BY created DESC",
|
||||||
&[&(owner as isize)],
|
&[&(owner as i64)],
|
||||||
|x| { Self::get_membership_from_row(x) }
|
|x| { Self::get_membership_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,11 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> Notification {
|
) -> Notification {
|
||||||
Notification {
|
Notification {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
title: get!(x->2(String)),
|
title: get!(x->2(String)),
|
||||||
content: get!(x->3(String)),
|
content: get!(x->3(String)),
|
||||||
owner: get!(x->4(isize)) as usize,
|
owner: get!(x->4(i64)) as usize,
|
||||||
read: if get!(x->5(i8)) == 1 { true } else { false },
|
read: if get!(x->5(i8)) == 1 { true } else { false },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM notifications WHERE owner = $1 ORDER BY created DESC",
|
"SELECT * FROM notifications WHERE owner = $1 ORDER BY created DESC",
|
||||||
&[&(owner as isize)],
|
&[&(owner as i64)],
|
||||||
|x| { Self::get_notification_from_row(x) }
|
|x| { Self::get_notification_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,11 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> Post {
|
) -> Post {
|
||||||
Post {
|
Post {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
content: get!(x->2(String)),
|
content: get!(x->2(String)),
|
||||||
owner: get!(x->3(isize)) as usize,
|
owner: get!(x->3(i64)) as usize,
|
||||||
community: get!(x->4(isize)) as usize,
|
community: get!(x->4(i64)) as usize,
|
||||||
context: serde_json::from_str(&get!(x->5(String))).unwrap(),
|
context: serde_json::from_str(&get!(x->5(String))).unwrap(),
|
||||||
replying_to: if let Some(id) = get!(x->6(Option<i64>)) {
|
replying_to: if let Some(id) = get!(x->6(Option<i64>)) {
|
||||||
Some(id as usize)
|
Some(id as usize)
|
||||||
|
@ -38,10 +38,10 @@ impl DataManager {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
// likes
|
// likes
|
||||||
likes: get!(x->7(isize)) as isize,
|
likes: get!(x->7(i64)) as isize,
|
||||||
dislikes: get!(x->8(isize)) as isize,
|
dislikes: get!(x->8(i64)) as isize,
|
||||||
// other counts
|
// other counts
|
||||||
comment_count: get!(x->9(isize)) as usize,
|
comment_count: get!(x->9(i64)) as usize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,11 +67,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM posts WHERE replying_to = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
"SELECT * FROM posts WHERE replying_to = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||||
&[
|
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||||
&(id as isize),
|
|
||||||
&(batch as isize),
|
|
||||||
&((page * batch) as isize)
|
|
||||||
],
|
|
||||||
|x| { Self::get_post_from_row(x) }
|
|x| { Self::get_post_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -148,11 +144,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM posts WHERE owner = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
"SELECT * FROM posts WHERE owner = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||||
&[
|
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||||
&(id as isize),
|
|
||||||
&(batch as isize),
|
|
||||||
&((page * batch) as isize)
|
|
||||||
],
|
|
||||||
|x| { Self::get_post_from_row(x) }
|
|x| { Self::get_post_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -183,11 +175,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM posts WHERE community = $1 AND replying_to IS NULL ORDER BY created DESC LIMIT $2 OFFSET $3",
|
"SELECT * FROM posts WHERE community = $1 AND replying_to IS NULL ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||||
&[
|
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||||
&(id as isize),
|
|
||||||
&(batch as isize),
|
|
||||||
&((page * batch) as isize)
|
|
||||||
],
|
|
||||||
|x| { Self::get_post_from_row(x) }
|
|x| { Self::get_post_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -211,7 +199,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM posts WHERE community = $1 AND context LIKE '%\"is_pinned\":true%' ORDER BY created DESC",
|
"SELECT * FROM posts WHERE community = $1 AND context LIKE '%\"is_pinned\":true%' ORDER BY created DESC",
|
||||||
&[&(id as isize),],
|
&[&(id as i64),],
|
||||||
|x| { Self::get_post_from_row(x) }
|
|x| { Self::get_post_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -236,7 +224,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM posts ORDER BY likes DESC, created ASC LIMIT $2 OFFSET $3",
|
"SELECT * FROM posts ORDER BY likes DESC, created ASC LIMIT $2 OFFSET $3",
|
||||||
&[&(batch as isize), &((page * batch) as isize)],
|
&[&(batch as i64), &((page * batch) as i64)],
|
||||||
|x| { Self::get_post_from_row(x) }
|
|x| { Self::get_post_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -283,7 +271,7 @@ impl DataManager {
|
||||||
"SELECT * FROM posts WHERE community = {} {query_string} ORDER BY created DESC LIMIT $1 OFFSET $2",
|
"SELECT * FROM posts WHERE community = {} {query_string} ORDER BY created DESC LIMIT $1 OFFSET $2",
|
||||||
first.community
|
first.community
|
||||||
),
|
),
|
||||||
&[&(batch as isize), &((page * batch) as isize)],
|
&[&(batch as i64), &((page * batch) as i64)],
|
||||||
|x| { Self::get_post_from_row(x) }
|
|x| { Self::get_post_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> Reaction {
|
) -> Reaction {
|
||||||
Reaction {
|
Reaction {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
owner: get!(x->2(isize)) as usize,
|
owner: get!(x->2(i64)) as usize,
|
||||||
asset: get!(x->3(isize)) as usize,
|
asset: get!(x->3(i64)) as usize,
|
||||||
asset_type: serde_json::from_str(&get!(x->4(String))).unwrap(),
|
asset_type: serde_json::from_str(&get!(x->4(String))).unwrap(),
|
||||||
is_like: if get!(x->5(i8)) == 1 { true } else { false },
|
is_like: if get!(x->5(i8)) == 1 { true } else { false },
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ impl DataManager {
|
||||||
let res = query_row!(
|
let res = query_row!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM reactions WHERE owner = $1 AND asset = $2",
|
"SELECT * FROM reactions WHERE owner = $1 AND asset = $2",
|
||||||
&[&(owner as isize), &(asset as isize)],
|
&[&(owner as i64), &(asset as i64)],
|
||||||
|x| { Ok(Self::get_reaction_from_row(x)) }
|
|x| { Ok(Self::get_reaction_from_row(x)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,11 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> Report {
|
) -> Report {
|
||||||
Report {
|
Report {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
owner: get!(x->2(isize)) as usize,
|
owner: get!(x->2(i64)) as usize,
|
||||||
content: get!(x->3(String)),
|
content: get!(x->3(String)),
|
||||||
asset: get!(x->4(isize)) as usize,
|
asset: get!(x->4(i64)) as usize,
|
||||||
asset_type: serde_json::from_str(&get!(x->5(String))).unwrap(),
|
asset_type: serde_json::from_str(&get!(x->5(String))).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM reports ORDER BY created DESC LIMIT $1 OFFSET $2",
|
"SELECT * FROM reports ORDER BY created DESC LIMIT $1 OFFSET $2",
|
||||||
&[&(batch as isize), &((page * batch) as isize)],
|
&[&(batch as i64), &((page * batch) as i64)],
|
||||||
|x| { Self::get_report_from_row(x) }
|
|x| { Self::get_report_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> UserBlock {
|
) -> UserBlock {
|
||||||
UserBlock {
|
UserBlock {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
initiator: get!(x->2(isize)) as usize,
|
initiator: get!(x->2(i64)) as usize,
|
||||||
receiver: get!(x->3(isize)) as usize,
|
receiver: get!(x->3(i64)) as usize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ impl DataManager {
|
||||||
let res = query_row!(
|
let res = query_row!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM userblocks WHERE initiator = $1 AND receiver = $2",
|
"SELECT * FROM userblocks WHERE initiator = $1 AND receiver = $2",
|
||||||
&[&(initiator as isize), &(receiver as isize)],
|
&[&(initiator as i64), &(receiver as i64)],
|
||||||
|x| { Ok(Self::get_userblock_from_row(x)) }
|
|x| { Ok(Self::get_userblock_from_row(x)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ impl DataManager {
|
||||||
let res = query_row!(
|
let res = query_row!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM userblocks WHERE receiver = $1 AND initiator = $2",
|
"SELECT * FROM userblocks WHERE receiver = $1 AND initiator = $2",
|
||||||
&[&(receiver as isize), &(initiator as isize)],
|
&[&(receiver as i64), &(initiator as i64)],
|
||||||
|x| { Ok(Self::get_userblock_from_row(x)) }
|
|x| { Ok(Self::get_userblock_from_row(x)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ impl DataManager {
|
||||||
#[cfg(feature = "postgres")] x: &Row,
|
#[cfg(feature = "postgres")] x: &Row,
|
||||||
) -> UserFollow {
|
) -> UserFollow {
|
||||||
UserFollow {
|
UserFollow {
|
||||||
id: get!(x->0(isize)) as usize,
|
id: get!(x->0(i64)) as usize,
|
||||||
created: get!(x->1(isize)) as usize,
|
created: get!(x->1(i64)) as usize,
|
||||||
initiator: get!(x->2(isize)) as usize,
|
initiator: get!(x->2(i64)) as usize,
|
||||||
receiver: get!(x->3(isize)) as usize,
|
receiver: get!(x->3(i64)) as usize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ impl DataManager {
|
||||||
let res = query_row!(
|
let res = query_row!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM userfollows WHERE initiator = $1 AND receiver = $2",
|
"SELECT * FROM userfollows WHERE initiator = $1 AND receiver = $2",
|
||||||
&[&(initiator as isize), &(receiver as isize)],
|
&[&(initiator as i64), &(receiver as i64)],
|
||||||
|x| { Ok(Self::get_userfollow_from_row(x)) }
|
|x| { Ok(Self::get_userfollow_from_row(x)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ impl DataManager {
|
||||||
let res = query_row!(
|
let res = query_row!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM userfollows WHERE receiver = $1 AND initiator = $2",
|
"SELECT * FROM userfollows WHERE receiver = $1 AND initiator = $2",
|
||||||
&[&(receiver as isize), &(initiator as isize)],
|
&[&(receiver as i64), &(initiator as i64)],
|
||||||
|x| { Ok(Self::get_userfollow_from_row(x)) }
|
|x| { Ok(Self::get_userfollow_from_row(x)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -95,11 +95,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM userfollows WHERE initiator = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
"SELECT * FROM userfollows WHERE initiator = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||||
&[
|
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||||
&(id as isize),
|
|
||||||
&(batch as isize),
|
|
||||||
&((page * batch) as isize)
|
|
||||||
],
|
|
||||||
|x| { Self::get_userfollow_from_row(x) }
|
|x| { Self::get_userfollow_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -130,11 +126,7 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
"SELECT * FROM userfollows WHERE receiver = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
"SELECT * FROM userfollows WHERE receiver = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||||
&[
|
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||||
&(id as isize),
|
|
||||||
&(batch as isize),
|
|
||||||
&((page * batch) as isize)
|
|
||||||
],
|
|
||||||
|x| { Self::get_userfollow_from_row(x) }
|
|x| { Self::get_userfollow_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue