forked from manyuanrong/sql-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fea9ac
commit 3e1e79c
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |