Skip to content

Commit

Permalink
Merge pull request #39 from qutheory/refactor
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
tanner0101 committed May 18, 2016
2 parents b8296fc + a6ffc31 commit a90d0e9
Show file tree
Hide file tree
Showing 42 changed files with 1,131 additions and 1,082 deletions.
51 changes: 51 additions & 0 deletions ISSUE_TEMPLATE.md
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.
14 changes: 2 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ import PackageDescription

let package = Package(
name: "Fluent",
dependencies: [],
targets: [
Target(
name: "Fluent",
dependencies: [
.Target(name: "libc")
]),
Target(
name: "FluentDev",
dependencies: [
.Target(name: "Fluent")
])
dependencies: [
.Package(url: "https://github.com/qutheory/libc.git", majorVersion: 0, minor: 1),
]
)
11 changes: 11 additions & 0 deletions Sources/Action.swift
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
}
33 changes: 33 additions & 0 deletions Sources/Comparison.swift
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 "!="
}
}
}
32 changes: 32 additions & 0 deletions Sources/Database.swift
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())
}
24 changes: 24 additions & 0 deletions Sources/Driver.swift
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]]
}
22 changes: 22 additions & 0 deletions Sources/Filter.swift
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)"
}
}
}
39 changes: 0 additions & 39 deletions Sources/Fluent/Action.swift

This file was deleted.

20 changes: 0 additions & 20 deletions Sources/Fluent/Comparison.swift

This file was deleted.

4 changes: 0 additions & 4 deletions Sources/Fluent/Database.swift

This file was deleted.

4 changes: 0 additions & 4 deletions Sources/Fluent/Driver.swift

This file was deleted.

14 changes: 0 additions & 14 deletions Sources/Fluent/Entity.swift

This file was deleted.

16 changes: 0 additions & 16 deletions Sources/Fluent/Error.swift

This file was deleted.

19 changes: 0 additions & 19 deletions Sources/Fluent/Filter.swift

This file was deleted.

16 changes: 0 additions & 16 deletions Sources/Fluent/Helper.swift

This file was deleted.

16 changes: 0 additions & 16 deletions Sources/Fluent/Join.swift

This file was deleted.

Loading

0 comments on commit a90d0e9

Please sign in to comment.