Migrate to diesel for db
This commit is contained in:
parent
7aeb45acf4
commit
db8a180c00
9 changed files with 123 additions and 91 deletions
1
.env
Normal file
1
.env
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DATABASE_URL=./src/storage/db.sqlite
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
src/storage/db.sqlite
|
75
Cargo.lock
generated
75
Cargo.lock
generated
|
@ -432,6 +432,12 @@ version = "3.14.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
|
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
|
@ -603,6 +609,45 @@ dependencies = [
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "diesel"
|
||||||
|
version = "2.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "62c6fcf842f17f8c78ecf7c81d75c5ce84436b41ee07e03f490fbb5f5a8731d8"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.4.1",
|
||||||
|
"byteorder",
|
||||||
|
"diesel_derives",
|
||||||
|
"itoa",
|
||||||
|
"libsqlite3-sys",
|
||||||
|
"mysqlclient-sys",
|
||||||
|
"percent-encoding",
|
||||||
|
"pq-sys",
|
||||||
|
"time",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "diesel_derives"
|
||||||
|
version = "2.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ef8337737574f55a468005a83499da720f20c65586241ffea339db9ecdfd2b44"
|
||||||
|
dependencies = [
|
||||||
|
"diesel_table_macro_syntax",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.39",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "diesel_table_macro_syntax"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5"
|
||||||
|
dependencies = [
|
||||||
|
"syn 2.0.39",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
|
@ -1138,12 +1183,23 @@ version = "0.2.150"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libsqlite3-sys"
|
||||||
|
version = "0.27.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716"
|
||||||
|
dependencies = [
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linstrom"
|
name = "linstrom"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
"activitypub_federation",
|
||||||
"axum 0.7.1",
|
"axum 0.7.1",
|
||||||
|
"diesel",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1235,6 +1291,16 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mysqlclient-sys"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f61b381528ba293005c42a409dd73d034508e273bf90481f17ec2e964a6e969b"
|
||||||
|
dependencies = [
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "native-tls"
|
name = "native-tls"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
|
@ -1416,6 +1482,15 @@ version = "0.2.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pq-sys"
|
||||||
|
version = "0.4.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "31c0052426df997c0cbd30789eb44ca097e3541717a7b8fa36b1c464ee7edebd"
|
||||||
|
dependencies = [
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.70"
|
version = "1.0.70"
|
||||||
|
|
|
@ -15,4 +15,5 @@ exclude = ["/.vscode", "/FeatureTargets.md"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
activitypub_federation = "0.4.7"
|
activitypub_federation = "0.4.7"
|
||||||
axum = "0.7.1"
|
axum = "0.7.1"
|
||||||
|
diesel = { version = "2.1.4", features = ["sqlite", "postgres"] }
|
||||||
tokio = { version = "1.34.0", features = ["full"]}
|
tokio = { version = "1.34.0", features = ["full"]}
|
||||||
|
|
9
diesel.toml
Normal file
9
diesel.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# For documentation on how to configure this file,
|
||||||
|
# see https://diesel.rs/guides/configuring-diesel-cli
|
||||||
|
|
||||||
|
[print_schema]
|
||||||
|
file = "src/schema.rs"
|
||||||
|
custom_type_derives = ["diesel::query_builder::QueryId"]
|
||||||
|
|
||||||
|
[migrations_directory]
|
||||||
|
dir = "migrations"
|
0
migrations/.keep
Normal file
0
migrations/.keep
Normal file
|
@ -8,9 +8,7 @@
|
||||||
// See the Licence for the specific language governing permissions and limitations under the Licence.
|
// See the Licence for the specific language governing permissions and limitations under the Licence.
|
||||||
|
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
use diesel::
|
||||||
mod sqlite;
|
|
||||||
mod postgres;
|
|
||||||
|
|
||||||
pub type MessageID = i64;
|
pub type MessageID = i64;
|
||||||
pub type MediaID = i64;
|
pub type MediaID = i64;
|
||||||
|
@ -27,3 +25,38 @@ pub trait StorageAccess {
|
||||||
fn delete_media<T, E>(id: &MediaID) -> Result<T, E>;
|
fn delete_media<T, E>(id: &MediaID) -> Result<T, E>;
|
||||||
// No edit media because how? Editing media in a message replaces the media, not edits it
|
// No edit media because how? Editing media in a message replaces the media, not edits it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub struct Storage {
|
||||||
|
db:
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StorageAccess for Storage {
|
||||||
|
fn store_message<E>(user: &str, message: &str) -> Result<MediaID, E> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_message<E>(user: &str, id: &MessageID) -> Result<String, E> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_message<T, E>(id: &MessageID) -> Result<T, E> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn edit_message<T, E>(id: &MessageID, message: &str) -> Result<T, E> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn store_media<E>(f: &File, nsfw: bool, alt_text: Option<&str>) -> Result<MediaID, E> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_media<E>(id: &MediaID) -> Result<(File, bool, Option<String>), E> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_media<T, E>(id: &MediaID) -> Result<T, E> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,44 +0,0 @@
|
||||||
// Copyright (c) 2023 mStar
|
|
||||||
//
|
|
||||||
// Licensed under the EUPL, Version 1.2
|
|
||||||
//
|
|
||||||
// You may not use this work except in compliance with the Licence.
|
|
||||||
// You should have received a copy of the Licence along with this work. If not, see:
|
|
||||||
// <https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12>.
|
|
||||||
// See the Licence for the specific language governing permissions and limitations under the Licence.
|
|
||||||
|
|
||||||
use crate::storage;
|
|
||||||
|
|
||||||
struct PostgressDB {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl storage::StorageAccess for PostgressDB {
|
|
||||||
fn store_message<E>(user: &str, message: &str) -> Result<storage::MediaID, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_message<E>(user: &str, id: &storage::MessageID) -> Result<String, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete_message<T, E>(id: &storage::MessageID) -> Result<T, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn edit_message<T, E>(id: &storage::MessageID, message: &str) -> Result<T, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn store_media<E>(f: &tokio::fs::File, nsfw: bool, alt_text: Option<&str>) -> Result<storage::MediaID, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_media<E>(id: &storage::MediaID) -> Result<(tokio::fs::File, bool, Option<String>), E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete_media<T, E>(id: &storage::MediaID) -> Result<T, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
// Copyright (c) 2023 mStar
|
|
||||||
//
|
|
||||||
// Licensed under the EUPL, Version 1.2
|
|
||||||
//
|
|
||||||
// You may not use this work except in compliance with the Licence.
|
|
||||||
// You should have received a copy of the Licence along with this work. If not, see:
|
|
||||||
// <https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12>.
|
|
||||||
// See the Licence for the specific language governing permissions and limitations under the Licence.
|
|
||||||
|
|
||||||
use crate::storage;
|
|
||||||
|
|
||||||
struct LiteDB {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl storage::StorageAccess for LiteDB {
|
|
||||||
fn store_message<E>(user: &str, message: &str) -> Result<storage::MediaID, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_message<E>(user: &str, id: &storage::MessageID) -> Result<String, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete_message<T, E>(id: &storage::MessageID) -> Result<T, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn edit_message<T, E>(id: &storage::MessageID, message: &str) -> Result<T, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn store_media<E>(f: &tokio::fs::File, nsfw: bool, alt_text: Option<&str>) -> Result<storage::MediaID, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_media<E>(id: &storage::MediaID) -> Result<(tokio::fs::File, bool, Option<String>), E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete_media<T, E>(id: &storage::MediaID) -> Result<T, E> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue