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

Method do_execute

examples/proxy_cloudflare_worker_example/src/orm.rs:103–166  ·  view source on GitHub ↗
(env: Arc<Env>, statement: Statement)

Source from the content-addressed store, hash-verified

101 }
102
103 async fn do_execute(env: Arc<Env>, statement: Statement) -> Result<ProxyExecResult> {
104 let sql = statement.sql.clone();
105 let values = match statement.values {
106 Some(Values(values)) => values
107 .iter()
108 .map(|val| match &val {
109 Value::BigInt(Some(val)) => JsValue::from(val.to_string()),
110 Value::BigUnsigned(Some(val)) => JsValue::from(val.to_string()),
111 Value::Int(Some(val)) => JsValue::from(*val),
112 Value::Unsigned(Some(val)) => JsValue::from(*val),
113 Value::SmallInt(Some(val)) => JsValue::from(*val),
114 Value::SmallUnsigned(Some(val)) => JsValue::from(*val),
115 Value::TinyInt(Some(val)) => JsValue::from(*val),
116 Value::TinyUnsigned(Some(val)) => JsValue::from(*val),
117
118 Value::Float(Some(val)) => JsValue::from_f64(*val as f64),
119 Value::Double(Some(val)) => JsValue::from_f64(*val),
120
121 Value::Bool(Some(val)) => JsValue::from(*val),
122 Value::Bytes(Some(val)) => JsValue::from(format!(
123 "X'{}'",
124 val.iter()
125 .map(|byte| format!("{:02x}", byte))
126 .collect::<String>()
127 )),
128 Value::Char(Some(val)) => JsValue::from(val.to_string()),
129 Value::Json(Some(val)) => JsValue::from(val.to_string()),
130 Value::String(Some(val)) => JsValue::from(val.to_string()),
131
132 Value::ChronoDate(Some(val)) => JsValue::from(val.to_string()),
133 Value::ChronoDateTime(Some(val)) => JsValue::from(val.to_string()),
134 Value::ChronoDateTimeLocal(Some(val)) => JsValue::from(val.to_string()),
135 Value::ChronoDateTimeUtc(Some(val)) => JsValue::from(val.to_string()),
136 Value::ChronoDateTimeWithTimeZone(Some(val)) => JsValue::from(val.to_string()),
137
138 _ => JsValue::NULL,
139 })
140 .collect(),
141 None => Vec::new(),
142 };
143
144 let ret = env
145 .d1("test-d1")?
146 .prepare(sql)
147 .bind(&values)?
148 .run()
149 .await?
150 .meta()?;
151 console_log!("SQL execute result: {:?}", ret);
152
153 let last_insert_id = ret
154 .as_ref()
155 .map(|meta| meta.last_row_id.unwrap_or(0))
156 .unwrap_or(0) as u64;
157 let rows_affected = ret
158 .as_ref()
159 .map(|meta| meta.rows_written.unwrap_or(0))
160 .unwrap_or(0) as u64;

Callers

nothing calls this directly

Calls 4

prepareMethod · 0.80
as_refMethod · 0.80
newFunction · 0.50
runMethod · 0.45

Tested by

no test coverage detected