Skip to content

Commit

Permalink
Merge branch 'master' into feature/seed-via-fn
Browse files Browse the repository at this point in the history
  • Loading branch information
DenuxPlays authored Dec 8, 2024
2 parents 31376c9 + 6ca216d commit 174d339
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
8 changes: 5 additions & 3 deletions loco-new/base_template/config/development.yaml.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ logger:
# Enable pretty backtrace (sets RUST_BACKTRACE=1)
pretty_backtrace: true
# Log level, options: trace, debug, info, warn or error.
level: debug
level: {{ get_env(name="LOG_LEVEL", default="debug") }}
# Define the logging format. options: compact, pretty or json
format: compact
# By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries
Expand All @@ -17,7 +17,9 @@ logger:
# Web server configuration
server:
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
port: 5150
port: {{ get_env(name="PORT", default="5150") }}
# Binding for the server (which interface to bind to)
binding: {{ get_env(name="BINDING", default="localhost") }}
# The UI hostname or IP address that mailers will point to.
host: http://localhost
# Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block
Expand Down Expand Up @@ -101,7 +103,7 @@ database:
# Database connection URI
uri: {% raw %}{{{% endraw %} get_env(name="DATABASE_URL", default="{{settings.db.endpoint | replace(from='NAME', to=settings.package_name) | replace(from='ENV', to='development')}}") {% raw %}}}{% endraw %}
# When enabled, the sql query will be logged.
enable_logging: false
enable_logging: {{ get_env(name="DB_LOGGING", default="false") }}
# Set the timeout duration when acquiring a connection.
connect_timeout: {% raw %}{{{% endraw %} get_env(name="DB_CONNECT_TIMEOUT", default="500") {% raw %}}}{% endraw %}
# Set the idle duration before closing a connection.
Expand Down
13 changes: 10 additions & 3 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,11 @@ fn fix_entities() -> AppResult<()> {
&new_file,
format!(
r"use sea_orm::entity::prelude::*;
pub use super::_entities::{module}::{{ActiveModel, Entity}};
pub use super::_entities::{module}::{{ActiveModel, Model, Entity}};
pub type {module_pascal} = Entity;
#[async_trait::async_trait]
impl ActiveModelBehavior for ActiveModel {{
// extend activemodel below (keep comment for generators)
async fn before_save<C>(self, _db: &C, insert: bool) -> std::result::Result<Self, DbErr>
where
C: ConnectionTrait,
Expand All @@ -439,6 +437,15 @@ impl ActiveModelBehavior for ActiveModel {{
}}
}}
}}
// implement your read-oriented logic here
impl Model {{}}
// implement your write-oriented logic here
impl ActiveModel {{}}
// implement your custom finders, selectors oriented logic here
impl Entity {{}}
"
),
)?;
Expand Down
19 changes: 19 additions & 0 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,30 @@ pub enum ModelError {

#[error(transparent)]
Any(#[from] Box<dyn std::error::Error + Send + Sync>),

#[error("{0}")]
Message(String),
}

#[allow(clippy::module_name_repetitions)]
pub type ModelResult<T, E = ModelError> = std::result::Result<T, E>;

impl ModelError {
#[must_use]
pub fn wrap(err: impl std::error::Error + Send + Sync + 'static) -> Self {
Self::Any(Box::new(err))
}

#[must_use]
pub fn to_msg(err: impl std::error::Error + Send + Sync + 'static) -> Self {
Self::Message(err.to_string())
}

#[must_use]
pub fn msg(s: &str) -> Self {
Self::Message(s.to_string())
}
}
#[async_trait]
pub trait Authenticable: Clone {
async fn find_by_api_key(db: &DatabaseConnection, api_key: &str) -> ModelResult<Self>;
Expand Down

0 comments on commit 174d339

Please sign in to comment.