Skip to content

Commit

Permalink
add Order helper
Browse files Browse the repository at this point in the history
  • Loading branch information
manyuanrong committed Jun 14, 2019
1 parent 1fea9ac commit 3e1e79c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Order

### `Order.by(fieldName: string).desc`

DESC, In reverse order according to `"fieldName"`

### `Order.by(fieldName: string).asc`

ASC, In ascending order according to `"fieldName"`
18 changes: 18 additions & 0 deletions order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { replaceParams } from "./util.ts";

export class Order {
value: string;
static by(field: string) {
const order = new Order();
return {
get desc() {
order.value = replaceParams("?? DESC", [field]);
return order;
},
get asc() {
order.value = replaceParams("?? ASC", [field]);
return order;
}
};
}
}
7 changes: 7 additions & 0 deletions test/order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { assertEquals, test } from "../deps.ts";
import { Order } from "../order.ts";

test(function testOrderBuilder() {
assertEquals(Order.by("name").desc.value, "`name` DESC");
assertEquals(Order.by("name").asc.value, "`name` ASC");
});

0 comments on commit 3e1e79c

Please sign in to comment.