diff --git a/src/db.rs b/src/db.rs index 65b6a01..537f6d2 100644 --- a/src/db.rs +++ b/src/db.rs @@ -436,6 +436,22 @@ impl DBWithThreadMode { Self::open_cf_descriptors_internal(opts, path, cfs, &AccessType::ReadWrite) } + /// Opens a database with the given database options and column family names. + /// + /// Column families opened using given `Options`. + pub fn open_cf_with_opts(opts: &Options, path: P, cfs: I) -> Result + where + P: AsRef, + I: IntoIterator, + N: AsRef, + { + let cfs = cfs + .into_iter() + .map(|(name, opts)| ColumnFamilyDescriptor::new(name.as_ref(), opts)); + + Self::open_cf_descriptors(opts, path, cfs) + } + /// Opens a database for read only with the given database options and column family names. pub fn open_cf_for_read_only( opts: &Options, diff --git a/tests/test_column_family.rs b/tests/test_column_family.rs index fc71bed..e0fb0f4 100644 --- a/tests/test_column_family.rs +++ b/tests/test_column_family.rs @@ -156,6 +156,31 @@ fn test_create_missing_column_family() { } } +#[test] +fn test_open_column_family_with_opts() { + let n = DBPath::new("_rust_rocksdb_open_cf_with_opts"); + + { + let mut opts = Options::default(); + opts.create_if_missing(true); + opts.create_missing_column_families(true); + + // We can use different parameters for different column family. + let mut cf1_opts = Options::default(); + cf1_opts.set_min_write_buffer_number(2); + cf1_opts.set_min_write_buffer_number_to_merge(4); + let mut cf2_opts = Options::default(); + cf2_opts.set_min_write_buffer_number(5); + cf2_opts.set_min_write_buffer_number_to_merge(10); + + let cfs = vec![("cf1", cf1_opts), ("cf2", cf2_opts)]; + match DB::open_cf_with_opts(&opts, &n, cfs) { + Ok(_db) => println!("successfully opened column family with the specified options"), + Err(e) => panic!("failed to open cf with options: {}", e), + } + } +} + #[test] #[ignore] fn test_merge_operator() {