-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #656 from vapor/tn-operator-fix
Export Custom Operators
- Loading branch information
Showing
2 changed files
with
64 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 |
---|---|---|
@@ -1 +1,7 @@ | ||
@_exported import FluentKit | ||
|
||
infix operator ~~ | ||
infix operator =~ | ||
infix operator !~ | ||
infix operator !=~ | ||
infix operator !~= |
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,58 @@ | ||
import Fluent | ||
import Vapor | ||
import XCTVapor | ||
|
||
final class FluentOperatorTests: XCTestCase { | ||
func testCustomOperators() throws { | ||
let db = DummyDatabase() | ||
|
||
// name contains string anywhere, prefix, suffix | ||
_ = Planet.query(on: db) | ||
.filter(\.$name ~~ "art") | ||
_ = Planet.query(on: db) | ||
.filter(\.$name =~ "art") | ||
_ = Planet.query(on: db) | ||
.filter(\.$name ~= "art") | ||
// name doesn't contain string anywhere, prefix, suffix | ||
_ = Planet.query(on: db) | ||
.filter(\.$name !~ "art") | ||
_ = Planet.query(on: db) | ||
.filter(\.$name !=~ "art") | ||
_ = Planet.query(on: db) | ||
.filter(\.$name !~= "art") | ||
|
||
// name in array | ||
_ = Planet.query(on: db) | ||
.filter(\.$name ~~ ["Earth", "Mars"]) | ||
// name not in array | ||
_ = Planet.query(on: db) | ||
.filter(\.$name !~ ["Earth", "Mars"]) | ||
} | ||
} | ||
private final class Planet: Model { | ||
static let schema = "planets" | ||
|
||
@ID(key: "id") | ||
var id: Int? | ||
|
||
@Field(key: "name") | ||
var name: String | ||
} | ||
|
||
private struct DummyDatabase: Database { | ||
var context: DatabaseContext { | ||
fatalError() | ||
} | ||
|
||
func execute(query: DatabaseQuery, onRow: @escaping (DatabaseRow) -> ()) -> EventLoopFuture<Void> { | ||
fatalError() | ||
} | ||
|
||
func execute(schema: DatabaseSchema) -> EventLoopFuture<Void> { | ||
fatalError() | ||
} | ||
|
||
func withConnection<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> { | ||
fatalError() | ||
} | ||
} |