diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a63719..4c91e88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [Unreleased] + +* Export the `DEFAULT_COLUMN_FAMILY_NAME` constant. + ## 0.14.0 (2020-04-22) * Updated lz4 to v1.9.2 (ordian) diff --git a/src/column_family.rs b/src/column_family.rs index 62665f9..2c1b505 100644 --- a/src/column_family.rs +++ b/src/column_family.rs @@ -14,6 +14,12 @@ use crate::{ffi, Options}; +/// The name of the default column family. +/// +/// The column family with this name is created implicitly whenever column +/// families are used. +pub const DEFAULT_COLUMN_FAMILY_NAME: &str = "default"; + /// A descriptor for a RocksDB column family. /// /// A description of the column family, containing the name and `Options`. diff --git a/src/db.rs b/src/db.rs index c76df63..9499fba 100644 --- a/src/db.rs +++ b/src/db.rs @@ -18,7 +18,7 @@ use crate::{ ffi_util::{opt_bytes_to_ptr, to_cpath}, ColumnFamily, ColumnFamilyDescriptor, DBIterator, DBPinnableSlice, DBRawIterator, DBWALIterator, Direction, Error, FlushOptions, IngestExternalFileOptions, IteratorMode, - Options, ReadOptions, Snapshot, WriteBatch, WriteOptions, + Options, ReadOptions, Snapshot, WriteBatch, WriteOptions, DEFAULT_COLUMN_FAMILY_NAME, }; use libc::{self, c_char, c_int, c_uchar, c_void, size_t}; @@ -216,9 +216,9 @@ impl DB { } else { let mut cfs_v = cfs; // Always open the default column family. - if !cfs_v.iter().any(|cf| cf.name == "default") { + if !cfs_v.iter().any(|cf| cf.name == DEFAULT_COLUMN_FAMILY_NAME) { cfs_v.push(ColumnFamilyDescriptor { - name: String::from("default"), + name: String::from(DEFAULT_COLUMN_FAMILY_NAME), options: Options::default(), }); } diff --git a/src/lib.rs b/src/lib.rs index 1161997..f4e2ce5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,7 +90,7 @@ mod sst_file_writer; mod write_batch; pub use crate::{ - column_family::{ColumnFamily, ColumnFamilyDescriptor}, + column_family::{ColumnFamily, ColumnFamilyDescriptor, DEFAULT_COLUMN_FAMILY_NAME}, compaction_filter::Decision as CompactionDecision, db::DB, db_iterator::{DBIterator, DBRawIterator, DBWALIterator, Direction, IteratorMode}, diff --git a/tests/test_column_family.rs b/tests/test_column_family.rs index feaaacd..fc9e9b2 100644 --- a/tests/test_column_family.rs +++ b/tests/test_column_family.rs @@ -14,7 +14,7 @@ mod util; -use rocksdb::{ColumnFamilyDescriptor, MergeOperands, Options, DB}; +use rocksdb::{ColumnFamilyDescriptor, MergeOperands, Options, DB, DEFAULT_COLUMN_FAMILY_NAME}; use util::DBPath; #[test] @@ -68,7 +68,7 @@ fn test_column_family() { let opts = Options::default(); let vec = DB::list_cf(&opts, &n); match vec { - Ok(vec) => assert_eq!(vec, vec!["default", "cf1"]), + Ok(vec) => assert_eq!(vec, vec![DEFAULT_COLUMN_FAMILY_NAME, "cf1"]), Err(e) => panic!("failed to drop column family: {}", e), } }