Skip to content

Commit 7ea0fb5

Browse files
committed
info
1 parent a91c178 commit 7ea0fb5

File tree

3 files changed

+106
-7
lines changed

3 files changed

+106
-7
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Ryan Carver
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# swift-elasticsearch-query-builder
2+
3+
Status: Experimental / In Progress
4+
5+
A simple DSL to make it easier to construct Elasticsearch queries in Swift.
6+
7+
## Goals
8+
9+
* Builder Syntax supporting conditionals and loops
10+
* Simple typing system for scalar values
11+
* Doesn't try to define the whole syntax language, just enough to provide structure.
12+
13+
## Examples
14+
15+
Static
16+
17+
```swift
18+
@ElasticsearchQueryBuilder
19+
func build() -> some esb.QueryDSL {
20+
esb.Query {
21+
esb.Bool {
22+
esb.Key("match_bool_prefix") {
23+
[
24+
"message": "quick brown f"
25+
]
26+
}
27+
}
28+
}
29+
esb.Pagination.init(size: 20)
30+
}
31+
```
32+
33+
Conditionals
34+
35+
```swift
36+
@ElasticsearchQueryBuilder
37+
func build(message: String?) -> some esb.QueryDSL {
38+
esb.Query {
39+
esb.Bool {
40+
if let message {
41+
esb.Key("match") {
42+
[
43+
"message": .string(message)
44+
]
45+
}
46+
}
47+
}
48+
}
49+
}
50+
```
51+
52+
Loops
53+
54+
```swift
55+
@ElasticsearchQueryBuilder
56+
func build(messages: [String]) -> some esb.QueryDSL {
57+
esb.Query {
58+
esb.Bool {
59+
esb.Should {
60+
for message in messages {
61+
esb.Key("match") {
62+
[
63+
"message": .string(message)
64+
]
65+
}
66+
}
67+
}
68+
}
69+
}
70+
}
71+
```
72+
73+
## License
74+
75+
This library is released under the MIT license. See LICENSE for details.

Tests/ElasticsearchQueryBuilderTests/ComponentTests.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ final class KeyTests: XCTestCase {
4545

4646
final class QueryTests: XCTestCase {
4747
func testBuild() throws {
48-
@ElasticsearchQueryBuilder func build() -> some esb.QueryDSL {
49-
esb.Query {
50-
esb.Key("match_bool_prefix") {
51-
[
52-
"message": "quick brown f"
53-
]
54-
}
48+
@ElasticsearchQueryBuilder func build() -> some esb.QueryDSL {
49+
esb.Query {
50+
esb.Bool {
51+
esb.Key("match_bool_prefix") {
52+
[
53+
"message": "quick brown f"
54+
]
5555
}
5656
}
57+
}
58+
esb.Pagination.init(size: 20)
59+
}
5760
XCTAssertNoDifference(build().makeQuery(), [
5861
"query": [
5962
"match_bool_prefix": [

0 commit comments

Comments
 (0)