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

Function main

issues/1357/src/main.rs:9–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7
8#[tokio::main]
9async fn main() -> Result<()> {
10 let db = Database::connect("sqlite::memory:").await.unwrap();
11
12 let builder = db.get_database_backend();
13 let schema = Schema::new(builder);
14 let stmt = schema.create_table_from_entity(Entity);
15 db.execute(builder.build(&stmt)).await?;
16
17 let model = Model {
18 id: 100,
19 name: "Hello".to_owned(),
20 };
21
22 let res = Entity::insert(model.clone().into_active_model())
23 .exec(&db)
24 .await?;
25
26 assert_eq!(Entity::find().one(&db).await?, Some(model.clone()));
27 assert_eq!(res.last_insert_id, model.id);
28
29 let model = Model {
30 id: -10,
31 name: "World".to_owned(),
32 };
33
34 let res = Entity::insert(model.clone().into_active_model())
35 .exec(&db)
36 .await?;
37
38 assert_eq!(Entity::find().one(&db).await?, Some(model.clone()));
39 assert_eq!(res.last_insert_id, model.id);
40
41 Ok(())
42}

Callers

nothing calls this directly

Calls 8

unwrapMethod · 0.80
into_active_modelMethod · 0.80
newFunction · 0.50
get_database_backendMethod · 0.45
executeMethod · 0.45
buildMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected