-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rustqlite example #49
base: main
Are you sure you want to change the base?
Conversation
1e062a2
to
7495566
Compare
Hey, thanks for the PR. The examples all use sqlite now. If it is about persisting the DB to a file, maybe that can be added as a CLI option to the existing example? |
Good idea, let's do that :) |
7495566
to
8ca1b92
Compare
@carllerche I opted for grabbing the CLI arg directly instead of using Clap etc. Cheers! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason for not using clap? few minor nits and can we squash commits, as context for both revolves around same file. Rest look ok.
let flag = "--persist-to-file"; | ||
let driver = if args.len() > 1 && args[1] == flag { | ||
// Persist to local file | ||
let filename = "toasty.db3"; | ||
let file_path = format!("./{}", filename); | ||
let file = PathBuf::from(file_path.as_str()); | ||
Sqlite::open(file).unwrap() | ||
} else { | ||
// Use the in-memory sqlite driver | ||
Sqlite::in_memory() | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let flag = "--persist-to-file"; | |
let driver = if args.len() > 1 && args[1] == flag { | |
// Persist to local file | |
let filename = "toasty.db3"; | |
let file_path = format!("./{}", filename); | |
let file = PathBuf::from(file_path.as_str()); | |
Sqlite::open(file).unwrap() | |
} else { | |
// Use the in-memory sqlite driver | |
Sqlite::in_memory() | |
}; | |
const PERSIST_FLAG: &str = "--persist-to-file"; | |
const DB_FILENAME: &str = "toasty.db3"; | |
let driver = if args.get(1).map_or(false, |arg| arg == PERSIST_FLAG) { | |
let file_path = PathBuf::from(DB_FILENAME); | |
Sqlite::open(file_path).expect("Failed to open SQLite file") | |
} else { | |
Sqlite::in_memory() | |
}; |
This also incorporates corrections in #47