Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
soulww committed Dec 26, 2023
1 parent 9bdcd79 commit 4a981d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/sqlite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/workspace
1 change: 1 addition & 0 deletions examples/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
21 changes: 17 additions & 4 deletions examples/sqlite/src/main.rs
Original file line number Diff line number Diff line change
@@ -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> = 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(())
}

0 comments on commit 4a981d1

Please sign in to comment.