fix: postgres
This commit is contained in:
parent
dcd5f359c6
commit
27d7c2f4b5
29 changed files with 298 additions and 224 deletions
|
@ -13,6 +13,7 @@ use bb8_postgres::{
|
|||
use std::collections::HashMap;
|
||||
use tetratto_l10n::{LangFile, read_langs};
|
||||
use tokio_postgres::{Config as PgConfig, NoTls, Row, types::ToSql};
|
||||
use std::str::FromStr;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, tokio_postgres::Error>;
|
||||
pub type Connection<'a> = PooledConnection<'a, PostgresConnectionManager<NoTls>>;
|
||||
|
@ -35,13 +36,14 @@ impl DataManager {
|
|||
/// Create a new [`DataManager`] (and init database).
|
||||
pub async fn new(config: Config) -> Result<Self> {
|
||||
let manager = PostgresConnectionManager::new(
|
||||
{
|
||||
let mut c = PgConfig::new();
|
||||
c.user(&config.database.user);
|
||||
c.password(&config.database.password);
|
||||
c.dbname(&config.database.name);
|
||||
c
|
||||
},
|
||||
PgConfig::from_str(&format!(
|
||||
"postgresql://{}:{}@{}/{}?target_session_attrs=read-write",
|
||||
config.database.user,
|
||||
config.database.password,
|
||||
config.database.url,
|
||||
config.database.name
|
||||
))
|
||||
.unwrap(),
|
||||
NoTls,
|
||||
);
|
||||
|
||||
|
@ -144,3 +146,13 @@ macro_rules! execute {
|
|||
crate::database::execute_helper($conn, $sql, &[]).await
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! params {
|
||||
() => {
|
||||
&[]
|
||||
};
|
||||
($($x:expr),+ $(,)?) => {
|
||||
&[$(&$x),+]
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
CREATE TABLE IF NOT EXISTS audit_log (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
owner INTEGER NOT NULL,
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
CREATE TABLE IF NOT EXISTS communities (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
context TEXT NOT NULL,
|
||||
owner INTEGER NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
read_access TEXT NOT NULL,
|
||||
write_access TEXT NOT NULL,
|
||||
join_access TEXT NOT NULL,
|
||||
-- likes
|
||||
likes INTEGER NOT NULL,
|
||||
dislikes INTEGER NOT NULL,
|
||||
likes BIGINT NOT NULL,
|
||||
dislikes BIGINT NOT NULL,
|
||||
-- counts
|
||||
member_count INTEGER NOT NULL
|
||||
member_count BIGINT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
CREATE TABLE IF NOT EXISTS ipbans (
|
||||
ip TEXT NOT NULL,
|
||||
created INTEGER NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL PRIMARY KEY,
|
||||
reason TEXT NOT NULL,
|
||||
moderator TEXT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
CREATE TABLE IF NOT EXISTS memberships (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
owner INTEGER NOT NULL,
|
||||
community INTEGER NOT NULL,
|
||||
role INTEGER NOT NULL
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
community BIGINT NOT NULL,
|
||||
role BIGINT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
CREATE TABLE IF NOT EXISTS notifications (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
owner INTEGER NOT NULL,
|
||||
read INTEGER NOT NULL
|
||||
owner BIGINT NOT NULL,
|
||||
read BIGINT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
owner INTEGER NOT NULL,
|
||||
community INTEGER NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
community BIGINT NOT NULL,
|
||||
context TEXT NOT NULL,
|
||||
replying_to INTEGER, -- the ID of the post this is a comment on... NULL means it isn't a reply
|
||||
replying_to BIGINT, -- the ID of the post this is a comment on... NULL means it isn't a reply
|
||||
-- likes
|
||||
likes INTEGER NOT NULL,
|
||||
dislikes INTEGER NOT NULL,
|
||||
likes BIGINT NOT NULL,
|
||||
dislikes BIGINT NOT NULL,
|
||||
-- other counts
|
||||
comment_count INTEGER NOT NULL
|
||||
comment_count BIGINT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
CREATE TABLE IF NOT EXISTS reactions (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
owner INTEGER NOT NULL,
|
||||
asset INTEGER NOT NULL,
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
asset BIGINT NOT NULL,
|
||||
asset_type TEXT NOT NULL,
|
||||
is_like INTEGER NOT NULL
|
||||
is_like BIGINT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
CREATE TABLE IF NOT EXISTS reports (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
owner INTEGER NOT NULL,
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
asset INTEGER NOT NULL,
|
||||
asset BIGINT NOT NULL,
|
||||
asset_type TEXT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
CREATE TABLE IF NOT EXISTS userblocks (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
initiator INTEGER NOT NULL,
|
||||
receiver INTEGER NOT NULL
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
initiator BIGINT NOT NULL,
|
||||
receiver BIGINT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
CREATE TABLE IF NOT EXISTS userfollows (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
initiator INTEGER NOT NULL,
|
||||
receiver INTEGER NOT NULL
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
initiator BIGINT NOT NULL,
|
||||
receiver BIGINT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
created INTEGER NOT NULL,
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
salt TEXT NOT NULL,
|
||||
settings TEXT NOT NULL,
|
||||
tokens TEXT NOT NULL,
|
||||
permissions INTEGER NOT NULL,
|
||||
verified INTEGER NOT NULL,
|
||||
notification_count INTEGER NOT NULL,
|
||||
follower_count INTEGER NOT NULL,
|
||||
following_count INTEGER NOT NULL,
|
||||
last_seen INTEGER NOT NULL
|
||||
permissions BIGINT NOT NULL,
|
||||
verified BIGINT NOT NULL,
|
||||
notification_count BIGINT NOT NULL,
|
||||
follower_count BIGINT NOT NULL,
|
||||
following_count BIGINT NOT NULL,
|
||||
last_seen BIGINT NOT NULL
|
||||
)
|
||||
|
|
|
@ -86,3 +86,13 @@ macro_rules! execute {
|
|||
$conn.prepare($sql).unwrap().execute(())
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! params {
|
||||
() => {
|
||||
rusqlite::params![]
|
||||
};
|
||||
($($params:expr),+ $(,)?) => {
|
||||
rusqlite::params![$($params),+]
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue