Skip to content

Commit

Permalink
Merge pull request #45 from qutheory/preview
Browse files Browse the repository at this point in the history
updating to swift preview release
  • Loading branch information
tanner0101 committed Jun 1, 2016
2 parents 23d2ad8 + eb2285b commit 29658ba
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DEVELOPMENT-SNAPSHOT-2016-05-03-a
3.0-preview-1-SNAPSHOT-2016-05-31-a
7 changes: 2 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import PackageDescription

let package = Package(
name: "Fluent",
dependencies: [
.Package(url: "https://github.com/qutheory/libc.git", majorVersion: 0, minor: 1),
]
)
name: "Fluent"
)
18 changes: 10 additions & 8 deletions Sources/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class Query<T: Model> {
Returns an array of entities.
*/
// @discardableResult
func run() throws -> [T] {
var models: [T] = []

Expand Down Expand Up @@ -116,18 +117,16 @@ public class Query<T: Model> {
Attempts to save a supplied entity
and updates its identifier if successful.
*/
public func save(_ model: inout T) throws -> T {
public func save(_ model: inout T) throws {
let data = model.serialize()

if let id = model.id {
filter(database.driver.idKey, .equals, id)
let _ = filter(database.driver.idKey, .equals, id) // discardableResult
try update(data)
} else {
let new = try create(data)
model.id = new?.id
}

return model
}

//MARK: Delete
Expand All @@ -138,7 +137,7 @@ public class Query<T: Model> {
*/
public func delete() throws {
action = .delete
try run()
let _ = try run() // discardableResult
}

/**
Expand All @@ -153,8 +152,8 @@ public class Query<T: Model> {

let filter = Filter.compare(database.driver.idKey, .equals, id)
filters.append(filter)
try run()

let _ = try run() // discardableResult
}

//MARK: Update
Expand All @@ -166,7 +165,7 @@ public class Query<T: Model> {
public func update(_ serialized: [String: Value?]) throws {
action = .update
data = serialized
try run()
let _ = try run() // discardableResult
}


Expand All @@ -179,6 +178,7 @@ public class Query<T: Model> {
Used for filtering results based on how
a result's value compares to the supplied value.
*/
// @discardableResult
public func filter(_ field: String, _ comparison: Filter.Comparison, _ value: Value) -> Self {
let filter = Filter.compare(field, comparison, value)
filters.append(filter)
Expand All @@ -192,6 +192,7 @@ public class Query<T: Model> {
Used for filtering results based on whether
a result's value is or is not in a set.
*/
// @discardableResult
public func filter(_ field: String, _ scope: Filter.Scope, _ set: [Value]) -> Self {
let filter = Filter.subset(field, scope, set)
filters.append(filter)
Expand All @@ -202,6 +203,7 @@ public class Query<T: Model> {
/**
Shortcut for creating a `.equals` filter.
*/
// @discardableResult
public func filter(_ field: String, _ value: Value) -> Self {
return filter(field, .equals, value)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fluent/ModelFindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ModelFindTests: XCTestCase {
}
}

static var allTests : [(String, ModelFindTests -> () throws -> Void)] {
static var allTests : [(String, (ModelFindTests) -> () throws -> Void)] {
return [
("testFindFailing", testFindFailing),
("testFindSucceeding", testFindSucceeding),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fluent/QueryFiltersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QueryFiltersTests: XCTestCase {
}
}

static var allTests : [(String, QueryFiltersTests -> () throws -> Void)] {
static var allTests : [(String, (QueryFiltersTests) -> () throws -> Void)] {
return [
("testBasalQuery", testBasalQuery),
("testBasicQuery", testBasicQuery),
Expand Down

0 comments on commit 29658ba

Please sign in to comment.