Skip to content

Commit

Permalink
node 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Jul 29, 2016
1 parent e59d11d commit c6396db
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
)

4 changes: 2 additions & 2 deletions Sources/Fluent/Preparation/Migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
Expand Down
4 changes: 2 additions & 2 deletions Sources/Fluent/Query/Join.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fluent/Query/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Query<T: Entity>: 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]
}
Expand Down
62 changes: 31 additions & 31 deletions Sources/Fluent/Utilities/Fluent+Node.swift
Original file line number Diff line number Diff line change
@@ -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<N: NodeInitializable>(_ key: PathIndex) throws -> N {
guard let node = self[key] else {
throw ExtractionError.unexpectedNil
}

return try N(with: node)
}


public func extract<N: NodeInitializable>(_ 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<N: NodeInitializable>(_ key: PathIndex) throws -> N {
// guard let node = self[key] else {
// throw ExtractionError.unexpectedNil
// }
//
// return try N(: node)
// }
//
//
// public func extract<N: NodeInitializable>(_ key: PathIndex) throws -> [N] {
// guard let node = self[key]?.nodeArray else {
// throw ExtractionError.unexpectedNil
// }
//
// return try [N](with: node)
// }
//}
2 changes: 1 addition & 1 deletion Tests/Fluent/ModelFindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ModelFindTests: XCTestCase {
return .null
}

init(with node: Node, in context: Context) throws {
init(node: Node, in context: Context) throws {

}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Fluent/PreparationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fluent/QueryFiltersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class QueryFiltersTests: XCTestCase {
return .null
}

init(with node: Node, in context: Context) throws {
init(node: Node, in context: Context) throws {

}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Fluent/RelationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fluent/Utilities/Atom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fluent/Utilities/Compound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fluent/Utilities/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fluent/Utilities/Nucleus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fluent/Utilities/Proton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fluent/Utilities/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c6396db

Please sign in to comment.