-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from qutheory/refactor
refactor
- Loading branch information
Showing
42 changed files
with
1,131 additions
and
1,082 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
🚀 Thanks for contributing! | ||
|
||
Below are templates for various types of issues (Bugs, Security, and Features) separated by horizontal rules. | ||
Please delete whichever sections of the template you do not need. | ||
|
||
# Bugs | ||
|
||
If you find a bug, please submit a pull request with a failing test case displaying the bug or just create an issue with as much information as possible. | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
# Security Issue | ||
|
||
If you find a security vulnerability, please contact [[email protected]]([email protected]) as soon as possible. We take these matters seriously. | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
# Feature, Enhancement, or Optimization | ||
|
||
# Name of Feature | ||
|
||
* Author(s): [Developer](https://github.com/<your-username>) | ||
* Status: **[Awaiting review](#rationale)** | ||
|
||
## Introduction | ||
|
||
A short description of what the feature is. Try to keep it to a single-paragraph "elevator pitch" so the reader understands what problem this proposal is addressing. | ||
|
||
## Motivation | ||
|
||
Describe the problems that this proposal seeks to address. If the problem is that some common pattern is currently hard to express, show how one can currently get a similar effect and describe its drawbacks. If it's completely new functionality that cannot be emulated, motivate why this new functionality would help Fluent be a better framework. | ||
|
||
## Proposed solution | ||
|
||
Describe your solution to the problem. Provide examples and describe how they work. Show how your solution is better than current workarounds: is it cleaner, safer, or more efficient? | ||
|
||
## Code snippets | ||
|
||
Give us an idea of what this new idea will look like in code. The more code snippets you provide here, the easier it will be for the community to understand what your idea is. | ||
|
||
## Impact | ||
|
||
Describe the impact that this change will have on existing code. Will some Fluent applications stop compiling due to this change? Will applications still compile but produce different behavior than they used to? | ||
|
||
## Alternatives considered | ||
|
||
Describe alternative approaches to addressing the same problem, and why you chose this approach instead. | ||
|
||
## Decision (For Moderator Use) | ||
|
||
On **[Date]**, the community decided to **(TBD)** this proposal. When the community makes a decision regarding this proposal, their rationale for the decision will be written here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
The types of actions that can be performed | ||
on database entities, such as fetching, deleting, | ||
creating, and updating. | ||
*/ | ||
public enum Action { | ||
case fetch | ||
case delete | ||
case create | ||
case update | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
extension Filter { | ||
/** | ||
Describes the various operators for | ||
comparing values. | ||
*/ | ||
public enum Comparison { | ||
case equals | ||
case greaterThan | ||
case lessThan | ||
case greaterThanOrEquals | ||
case lessThanOrEquals | ||
case notEquals | ||
} | ||
} | ||
|
||
extension Filter.Comparison: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case .equals: | ||
return "=" | ||
case .greaterThan: | ||
return ">" | ||
case .lessThan: | ||
return "<" | ||
case .greaterThanOrEquals: | ||
return ">=" | ||
case .lessThanOrEquals: | ||
return "<=" | ||
case .notEquals: | ||
return "!=" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
References a database with a single `Driver`. | ||
Statically maps `Model`s to `Database`s. | ||
*/ | ||
public class Database { | ||
/** | ||
The `Driver` powering this database. | ||
Responsible for executing queries. | ||
*/ | ||
public let driver: Driver | ||
|
||
/** | ||
Creates a `Database` with the supplied | ||
`Driver`. This cannot be changed later. | ||
*/ | ||
public init(driver: Driver) { | ||
self.driver = driver | ||
} | ||
|
||
/** | ||
Maps `Model` names to their respective | ||
`Database`. This allows multiple models | ||
in the same application to use different | ||
methods of data persistence. | ||
*/ | ||
public static var map: [String: Database] = [:] | ||
|
||
/** | ||
The default database for all `Model` types. | ||
*/ | ||
public static var `default`: Database = Database(driver: PrintDriver()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
A `Driver` execute queries | ||
and returns an array of results. | ||
It is responsible for interfacing | ||
with the data store powering Fluent. | ||
*/ | ||
public protocol Driver { | ||
/** | ||
The string value for the | ||
default identifier key. | ||
The `idKey` will be used when | ||
`Model.find(_:)` or other find | ||
by identifier methods are used. | ||
*/ | ||
var idKey: String { get } | ||
|
||
/** | ||
Executes a `Query` from and | ||
returns an array of results fetched, | ||
created, or updated by the action. | ||
*/ | ||
func execute<T: Model>(_ query: Query<T>) throws -> [[String: Value]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
Defines a `Filter` that can be | ||
added on fetch, delete, and update | ||
operations to limit the amount of | ||
data affected. | ||
*/ | ||
public enum Filter { | ||
case compare(String, Comparison, Value) | ||
case subset(String, Scope, [Value]) | ||
} | ||
|
||
extension Filter: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case .compare(let field, let comparison, let value): | ||
return "\(field) \(comparison) \(value)" | ||
case .subset(let field, let scope, let values): | ||
let valueDescriptions = values.map { return $0.description } | ||
return "\(field) \(scope) \(valueDescriptions)" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.