Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bsodmike
Copy link
Contributor

@bsodmike bsodmike commented Nov 2, 2024

This also incorporates corrections in #47

@bsodmike bsodmike force-pushed the add_rustqlite_example branch from 1e062a2 to 7495566 Compare November 2, 2024 17:55
@carllerche
Copy link
Member

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?

@bsodmike
Copy link
Contributor Author

bsodmike commented Nov 8, 2024

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 :)

@bsodmike bsodmike force-pushed the add_rustqlite_example branch from 7495566 to 8ca1b92 Compare November 9, 2024 08:22
@bsodmike
Copy link
Contributor Author

bsodmike commented Nov 9, 2024

@carllerche I opted for grabbing the CLI arg directly instead of using Clap etc. Cheers!

Copy link

@Shourya742 Shourya742 left a 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.

Comment on lines +16 to +26
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()
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants