Skip to content

Commit

Permalink
Add doc test
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Oct 4, 2024
1 parent 0ac71eb commit eb062e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/backend/postgres/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ impl QueryBuilder for PostgresQueryBuilder {
fn prepare_simple_expr(&self, simple_expr: &SimpleExpr, sql: &mut dyn SqlWriter) {
match simple_expr {
SimpleExpr::AsEnum(type_name, expr) => {
let simple_expr = expr.clone().cast_as_quoted(SeaRc::clone(type_name), self.quote());
let simple_expr = expr
.clone()
.cast_as_quoted(SeaRc::clone(type_name), self.quote());
self.prepare_simple_expr_common(&simple_expr, sql);
}
_ => QueryBuilder::prepare_simple_expr_common(self, simple_expr, sql),
Expand Down
15 changes: 15 additions & 0 deletions src/extension/postgres/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,21 @@ impl TypeAlterStatement {
self
}

/// Add a enum value if not already exists
///
/// ```
/// use sea_query::{extension::postgres::Type, tests_cfg::*, *};
///
/// assert_eq!(
/// Type::alter()
/// .name(Font::Table)
/// .add_value(Alias::new("weight"))
/// .if_not_exists()
/// .after(Font::Variant)
/// .to_string(PostgresQueryBuilder),
/// r#"ALTER TYPE "font" ADD VALUE IF NOT EXISTS 'weight' AFTER 'variant'"#
/// )
/// ```
pub fn if_not_exists(mut self) -> Self {
if let Some(option) = self.option {
self.option = Some(option.if_not_exists());
Expand Down
6 changes: 2 additions & 4 deletions src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,8 @@ impl Func {
let expr: SimpleExpr = expr.into();
let mut quoted_type = String::new();
iden.into_iden().prepare(&mut quoted_type, q);
FunctionCall::new(Function::Cast).arg(expr.binary(
BinOper::As,
Expr::cust(quoted_type.as_str()),
))
FunctionCall::new(Function::Cast)
.arg(expr.binary(BinOper::As, Expr::cust(quoted_type.as_str())))
}

/// Call `COALESCE` function.
Expand Down

0 comments on commit eb062e2

Please sign in to comment.