Skip to content

Commit

Permalink
Impl current timestamp/date/time for expr
Browse files Browse the repository at this point in the history
  • Loading branch information
oldani committed Nov 5, 2024
1 parent 4c525ee commit 53181b2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sea-query"
version = "0.2.4"
version = "0.2.5"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
6 changes: 6 additions & 0 deletions python/sea_query/_internal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class Expr:
def count_distinct(self) -> SimpleExpr: ...
def if_null(self, value: ValueType) -> SimpleExpr: ...
@staticmethod
def current_timestamp() -> Expr: ...
@staticmethod
def current_date() -> Expr: ...
@staticmethod
def current_time() -> Expr: ...
@staticmethod
def exists(query: SelectStatement) -> SimpleExpr: ...
@staticmethod
def case() -> CaseStatement: ...
Expand Down
15 changes: 15 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ impl Expr {
SimpleExpr(self.take().if_null(&value))
}

#[staticmethod]
fn current_timestamp() -> Expr {
Expr(Some(SeaExpr::current_timestamp()))
}

#[staticmethod]
fn current_date() -> Expr {
Expr(Some(SeaExpr::current_date()))
}

#[staticmethod]
fn current_time() -> Expr {
Expr(Some(SeaExpr::current_time()))
}

#[staticmethod]
fn exists(query: SelectStatement) -> SimpleExpr {
SimpleExpr(SeaExpr::exists(query.0))
Expand Down
12 changes: 12 additions & 0 deletions tests/test_table_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,18 @@ def test_col_auto_increment():
"\"created_at\" timestamp without time zone DEFAULT 'now()'",
),
(Column("data").json().default(Expr.value("{}")), "\"data\" json DEFAULT '{}'"),
(
Column("datetime").timestamp().default(Expr.current_timestamp()),
'"datetime" timestamp DEFAULT CURRENT_TIMESTAMP',
),
(
Column("date").date().default(Expr.current_date()),
'"date" date DEFAULT CURRENT_DATE',
),
(
Column("time").time().default(Expr.current_time()),
'"time" time DEFAULT CURRENT_TIME',
),
],
)
def test_col_default(column, expected):
Expand Down

0 comments on commit 53181b2

Please sign in to comment.