Skip to content

Commit

Permalink
Merge pull request #656 from vapor/tn-operator-fix
Browse files Browse the repository at this point in the history
Export Custom Operators
  • Loading branch information
tanner0101 authored Feb 5, 2020
2 parents 8dede23 + 25584a1 commit 74c64be
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/Fluent/Exports.swift
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 !~=
58 changes: 58 additions & 0 deletions Tests/FluentTests/FluentOperatorTests.swift
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()
}
}

0 comments on commit 74c64be

Please sign in to comment.