Atproto, add sqlx support
This commit is contained in:
parent
ab78d1fb7b
commit
0707b5eed4
6 changed files with 102 additions and 1 deletions
55
Cargo.lock
generated
55
Cargo.lock
generated
|
|
@ -118,6 +118,9 @@ dependencies = [
|
||||||
"lazy-regex",
|
"lazy-regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"sqlx",
|
||||||
|
"thiserror 2.0.12",
|
||||||
|
"time",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
@ -581,6 +584,15 @@ dependencies = [
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deranged"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e"
|
||||||
|
dependencies = [
|
||||||
|
"powerfmt",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_builder"
|
name = "derive_builder"
|
||||||
version = "0.20.2"
|
version = "0.20.2"
|
||||||
|
|
@ -1470,6 +1482,12 @@ dependencies = [
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-conv"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-integer"
|
name = "num-integer"
|
||||||
version = "0.1.46"
|
version = "0.1.46"
|
||||||
|
|
@ -1625,6 +1643,12 @@ dependencies = [
|
||||||
"zerovec",
|
"zerovec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "powerfmt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.21"
|
version = "0.2.21"
|
||||||
|
|
@ -2410,6 +2434,37 @@ dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.3.41"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40"
|
||||||
|
dependencies = [
|
||||||
|
"deranged",
|
||||||
|
"itoa",
|
||||||
|
"num-conv",
|
||||||
|
"powerfmt",
|
||||||
|
"serde",
|
||||||
|
"time-core",
|
||||||
|
"time-macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-core"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-macros"
|
||||||
|
version = "0.2.22"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49"
|
||||||
|
dependencies = [
|
||||||
|
"num-conv",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinystr"
|
name = "tinystr"
|
||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ async-trait = "0.1.88"
|
||||||
atproto = { path = "./atproto" }
|
atproto = { path = "./atproto" }
|
||||||
serde = "1.0.219"
|
serde = "1.0.219"
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
|
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio"] }
|
||||||
thiserror = "2.0.12"
|
thiserror = "2.0.12"
|
||||||
tokio = { version = "1.45.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.45.0", features = ["macros", "rt-multi-thread"] }
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,12 @@ atrium-api = { version = "0.25.3", default-features = false }
|
||||||
lazy-regex = "3.4.1"
|
lazy-regex = "3.4.1"
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
sqlx = { workspace = true, optional = true }
|
||||||
time = { version = "0.3.41", features = ["parsing", "formatting"] }
|
time = { version = "0.3.41", features = ["parsing", "formatting"] }
|
||||||
tracing-subscriber.workspace = true
|
tracing-subscriber.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
sqlx-support = ["dep:sqlx"]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
pub mod lexicons;
|
pub mod lexicons;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
#[cfg(feature = "sqlx-support")]
|
||||||
|
pub mod sqlx;
|
||||||
|
|
|
||||||
38
atproto/src/sqlx.rs
Normal file
38
atproto/src/sqlx.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
use crate::types::{
|
||||||
|
Did,
|
||||||
|
Cid,
|
||||||
|
Uri,
|
||||||
|
Handle,
|
||||||
|
Datetime,
|
||||||
|
};
|
||||||
|
|
||||||
|
macro_rules! implement_sqlx_for_string_type {
|
||||||
|
($name:ident) => {
|
||||||
|
impl sqlx::Type<sqlx::Postgres> for $name {
|
||||||
|
fn type_info() -> sqlx::postgres::PgTypeInfo {
|
||||||
|
<String as sqlx::Type<sqlx::Postgres>>::type_info()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for $name {
|
||||||
|
fn encode_by_ref(
|
||||||
|
&self, buf: &mut sqlx::postgres::PgArgumentBuffer
|
||||||
|
) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
|
||||||
|
<String as sqlx::Encode<sqlx::Postgres>>::encode_by_ref(&self.to_string(), buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'r> sqlx::Decode<'r, sqlx::Postgres> for $name {
|
||||||
|
fn decode(
|
||||||
|
value: sqlx::postgres::PgValueRef<'r>
|
||||||
|
) -> Result<Self, sqlx::error::BoxDynError> {
|
||||||
|
let s = <String as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
|
||||||
|
s.parse::<$name>().map_err(|e| Box::new(e) as sqlx::error::BoxDynError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
implement_sqlx_for_string_type!(Did);
|
||||||
|
implement_sqlx_for_string_type!(Cid);
|
||||||
|
implement_sqlx_for_string_type!(Uri);
|
||||||
|
implement_sqlx_for_string_type!(Handle);
|
||||||
|
implement_sqlx_for_string_type!(Datetime);
|
||||||
|
|
@ -4,8 +4,8 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
atproto.workspace = true
|
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
|
atproto = { workspace = true, features = ["sqlx-support"] }
|
||||||
sqlx.workspace = true
|
sqlx.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue