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

feat: 允许config中database配置项不填写namespace参数,默认为空字符串,namespace为空不拼接model_… #62

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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