sqlx
This commit is contained in:
parent
b3c3c8cfb0
commit
083d53d335
5 changed files with 732 additions and 67 deletions
1
.env
Normal file
1
.env
Normal file
|
@ -0,0 +1 @@
|
|||
DATABASE_URL=""
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,7 +2,7 @@
|
|||
/target
|
||||
|
||||
# Tokens
|
||||
.env
|
||||
# .env
|
||||
|
||||
# Hidden files
|
||||
/src/.*
|
||||
|
|
757
Cargo.lock
generated
757
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -16,10 +16,8 @@ serenity = { version = "0.12.0", default-features = false, features = ["client",
|
|||
serenity_utils = "0.7.0"
|
||||
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
|
||||
regex = "1.9.0"
|
||||
# sqlite = "0.32.0"
|
||||
# async-sqlite = { version = "0.2.1", default-features = false }
|
||||
async-rusqlite = "0.4.0"
|
||||
chrono = "0.4.31"
|
||||
sqlx = {version="0.7.3", features=["runtime-tokio", "sqlite"]}
|
||||
|
||||
[features]
|
||||
DEBUG = []
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
use chrono::{Datelike, Local};
|
||||
use serenity::prelude::*;
|
||||
use chrono::{Local, Datelike};
|
||||
|
||||
// use async_sqlite::{rusqlite::{Rows, Statement}, ClientBuilder, JournalMode};
|
||||
|
||||
use crate::util::debug::send_error;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use async_rusqlite::Connection;
|
||||
|
||||
pub async fn notice_wrapper(ctx: Context) {
|
||||
match notice(ctx.clone()).await {
|
||||
Ok(_) => return,
|
||||
Err(e) => {
|
||||
send_error(ctx.http.clone(), e.to_string()).await;
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +18,7 @@ pub async fn notice_wrapper(ctx: Context) {
|
|||
struct BirtdayRow {
|
||||
day: u8,
|
||||
month: u8,
|
||||
nick: String
|
||||
nick: String,
|
||||
}
|
||||
|
||||
async fn notice(ctx: Context) -> anyhow::Result<()> {
|
||||
|
@ -30,12 +26,16 @@ async fn notice(ctx: Context) -> anyhow::Result<()> {
|
|||
let day = local.day();
|
||||
let month = local.month();
|
||||
|
||||
let pool = sqlx::sqlite::SqlitePoolOptions::new()
|
||||
.connect("my.db")
|
||||
.await?;
|
||||
|
||||
let conn = Connection::open("my.db").await?;
|
||||
|
||||
let stmt = conn.call(move |conn| {
|
||||
conn.prepare("SELECT * FROM birthdays WHERE day=6 AND month=3;")
|
||||
}).await?;
|
||||
let birtdays: Vec<BirtdayRow> = sqlx::query_as!(
|
||||
BirtdayRow,
|
||||
"SELECT * FROM birthdays WHERE day=6 AND month=3;"
|
||||
)
|
||||
.fetch(&pool)
|
||||
.await?;
|
||||
|
||||
// let result = Vec::new();
|
||||
// let stmt = client.conn(|conn| {
|
||||
|
@ -50,7 +50,7 @@ async fn notice(ctx: Context) -> anyhow::Result<()> {
|
|||
let bd = BirtdayRow {
|
||||
day: row.get(1)?,
|
||||
month: row.get(2)?,
|
||||
nick: row.get(3)?
|
||||
nick: row.get(3)?,
|
||||
};
|
||||
result.push(bd);
|
||||
}
|
||||
|
@ -65,3 +65,4 @@ async fn notice(ctx: Context) -> anyhow::Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue