Skip to content

Commit 22a01d3

Browse files
committed
feat(sqlite): add getters for SqliteConnectOptions properties
1 parent bab1b02 commit 22a01d3

1 file changed

Lines changed: 177 additions & 5 deletions

File tree

sqlx-sqlite/src/options/mod.rs

Lines changed: 177 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,6 @@ impl SqliteConnectOptions {
225225
self
226226
}
227227

228-
/// Gets the current name of the database file.
229-
pub fn get_filename(&self) -> &Path {
230-
&self.filename
231-
}
232-
233228
/// Set the enforcement of [foreign key constraints](https://www.sqlite.org/pragma.html#pragma_foreign_keys).
234229
///
235230
/// SQLx chooses to enable this by default so that foreign keys function as expected,
@@ -576,3 +571,180 @@ impl SqliteConnectOptions {
576571
self
577572
}
578573
}
574+
575+
impl SqliteConnectOptions {
576+
/// Get the current database filename.
577+
///
578+
/// # Example
579+
///
580+
/// ```rust
581+
/// # use sqlx_sqlite::SqliteConnectOptions;
582+
/// # use std::path::Path;
583+
/// let options = SqliteConnectOptions::new()
584+
/// .filename("data.db");
585+
/// assert_eq!(options.get_filename(), Path::new("data.db"));
586+
/// ```
587+
pub fn get_filename(&self) -> &Path {
588+
&self.filename
589+
}
590+
591+
/// Get whether the in-memory flag is set.
592+
///
593+
/// # Example
594+
///
595+
/// ```rust
596+
/// # use sqlx_sqlite::SqliteConnectOptions;
597+
/// let options = SqliteConnectOptions::new()
598+
/// .in_memory(true);
599+
/// assert!(options.is_in_memory());
600+
/// ```
601+
pub fn is_in_memory(&self) -> bool {
602+
self.in_memory
603+
}
604+
605+
/// Get whether the database is opened in read-only mode.
606+
///
607+
/// # Example
608+
///
609+
/// ```rust
610+
/// # use sqlx_sqlite::SqliteConnectOptions;
611+
/// let options = SqliteConnectOptions::new()
612+
/// .read_only(true);
613+
/// assert!(options.is_read_only());
614+
/// ```
615+
pub fn is_read_only(&self) -> bool {
616+
self.read_only
617+
}
618+
619+
/// Get whether the database file will be created if missing.
620+
///
621+
/// # Example
622+
///
623+
/// ```rust
624+
/// # use sqlx_sqlite::SqliteConnectOptions;
625+
/// let options = SqliteConnectOptions::new()
626+
/// .create_if_missing(true);
627+
/// assert!(options.is_create_if_missing());
628+
/// ```
629+
pub fn is_create_if_missing(&self) -> bool {
630+
self.create_if_missing
631+
}
632+
633+
/// Get whether the shared cache is enabled.
634+
///
635+
/// # Example
636+
///
637+
/// ```rust
638+
/// # use sqlx_sqlite::SqliteConnectOptions;
639+
/// let options = SqliteConnectOptions::new()
640+
/// .shared_cache(true);
641+
/// assert!(options.is_shared_cache());
642+
/// ```
643+
pub fn is_shared_cache(&self) -> bool {
644+
self.shared_cache
645+
}
646+
647+
/// Get the statement cache capacity.
648+
///
649+
/// # Example
650+
///
651+
/// ```rust
652+
/// # use sqlx_sqlite::SqliteConnectOptions;
653+
/// let options = SqliteConnectOptions::new()
654+
/// .statement_cache_capacity(200);
655+
/// assert_eq!(options.get_statement_cache_capacity(), 200);
656+
/// ```
657+
pub fn get_statement_cache_capacity(&self) -> usize {
658+
self.statement_cache_capacity
659+
}
660+
661+
/// Get the busy timeout duration.
662+
///
663+
/// # Example
664+
///
665+
/// ```rust
666+
/// # use sqlx_sqlite::SqliteConnectOptions;
667+
/// # use std::time::Duration;
668+
/// let options = SqliteConnectOptions::new()
669+
/// .busy_timeout(Duration::from_secs(10));
670+
/// assert_eq!(options.get_busy_timeout(), Duration::from_secs(10));
671+
/// ```
672+
pub fn get_busy_timeout(&self) -> Duration {
673+
self.busy_timeout
674+
}
675+
676+
/// Get the log settings.
677+
pub fn get_log_settings(&self) -> &LogSettings {
678+
&self.log_settings
679+
}
680+
681+
/// Get whether the database is set as immutable.
682+
///
683+
/// # Example
684+
///
685+
/// ```rust
686+
/// # use sqlx_sqlite::SqliteConnectOptions;
687+
/// let options = SqliteConnectOptions::new()
688+
/// .immutable(true);
689+
/// assert!(options.is_immutable());
690+
/// ```
691+
pub fn is_immutable(&self) -> bool {
692+
self.immutable
693+
}
694+
695+
/// Get the VFS name.
696+
///
697+
/// # Example
698+
///
699+
/// ```rust
700+
/// # use sqlx_sqlite::SqliteConnectOptions;
701+
/// let options = SqliteConnectOptions::new()
702+
/// .vfs("unix-none");
703+
/// assert_eq!(options.get_vfs(), Some("unix-none"));
704+
/// ```
705+
pub fn get_vfs(&self) -> Option<&str> {
706+
self.vfs.as_deref()
707+
}
708+
709+
/// Get the command channel buffer size.
710+
///
711+
/// # Example
712+
///
713+
/// ```rust
714+
/// # use sqlx_sqlite::SqliteConnectOptions;
715+
/// let options = SqliteConnectOptions::new()
716+
/// .command_buffer_size(100);
717+
/// assert_eq!(options.get_command_channel_size(), 100);
718+
/// ```
719+
pub fn get_command_channel_size(&self) -> usize {
720+
self.command_channel_size
721+
}
722+
723+
/// Get the row channel buffer size.
724+
///
725+
/// # Example
726+
///
727+
/// ```rust
728+
/// # use sqlx_sqlite::SqliteConnectOptions;
729+
/// let options = SqliteConnectOptions::new()
730+
/// .row_buffer_size(100);
731+
/// assert_eq!(options.get_row_channel_size(), 100);
732+
/// ```
733+
pub fn get_row_channel_size(&self) -> usize {
734+
self.row_channel_size
735+
}
736+
737+
/// Get whether serialized threading mode is enabled.
738+
///
739+
/// # Example
740+
///
741+
/// ```rust
742+
/// # use sqlx_sqlite::SqliteConnectOptions;
743+
/// let options = SqliteConnectOptions::new()
744+
/// .serialized(true);
745+
/// assert!(options.is_serialized());
746+
/// ```
747+
pub fn is_serialized(&self) -> bool {
748+
self.serialized
749+
}
750+
}

0 commit comments

Comments
 (0)