MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / num_items

Method num_items

src/executor/paginator.rs:68–92  ·  view source on GitHub ↗

Get the total number of items

(&self)

Source from the content-addressed store, hash-verified

66
67 /// Get the total number of items
68 pub async fn num_items(&self) -> Result<u64, DbErr> {
69 let builder = self.db.get_database_backend();
70 let stmt = SelectStatement::new()
71 .expr(Expr::cust("COUNT(*) AS num_items"))
72 .from_subquery(
73 self.query
74 .clone()
75 .reset_limit()
76 .reset_offset()
77 .clear_order_by()
78 .to_owned(),
79 "sub_query",
80 )
81 .to_owned();
82 let stmt = builder.build(&stmt);
83 let result = match self.db.query_one(stmt).await? {
84 Some(res) => res,
85 None => return Ok(0),
86 };
87 let num_items = match builder {
88 DbBackend::Postgres => result.try_get::<i64>("", "num_items")? as u64,
89 _ => result.try_get::<i32>("", "num_items")? as u64,
90 };
91 Ok(num_items)
92 }
93
94 /// Get the total number of pages
95 pub async fn num_pages(&self) -> Result<u64, DbErr> {

Callers 3

num_pagesMethod · 0.80
num_items_and_pagesMethod · 0.80
countMethod · 0.80

Calls 5

exprMethod · 0.80
newFunction · 0.50
get_database_backendMethod · 0.45
buildMethod · 0.45
query_oneMethod · 0.45

Tested by

no test coverage detected