MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / handler_generate

Function handler_generate

examples/proxy_cloudflare_worker_example/src/route.rs:63–90  ·  view source on GitHub ↗
(
    State(state): State<CFEnv>,
)

Source from the content-addressed store, hash-verified

61}
62
63async fn handler_generate(
64 State(state): State<CFEnv>,
65) -> Result<impl IntoResponse, (StatusCode, String)> {
66 let env = state.env.clone();
67 let db = crate::orm::init_db(env).await.map_err(|err| {
68 console_log!("Failed to connect to database: {:?}", err);
69 (
70 StatusCode::INTERNAL_SERVER_ERROR,
71 "Failed to connect to database".to_string(),
72 )
73 })?;
74
75 let ret = crate::entity::ActiveModel {
76 id: NotSet,
77 title: Set(chrono::Utc::now().to_rfc3339()),
78 text: Set(uuid::Uuid::new_v4().to_string()),
79 };
80
81 let ret = ret.insert(&db).await.map_err(|err| {
82 console_log!("Failed to insert into database: {:?}", err);
83 (
84 StatusCode::INTERNAL_SERVER_ERROR,
85 "Failed to insert into database".to_string(),
86 )
87 })?;
88
89 Ok(format!("Inserted: {:?}", ret).into_response())
90}

Callers

nothing calls this directly

Calls 2

init_dbFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected