Skip to content

Commit

Permalink
schema tests + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Jun 20, 2016
1 parent a56e312 commit 129fe21
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 396 deletions.
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ let package = Package(
.Package(url: "https://github.com/open-swift/C7.git", majorVersion: 0, minor: 9),

// Syntax for easily accessing values from generic data.
.Package(url: "https://github.com/qutheory/polymorphic.git", majorVersion: 0, minor: 2)
.Package(url: "https://github.com/qutheory/polymorphic.git", majorVersion: 0, minor: 2),

// Syntax for easily indexing arrays and dictionaries.
.Package(url: "https://github.com/qutheory/path-indexable.git", majorVersion: 0, minor: 2)
]
)
292 changes: 0 additions & 292 deletions Sources/Fluent/Helper/oldsql.swift

This file was deleted.

7 changes: 7 additions & 0 deletions Sources/Fluent/Preparation/Database+Preparation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ extension Database {
try migration.save()
}
}

extension Preparation {
public static var name: String {
let type = "\(self.dynamicType)"
return type.components(separatedBy: ".Type").first ?? type
}
}
9 changes: 9 additions & 0 deletions Sources/Fluent/Preparation/Model+Preparation.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// MARK: Preparation

extension Model {
/**
Automates the preparation of a model.
*/
public static func prepare(database: Database) throws {
try database.create(entity) { builder in
let model = self.init()
Expand Down Expand Up @@ -29,6 +32,9 @@ extension Model {
}
}

/**
Automates reverting the model's preparation.
*/
public static func revert(database: Database) throws {
try database.delete(entity)
}
Expand All @@ -41,6 +47,9 @@ extension Model {
self.init(serialized: [:])
}

/**
Automates the serialization of a model.
*/
public func serialize() -> [String: Value?] {
var serialized: [String: Value?] = [:]

Expand Down
16 changes: 16 additions & 0 deletions Sources/Fluent/Preparation/Preparation.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
/**
A preparation prepares the database for
any task that it may need to perform during runtime.
*/
public protocol Preparation {
/**
The prepare method should call any methods
it needs on the database to prepare.
*/
static func prepare(database: Database) throws

/**
The revert method should undo any actions
caused by the prepare method.
If this is impossible, the `PreparationError.revertImpossible`
error should be thrown.
*/
static func revert(database: Database) throws
}
Loading

0 comments on commit 129fe21

Please sign in to comment.