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

Function main

examples/proxy_gluesql_example/src/main.rs:135–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

133
134#[async_std::main]
135async fn main() {
136 let mem = MemoryStorage::default();
137 let mut glue = Glue::new(mem);
138
139 glue.execute(
140 r#"
141 CREATE TABLE IF NOT EXISTS posts (
142 id INTEGER PRIMARY KEY,
143 title TEXT NOT NULL,
144 text TEXT NOT NULL
145 )
146 "#,
147 )
148 .await
149 .unwrap();
150
151 let db = Database::connect_proxy(
152 DbBackend::Sqlite,
153 Arc::new(Box::new(ProxyDb {
154 mem: Mutex::new(glue),
155 })),
156 )
157 .await
158 .unwrap();
159
160 println!("Initialized");
161
162 let data = ActiveModel {
163 id: Set(11),
164 title: Set("Homo".to_owned()),
165 text: Set("いいよ、来いよ".to_owned()),
166 };
167 Entity::insert(data).exec(&db).await.unwrap();
168 let data = ActiveModel {
169 id: Set(45),
170 title: Set("Homo".to_owned()),
171 text: Set("そうだよ".to_owned()),
172 };
173 Entity::insert(data).exec(&db).await.unwrap();
174 let data = ActiveModel {
175 id: Set(14),
176 title: Set("Homo".to_owned()),
177 text: Set("悔い改めて".to_owned()),
178 };
179 Entity::insert(data).exec(&db).await.unwrap();
180
181 let list = Entity::find().all(&db).await.unwrap().to_vec();
182 println!("Result: {:?}", list);
183}
184
185#[cfg(test)]
186mod tests {

Callers 1

try_runFunction · 0.70

Calls 5

unwrapMethod · 0.80
newFunction · 0.50
executeMethod · 0.45
execMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected