Skip to content

Commit

Permalink
add mysql example
Browse files Browse the repository at this point in the history
  • Loading branch information
soulww committed Dec 26, 2023
1 parent 4a981d1 commit f5ff9b6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/mysql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
18 changes: 18 additions & 0 deletions examples/mysql/src/main.rs
Original file line number Diff line number Diff line change
@@ -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> = 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(())
}

0 comments on commit f5ff9b6

Please sign in to comment.