OxL Reference

method Table.count

The number of rows of the table.

Example:

oxl✓ checked in CI
use std.orm { Db }

@table("items")
data Item {
  @pk id: i64
  name: str
  price: i64
}

fn main() io, db {
  let db = Db.open("sqlite::memory:")!
  db.Item.insert(Item{ id: 1, name: "tea", price: 3 })
  print("{db.Item.count()}")
  db.close()
}
Output
1

Example:

oxl✓ checked in CI
use std.orm { Db }

@table("items")
data Item {
  @pk id: i64
  name: str
  price: i64
}

fn main() io, db {
  let db = Db.open("sqlite::memory:")!
  db.insert(Item{ id: 1, name: "tea", price: 3 })
  db.insert(Item{ id: 2, name: "cake", price: 9 })
  print("{db.Item.query().take(1).count()}")
  db.close()
}
Output
2
pub(api) fn count() -> i64  db

Complexity. O(1) to O(rows) in the database.

Since. 1.0.0-beta

Returns

i64

Effects

db

Defined in: std/orm/orm.oxl:1197

See also