Skip to content

Commit

Permalink
feat: 允许config中database配置项不填写namespace参数,默认为空字符串,namespace为空不拼接model_…
Browse files Browse the repository at this point in the history
…name
  • Loading branch information
jinmao88 committed Nov 19, 2023
1 parent ccf74db commit 6478c64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 1 addition & 2 deletions zino-core/src/orm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ static NAMESPACE_PREFIX: LazyLock<&'static str> = LazyLock::new(|| {
let max_rows = config.get_usize("max-rows").unwrap_or(10000);
MAX_ROWS.store(max_rows, Relaxed);
config
.get_str("namespace")
.expect("the `namespace` field should be a str")
.get_str("namespace").unwrap_or("")
.to_case(Case::Snake)
.leak()
});
Expand Down
20 changes: 14 additions & 6 deletions zino-core/src/orm/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,26 @@ pub trait Schema: 'static + Send + Sync + ModelHooks {
/// Returns the model namespace.
#[inline]
fn model_namespace() -> &'static str {
[*super::NAMESPACE_PREFIX, Self::MODEL_NAME]
.join(":")
.leak()
if super::NAMESPACE_PREFIX.is_empty() {
Self::MODEL_NAME
} else {
[*super::NAMESPACE_PREFIX, Self::MODEL_NAME]
.join(":")
.leak()
}
}

/// Returns the table name.
#[inline]
fn table_name() -> &'static str {
Self::TABLE_NAME.unwrap_or_else(|| {
[*super::NAMESPACE_PREFIX, Self::MODEL_NAME]
.join("_")
.leak()
if super::NAMESPACE_PREFIX.is_empty() {
Self::MODEL_NAME
} else {
[*super::NAMESPACE_PREFIX, Self::MODEL_NAME]
.join("_")
.leak()
}
})
}

Expand Down

0 comments on commit 6478c64

Please sign in to comment.