From f5ff9b6b377ed3406ec092bf5ded1f8d74988477 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 26 Dec 2023 10:58:53 +0800 Subject: [PATCH] add mysql example --- examples/mysql/Cargo.toml | 11 +++++++++++ examples/mysql/src/main.rs | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 examples/mysql/Cargo.toml create mode 100644 examples/mysql/src/main.rs diff --git a/examples/mysql/Cargo.toml b/examples/mysql/Cargo.toml new file mode 100644 index 0000000..44a0ac2 --- /dev/null +++ b/examples/mysql/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "mysql" +edition = "2021" +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +luna-orm = "0.3.1" +sqlx = { version = "0.7", features = [ "runtime-tokio" ] } +tokio = { version = "1.35.1", features = ["full"] } diff --git a/examples/mysql/src/main.rs b/examples/mysql/src/main.rs new file mode 100644 index 0000000..f7acc38 --- /dev/null +++ b/examples/mysql/src/main.rs @@ -0,0 +1,18 @@ +use luna_orm::prelude::*; +use luna_orm::LunaOrmResult; + +#[tokio::main] +async fn main() -> LunaOrmResult<()> { + // 2. create a DB instance. + let mut db: DB = MysqlDatabase::build("localhost/test", "user", "passwod") + .await? + .into(); + + // 3. optional: you may need to create the table for the first time. + let result = db.execute_plain( + "CREATE TABLE IF NOT EXISTS `user`(`id` INT PRIMARY KEY, `age` INT, `name` VARCHAR(64))", + ).await?; + + println!("result: {}", result.rows_affected()); + Ok(()) +}