Skip to content

Commit

Permalink
Use check
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Oct 1, 2024
1 parent cfa7617 commit a992bc0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions database/src/sqlite_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,27 @@ impl SqliteBackend {
ColumnDef::new(MessageIden::Mailbox)
.string()
.not_null()
.extra(String::from("CHECK (LENGTH(mailbox) > 0)")),
.check(Expr::expr(Func::char_length(Expr::col(MessageIden::Mailbox))).gt(0)),
)
.col(
ColumnDef::new(MessageIden::Content)
.string()
.not_null()
.extra(String::from("CHECK (LENGTH(content) > 0)")),
.check(Expr::expr(Func::char_length(Expr::col(MessageIden::Content))).gt(0)),
)
.col(
ColumnDef::new(MessageIden::State)
.integer()
.not_null()
.default(Value::Int(Some(0)))
.extra(String::from("CHECK (state >= 0 AND state <= 2)")),
.check(
Expr::col(MessageIden::State)
.gte(0)
.and(Expr::col(MessageIden::State).lte(2)),
),
)
.build(SqliteQueryBuilder);
println!("{sql}");
query(&sql)
.execute(&self.pool)
.await
Expand Down

0 comments on commit a992bc0

Please sign in to comment.