Add order/limit support to find queries
This commit is contained in:
parent
b4eeb2c296
commit
153725f785
4 changed files with 91 additions and 18 deletions
|
@ -222,6 +222,45 @@ test(".findAllWhere() returns a row based on basic criteria", () => {
|
|||
expect(manyJacks[2]).toEqual({ user_id: 3, name: "Jack" });
|
||||
});
|
||||
|
||||
test(".findAllWhere() can set a limit on returned rows", () => {
|
||||
const table = makeTestTable();
|
||||
table.insertPartial({ name: "Jack" });
|
||||
table.insertPartial({ name: "Jack" });
|
||||
table.insertPartial({ name: "Jack" });
|
||||
|
||||
const manyJacks = table.findAllWhere({ name: "Jack" }, { limit: 1 });
|
||||
|
||||
expect(manyJacks).toHaveLength(1);
|
||||
expect(manyJacks[0]).toEqual({ user_id: 1, name: "Jack" });
|
||||
});
|
||||
|
||||
test(".findAllWhere() can set an offset on a limit", () => {
|
||||
const table = makeTestTable();
|
||||
table.insertPartial({ name: "Jack" });
|
||||
table.insertPartial({ name: "Jack" });
|
||||
table.insertPartial({ name: "Jack" });
|
||||
|
||||
const manyJacks = table.findAllWhere({ name: "Jack" }, { limit: 1, skip: 1 });
|
||||
|
||||
expect(manyJacks).toHaveLength(1);
|
||||
expect(manyJacks[0]).toEqual({ user_id: 2, name: "Jack" });
|
||||
});
|
||||
|
||||
test(".findAllWhere() can set an order on the results", () => {
|
||||
const table = makeTestTable();
|
||||
table.insertPartial({ name: "Jack" });
|
||||
table.insertPartial({ name: "Jack" });
|
||||
table.insertPartial({ name: "Jack" });
|
||||
|
||||
const manyJacks = table.findAllWhere(
|
||||
{ name: "Jack" },
|
||||
{ order: "user_id DESC" },
|
||||
);
|
||||
|
||||
expect(manyJacks).toHaveLength(3);
|
||||
expect(manyJacks[0]).toEqual({ user_id: 3, name: "Jack" });
|
||||
});
|
||||
|
||||
test(".findOneById() returns a single element by its primary column", () => {
|
||||
const table = makeTestTable();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue