diff --git a/Package.swift b/Package.swift index a4ffe9b2..e3e2e007 100644 --- a/Package.swift +++ b/Package.swift @@ -4,7 +4,7 @@ let package = Package( name: "Fluent", dependencies: [ // Data structure for converting between multiple representations - .Package(url: "https://github.com/qutheory/node.git", majorVersion: 0, minor: 2) + .Package(url: "https://github.com/qutheory/node.git", majorVersion: 0, minor: 3) ] ) diff --git a/Sources/Fluent/Preparation/Migration.swift b/Sources/Fluent/Preparation/Migration.swift index 9d8d42fe..a2b23c64 100644 --- a/Sources/Fluent/Preparation/Migration.swift +++ b/Sources/Fluent/Preparation/Migration.swift @@ -8,13 +8,13 @@ final class Migration: Entity { self.name = name } - init(with node: Node, in context: Context) throws { + init(node: Node, in context: Context) throws { id = try node.extract("id") name = try node.extract("name") } func makeNode() throws -> Node { - return try Node([ + return try Node(node: [ "id": id, "name": name ]) diff --git a/Sources/Fluent/Query/Join.swift b/Sources/Fluent/Query/Join.swift index bf6a7ef2..4cc08cb3 100644 --- a/Sources/Fluent/Query/Join.swift +++ b/Sources/Fluent/Query/Join.swift @@ -57,7 +57,7 @@ public final class Pivot< } } - public init(with node: Node, in context: Context) throws { + public init(node: Node, in context: Context) throws { id = try node.extract("id") let firstQ = try First.query() @@ -76,7 +76,7 @@ public final class Pivot< } public func makeNode() throws -> Node { - return try Node([ + return try Node(node: [ "id": id, "\(self.dynamicType.left.name)_id": leftId, "\(self.dynamicType.right.name)_id": rightId, diff --git a/Sources/Fluent/Query/Query.swift b/Sources/Fluent/Query/Query.swift index d0d53516..8ecfd25a 100644 --- a/Sources/Fluent/Query/Query.swift +++ b/Sources/Fluent/Query/Query.swift @@ -90,7 +90,7 @@ public class Query: QueryRepresentable { if case .array(let array) = try raw() { for result in array { do { - var model = try T(with: result) + var model = try T(node: result) if case .object(let dict) = result { model.id = dict[database.driver.idKey] } diff --git a/Sources/Fluent/Utilities/Fluent+Node.swift b/Sources/Fluent/Utilities/Fluent+Node.swift index 76bc4172..bbb65aad 100644 --- a/Sources/Fluent/Utilities/Fluent+Node.swift +++ b/Sources/Fluent/Utilities/Fluent+Node.swift @@ -1,33 +1,33 @@ @_exported import Node -public enum ExtractionError: Error { - case unexpectedNil - case invalidType -} - -extension Node { - public func extract(_ key: PathIndex) throws -> Node { - guard let node = self[key] else { - throw ExtractionError.unexpectedNil - } - - return node - } - - public func extract(_ key: PathIndex) throws -> N { - guard let node = self[key] else { - throw ExtractionError.unexpectedNil - } - - return try N(with: node) - } - - - public func extract(_ key: PathIndex) throws -> [N] { - guard let node = self[key]?.nodeArray else { - throw ExtractionError.unexpectedNil - } - - return try [N](with: node) - } -} +//public enum ExtractionError: Error { +// case unexpectedNil +// case invalidType +//} +// +//extension Node { +// public func extract(_ key: PathIndex) throws -> Node { +// guard let node = self[key] else { +// throw ExtractionError.unexpectedNil +// } +// +// return node +// } +// +// public func extract(_ key: PathIndex) throws -> N { +// guard let node = self[key] else { +// throw ExtractionError.unexpectedNil +// } +// +// return try N(: node) +// } +// +// +// public func extract(_ key: PathIndex) throws -> [N] { +// guard let node = self[key]?.nodeArray else { +// throw ExtractionError.unexpectedNil +// } +// +// return try [N](with: node) +// } +//} diff --git a/Tests/Fluent/ModelFindTests.swift b/Tests/Fluent/ModelFindTests.swift index 2fd6ba57..3953c3c2 100644 --- a/Tests/Fluent/ModelFindTests.swift +++ b/Tests/Fluent/ModelFindTests.swift @@ -15,7 +15,7 @@ class ModelFindTests: XCTestCase { return .null } - init(with node: Node, in context: Context) throws { + init(node: Node, in context: Context) throws { } diff --git a/Tests/Fluent/PreparationTests.swift b/Tests/Fluent/PreparationTests.swift index 08cf9189..3fdc6a63 100644 --- a/Tests/Fluent/PreparationTests.swift +++ b/Tests/Fluent/PreparationTests.swift @@ -107,14 +107,14 @@ final class TestModel: Entity { var name: String var age: Int - init(with node: Node, in context: Context) throws { + init(node: Node, in context: Context) throws { id = try node.extract("id") name = try node.extract("name") age = try node.extract("age") } func makeNode() throws -> Node { - return try Node([ + return try Node(node: [ "id": id, "name": name, "age": age diff --git a/Tests/Fluent/QueryFiltersTests.swift b/Tests/Fluent/QueryFiltersTests.swift index 26c1c99d..4b77f774 100644 --- a/Tests/Fluent/QueryFiltersTests.swift +++ b/Tests/Fluent/QueryFiltersTests.swift @@ -13,7 +13,7 @@ class QueryFiltersTests: XCTestCase { return .null } - init(with node: Node, in context: Context) throws { + init(node: Node, in context: Context) throws { } diff --git a/Tests/Fluent/RelationTests.swift b/Tests/Fluent/RelationTests.swift index 826132be..3d30587c 100644 --- a/Tests/Fluent/RelationTests.swift +++ b/Tests/Fluent/RelationTests.swift @@ -8,7 +8,7 @@ class RelationTests: XCTestCase { ] func testHasMany() throws { - let hydrogen = try Atom([ + let hydrogen = try Atom(node: [ "id": 42, "name": "Hydrogen", "group_id": 1337 @@ -20,7 +20,7 @@ class RelationTests: XCTestCase { } func testBelongsToMany() throws { - let hydrogen = try Atom([ + let hydrogen = try Atom(node: [ "id": 42, "name": "Hydrogen", "group_id": 1337 diff --git a/Tests/Fluent/Utilities/Atom.swift b/Tests/Fluent/Utilities/Atom.swift index d0b959eb..65448f1a 100644 --- a/Tests/Fluent/Utilities/Atom.swift +++ b/Tests/Fluent/Utilities/Atom.swift @@ -10,14 +10,14 @@ final class Atom: Entity { self.name = name } - init(with node: Node, in context: Context) throws { + init(node: Node, in context: Context) throws { id = try node.extract("id") name = try node.extract("name") groupId = try node.extract("group_id") } func makeNode() throws -> Node { - return try Node([ + return try Node(node: [ "id": id, "name": name, "group": try group().get() diff --git a/Tests/Fluent/Utilities/Compound.swift b/Tests/Fluent/Utilities/Compound.swift index ce04553c..caafb0b0 100644 --- a/Tests/Fluent/Utilities/Compound.swift +++ b/Tests/Fluent/Utilities/Compound.swift @@ -4,13 +4,13 @@ final class Compound: Entity { var id: Node? var name: String - init(with node: Node, in context: Context) throws { + init(node: Node, in context: Context) throws { id = try node.extract("id") name = try node.extract("name") } func makeNode() throws -> Node { - return try Node([ + return try Node(node: [ "id": id, "name": name ]) diff --git a/Tests/Fluent/Utilities/Group.swift b/Tests/Fluent/Utilities/Group.swift index 406429cf..a1cf6bd5 100644 --- a/Tests/Fluent/Utilities/Group.swift +++ b/Tests/Fluent/Utilities/Group.swift @@ -2,7 +2,7 @@ import Fluent final class Group: Entity { var id: Node? - init(with node: Node, in context: Context) throws {} + init(node: Node, in context: Context) throws {} func makeNode() -> Node { return .null } static func prepare(_ database: Database) throws {} diff --git a/Tests/Fluent/Utilities/Nucleus.swift b/Tests/Fluent/Utilities/Nucleus.swift index 9b0702f2..c76fc2b3 100644 --- a/Tests/Fluent/Utilities/Nucleus.swift +++ b/Tests/Fluent/Utilities/Nucleus.swift @@ -3,7 +3,7 @@ import Fluent final class Nucleus: Entity { static var entity = "nuclei" var id: Node? - init(with node: Node, in context: Context) throws { } + init(node: Node, in context: Context) throws { } func makeNode() -> Node { return .null } static func prepare(_ database: Database) throws {} diff --git a/Tests/Fluent/Utilities/Proton.swift b/Tests/Fluent/Utilities/Proton.swift index 73282b26..576a65db 100644 --- a/Tests/Fluent/Utilities/Proton.swift +++ b/Tests/Fluent/Utilities/Proton.swift @@ -2,7 +2,7 @@ import Fluent final class Proton: Entity { var id: Node? - init(with node: Node, in context: Context) throws {} + init(node: Node, in context: Context) throws {} func makeNode() -> Node { return .null } static func prepare(_ database: Database) throws {} diff --git a/Tests/Fluent/Utilities/User.swift b/Tests/Fluent/Utilities/User.swift index 71ff0d46..0f08a99f 100644 --- a/Tests/Fluent/Utilities/User.swift +++ b/Tests/Fluent/Utilities/User.swift @@ -12,14 +12,14 @@ final class User: Entity { } func makeNode() throws -> Node { - return try Node([ + return try Node(node: [ "id": id, "name": name, "email": email ]) } - init(with node: Node, in context: Context) throws { + init(node: Node, in context: Context) throws { id = try node.extract("id") name = try node.extract("name") email = try node.extract("email")