From 4a981d109aaf6950308fbdc8317ff50990bd6e74 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 26 Dec 2023 10:50:02 +0800 Subject: [PATCH] update example --- examples/sqlite/.gitignore | 1 + examples/sqlite/Cargo.toml | 1 + examples/sqlite/src/main.rs | 21 +++++++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 examples/sqlite/.gitignore diff --git a/examples/sqlite/.gitignore b/examples/sqlite/.gitignore new file mode 100644 index 0000000..a7ca880 --- /dev/null +++ b/examples/sqlite/.gitignore @@ -0,0 +1 @@ +/workspace diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index 21c7d80..fdc54e6 100644 --- a/examples/sqlite/Cargo.toml +++ b/examples/sqlite/Cargo.toml @@ -7,4 +7,5 @@ version.workspace = true [dependencies] luna-orm = "0.3.1" +sqlx = { version = "0.7", features = [ "runtime-tokio" ] } tokio = { version = "1.35.1", features = ["full"] } diff --git a/examples/sqlite/src/main.rs b/examples/sqlite/src/main.rs index 6c5f945..903acf2 100644 --- a/examples/sqlite/src/main.rs +++ b/examples/sqlite/src/main.rs @@ -1,8 +1,21 @@ -use luna_orm::error::LunaOrmError; -use luna_orm::preclude::*; +use luna_orm::prelude::*; +use luna_orm::LunaOrmResult; #[tokio::main] -async fn main() -> Result<(), LunaOrmError> { - println!("Hello, world!"); +async fn main() -> LunaOrmResult<()> { + let config = SqliteLocalConfig { + work_dir: "./workspace".to_string(), + db_file: "test.db".to_string(), + }; + + // 2. create a DB instance. + let mut db: DB = SqliteDatabase::build(config).await.unwrap().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(()) }