Skip to content

Commit a8e0633

Browse files
authored
Merge pull request #2 from cclvi256/refactor/database-any
Refactor database connection from generic based to any
2 parents 6113ff8 + aebb7ab commit a8e0633

File tree

12 files changed

+270
-60
lines changed

12 files changed

+270
-60
lines changed

Cargo.lock

Lines changed: 126 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "botcat-capoo"
33
version = "0.2.2"
44
edition = "2024"
55
authors = ["cclvi256 <i@cclvi.cc>"]
6-
description = "A QQ bot implemented in Rust"
6+
description = "A NapCat based QQ bot implemented in Rust"
77
keywords = ["qq", "bot", "napcat", "chatbot"]
88
homepage = "https://github.com/cclvi256/botcat-capoo"
99
repository = "https://github.com/cclvi256/botcat-capoo"
@@ -19,11 +19,14 @@ serde = { version = "1.0.219", features = ["derive"] }
1919
serde_json = "1.0.142"
2020
sqlx = { version = "0.8.6", features = [
2121
"any",
22+
"chrono",
2223
"macros",
24+
"migrate",
2325
"mysql",
2426
"postgres",
2527
"runtime-tokio-rustls",
2628
"sqlite",
29+
"uuid",
2730
] }
2831
thiserror = "2.0.14"
2932
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }

config/example.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ host = "::"
77
port = 8080
88
owner = "Your QQ ID here"
99
id = "Your Bot's QQ ID here"
10-
# Deprecated, use [botcat_capoo.database] section instead
11-
# If [botcat_capoo.database] is not specified, this will be used as a fallback
12-
database_url = "Your database URL here, e.g., sqlite://data/botcat_capoo.sqlite"
1310

1411
[botcat_capoo.database]
1512
# Options: Postgres, Sqlite, MySql, Common abbreviations are supported, case insensitive

src/api/history.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ pub async fn get_private_history(
6464
#[cfg(test)]
6565
mod tests {
6666
use super::*;
67-
use crate::config::load_config;
6867

6968
#[tokio::test]
7069
#[ignore = "Requires an API server in internal network"]
7170
async fn test_get_group_history() {
72-
let config = load_config().expect("Failed to load config");
71+
let config = AppConfig::init().expect("Failed to load config");
7372
println!("Loaded config");
7473

7574
match get_group_history(&config, 738943282, 20, true).await {
@@ -85,7 +84,7 @@ mod tests {
8584
#[tokio::test]
8685
#[ignore = "Requires an API server in internal network"]
8786
async fn test_get_private_history() {
88-
let config = load_config().expect("Failed to load config");
87+
let config = AppConfig::init().expect("Failed to load config");
8988
println!("Loaded config");
9089

9190
match get_private_history(&config, 46595749, 20, true).await {

src/api/poke.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,35 @@ pub async fn group_poke(config: &AppConfig, group_id: u64, to: u64) {
4242
#[cfg(test)]
4343
mod tests {
4444
use super::*;
45-
use crate::config::load_config;
4645

4746
#[tokio::test]
4847
#[ignore = "Requires an API server in internal network"]
4948
async fn test_private_poke() {
50-
let config = load_config().expect("Failed to load config");
49+
let config = AppConfig::init().expect("Failed to load config");
5150
println!("Loaded config");
5251
private_poke(&config, 46595749, false).await;
5352
}
5453

5554
#[tokio::test]
5655
#[ignore = "Requires an API server in internal network"]
5756
async fn test_private_self_poke() {
58-
let config = load_config().expect("Failed to load config");
57+
let config = AppConfig::init().expect("Failed to load config");
5958
println!("Loaded config");
6059
private_poke(&config, 46595749, true).await;
6160
}
6261

6362
#[tokio::test]
6463
#[ignore = "Requires an API server in internal network"]
6564
async fn test_group_poke() {
66-
let config = load_config().expect("Failed to load config");
65+
let config = AppConfig::init().expect("Failed to load config");
6766
println!("Loaded config");
6867
group_poke(&config, 738943282, 46595749).await;
6968
}
7069

7170
#[tokio::test]
7271
#[ignore = "Requires an API server in internal network"]
7372
async fn test_group_self_poke() {
74-
let config = load_config().expect("Failed to load config");
73+
let config = AppConfig::init().expect("Failed to load config");
7574
println!("Loaded config");
7675
group_poke(&config, 738943282, config.botcat_capoo.id).await;
7776
}

src/api/send_message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ pub async fn send_private_message(config: &AppConfig, to: u64, message: Message)
3939
#[cfg(test)]
4040
mod tests {
4141
use super::*;
42-
use crate::config::load_config;
42+
4343
use crate::model::message::segment::MessageSegment;
4444

4545
#[tokio::test]
4646
#[ignore = "Requires an API server in internal network"]
4747
async fn test_send_group_message() {
48-
let config = load_config().expect("Failed to load config");
48+
let config = AppConfig::init().expect("Failed to load config");
4949
println!("Loaded config");
5050
let message = vec![
5151
MessageSegment::At {
@@ -61,7 +61,7 @@ mod tests {
6161
#[tokio::test]
6262
#[ignore = "Requires an API server in internal network"]
6363
async fn test_send_private_message() {
64-
let config = load_config().expect("Failed to load config");
64+
let config = AppConfig::init().expect("Failed to load config");
6565
println!("Loaded config");
6666
let message = vec![MessageSegment::Text {
6767
text: "Hello, user!".to_string(),

0 commit comments

Comments
 (0)