Skip to content

Commit

Permalink
📌 Pin the latest worker.
Browse files Browse the repository at this point in the history
  • Loading branch information
langyo committed Jul 10, 2024
1 parent f32b473 commit 1aa642c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ yew-router = { git = "https://github.com/langyo/yew", branch = "wasi-support-tes
stylist = { git = "https://github.com/langyo/stylist-rs", branch = "wasi-support" }
prokio = { git = "https://github.com/langyo/prokio", branch = "wasi-fix" }
sea-orm = { git = "https://github.com/langyo/sea-orm", branch = "async-proxy-conn" }
worker = { git = "https://github.com/langyo/workers-rs", branch = "main" }
24 changes: 17 additions & 7 deletions packages/database/src/providers/cloudflare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ use worker::Env;

struct ProxyDb {
env: Arc<Env>,
db_name: String,
}

impl std::fmt::Debug for ProxyDb {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ProxyDb").finish()
f.debug_struct(format!("[ProxyDb] {}", self.db_name).as_str())
.finish()
}
}

Expand Down Expand Up @@ -60,7 +62,12 @@ impl ProxyDb {
None => Vec::new(),
};

let ret = env.d1("test-d1")?.prepare(sql).bind(&values)?.all().await?;
let ret = env
.d1(self.db_name.clone())?
.prepare(sql)
.bind(&values)?
.all()
.await?;
if let Some(message) = ret.error() {
return Err(anyhow!(message.to_string()));
}
Expand Down Expand Up @@ -140,7 +147,7 @@ impl ProxyDb {
};

let ret = env
.d1("test-d1")?
.d1(self.db_name.clone())?
.prepare(sql)
.bind(&values)?
.run()
Expand Down Expand Up @@ -190,10 +197,13 @@ impl ProxyDatabaseTrait for ProxyDb {
}
}

pub async fn init_db(env: Arc<Env>) -> Result<DatabaseConnection> {
let db = Database::connect_proxy(DbBackend::Sqlite, Arc::new(Box::new(ProxyDb { env })))
.await
.context("Failed to connect to database")?;
pub async fn init_db(env: Arc<Env>, db_name: String) -> Result<DatabaseConnection> {
let db = Database::connect_proxy(
DbBackend::Sqlite,
Arc::new(Box::new(ProxyDb { env, db_name })),
)
.await
.context("Failed to connect to database")?;

Ok(db)
}

0 comments on commit 1aa642c

Please sign in to comment.