-
Notifications
You must be signed in to change notification settings - Fork 1
Query from table
The primary key in ONAM for all tables are maintained internally (auto generated, incrementing), you will be able to access them using getId() method, but not overwrite or alter its value.
Methods to fetch data from database. All methods are available in Entity class.
In-order to find a row by its id,
User user = User.find(User.class, 1);
This will return null, if the row doesn't exist.
User user = User.findByUniqueProperty(User.class, "name", "John Doe");
This will return a single row if it exists with value "John Doe" in column "name". Custom column names may be specified for tables using @Column(name = "") annotation. See migration docs on how to implement the same.
To find all rows with value "John Doe" in column "name" without any limit.
List<User> users = User.findByProperty(User.class, "name", "John Doe");
or, Use page index and page size parameters. For example, to return results 11-60 (where result 1 is the first row), use:
List<User> users = User.findByProperty(User.class, "name", "John Doe", 10, 50);
or, Use just limit parameter. For example, to return first 10 results, use:
List<User> users = User.findByProperty(User.class, "name", "John Doe", 10);
To get all rows without any limit.
List<User> users = User.findAll(User.class);
or, Use page index and page size parameters. For example, to return results 11-60 (where result 1 is the first row), use:
List<User> users = User.findByProperty(User.class, 10, 50);
or, Use just limit parameter. For example, to return first 10 results, use:
List<User> users = User.findByProperty(User.class, 10);
Incase, you need to specify a custom where clause.
Use where clause, use:
String nameOfUser = "John Doe";
String whereClause = "name == " + nameOfUser;
List<User> users = User.findByProperty(User.class, whereClause);
or, Use page index and page size parameters. For example, to return results 11-60 (where result 1 is the first row), use:
List<User> users = User.findByProperty(User.class, whereClause, 10, 50);
or, Use just limit parameter. For example, to return first 10 results, use:
List<User> users = User.findByProperty(User.class, whereClause, 10);