From 6478c6478bb3c4af151d674cd9fcaf8b48aea54d Mon Sep 17 00:00:00 2001 From: jinmao88 <50581550+jinmao88@users.noreply.github.com> Date: Mon, 20 Nov 2023 03:41:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8config=E4=B8=ADdataba?= =?UTF-8?q?se=E9=85=8D=E7=BD=AE=E9=A1=B9=E4=B8=8D=E5=A1=AB=E5=86=99namespa?= =?UTF-8?q?ce=E5=8F=82=E6=95=B0=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8Cnamespace=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E4=B8=8D=E6=8B=BC=E6=8E=A5model=5Fname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zino-core/src/orm/mod.rs | 3 +-- zino-core/src/orm/schema.rs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/zino-core/src/orm/mod.rs b/zino-core/src/orm/mod.rs index ac68d719..2ed6b10f 100644 --- a/zino-core/src/orm/mod.rs +++ b/zino-core/src/orm/mod.rs @@ -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() }); diff --git a/zino-core/src/orm/schema.rs b/zino-core/src/orm/schema.rs index 7f04c4b7..199e5f74 100644 --- a/zino-core/src/orm/schema.rs +++ b/zino-core/src/orm/schema.rs @@ -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() + } }) }