Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Zewo 0.13 #17

Merged
merged 9 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
# Created by https://www.gitignore.io/api/xcode

### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
.build/
build/
DerivedData
Carthage/
Packages/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint
XcodeDevelopment/
*.xcodeproj

.DS_Store
/.build
/Packages
/*.xcodeproj
Build
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DEVELOPMENT-SNAPSHOT-2016-05-09-a
3.0
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ os:
language: generic
sudo: required
dist: trusty
osx_image: xcode7.3
osx_image: xcode8
install:
- eval "$(curl -sL https://raw.githubusercontent.com/Zewo/Zewo/5254525d9da56df29346fd76e99529c22034d61d/Scripts/install-swiftenv.sh)"
- eval "$(curl -sL https://raw.githubusercontent.com/Zewo/Zewo/master/Scripts/Travis/install.sh)"
script:
- swift build --fetch # clones all dependencies
- rm -rf Packages/*/Tests # deletes dependency's tests until duplicate Package.tests issue can be resolved in SPM. At that point, remove.
- swift build -Xlinker -rpath -Xlinker $(pwd)/.build/debug/
- swift build --configuration release -Xlinker -rpath -Xlinker $(pwd)/.build/release/
- swift build
- swift build --configuration release
- swift test
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

The MIT License (MIT)

Copyright (c) 2015 Zewo
Copyright (c) 2016 Zewo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PackageDescription
let package = Package(
name: "SQL",
dependencies: [
.Package(url: "https://github.com/Zewo/String.git", majorVersion: 0, minor: 7),
.Package(url: "https://github.com/Zewo/URI.git", majorVersion: 0, minor: 8),
.Package(url: "https://github.com/Zewo/Core.git", majorVersion: 0, minor: 13)
]
)
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import PackageDescription

let package = Package(
dependencies: [
.Package(url: "https://github.com/Zewo/SQL.git", majorVersion: 0, minor: 5),
.Package(url: "https://github.com/Zewo/SQL.git", majorVersion: 0, minor: 13),
]
)
```
Expand Down Expand Up @@ -68,7 +68,7 @@ public class Artist: Table {
case name = "name"
case artistId = "artist_id"
}

static let tableName: String = "artists"
}
```
Expand All @@ -92,7 +92,7 @@ public final class Artist {
let id: Int?
let name: String
let genre: String

init(name: String, genre: String) {
self.name = name
self.genre = genre
Expand All @@ -106,13 +106,13 @@ extension Artist: Model {
case name = "name"
case genre = "genre"
}

// Specify a table name
static let tableName: String = "artists"

// Specify which field is primary
static var primaryKeyField: Field = .id

// Provide a getter and setter for the primary key
var primaryKey: Int? {
get {
Expand All @@ -122,13 +122,13 @@ extension Artist: Model {
id = newValue
}
}

// Specify the values to be persisted
var serialize: [Field: ValueConvertible?] {
return [.name: name, .genre: genre]
}
// Provide an initializer for the model taking a row

// Provide an initializer for the model taking a row
convenience init(row: Row) throws {
try self.init(
name: row.value(Artist.field(.name)),
Expand Down Expand Up @@ -169,7 +169,7 @@ This project is released under the MIT license. See [LICENSE](LICENSE) for detai

[swift-badge]: https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat
[swift-url]: https://swift.org
[zewo-badge]: https://img.shields.io/badge/Zewo-0.5-FF7565.svg?style=flat
[zewo-badge]: https://img.shields.io/badge/Zewo-0.13-FF7565.svg?style=flat
[zewo-url]: http://zewo.io
[platform-badge]: https://img.shields.io/badge/Platforms-OS%20X%20--%20Linux-lightgray.svg?style=flat
[platform-url]: https://swift.org
Expand All @@ -181,4 +181,4 @@ This project is released under the MIT license. See [LICENSE](LICENSE) for detai
[travis-badge]: https://travis-ci.org/Zewo/SQL.svg?branch=master
[travis-url]: https://travis-ci.org/Zewo/SQL
[codebeat-badge]: https://codebeat.co/badges/13196ddb-e30d-4a6a-bd41-3227cd965b80
[codebeat-url]: https://codebeat.co/projects/github-com-zewo-sql
[codebeat-url]: https://codebeat.co/projects/github-com-zewo-sql
65 changes: 23 additions & 42 deletions Sources/SQL/Core/ConnectionProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
// ConnectionProtocol.swift
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Formbound
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

@_exported import URI
import Core


/**
Expand All @@ -35,25 +11,26 @@ public protocol ConnectionInfoProtocol {
var databaseName: String { get }
var username: String? { get }
var password: String? { get }
init?(uri: URI)

init?(uri: URL)
}

public protocol ConnectionProtocol: class {
associatedtype InternalStatus
associatedtype Result: ResultProtocol
associatedtype Error: ErrorProtocol, CustomStringConvertible
associatedtype ConnectionError: Error, CustomStringConvertible
associatedtype ConnectionInfo: ConnectionInfoProtocol
associatedtype QueryRenderer: QueryRendererProtocol

var connectionInfo: ConnectionInfo { get }

func open() throws

func close()

var internalStatus: InternalStatus { get }


@discardableResult
func execute(_ statement: String, parameters: [Value?]?) throws -> Result

func begin() throws
Expand All @@ -69,13 +46,13 @@ public protocol ConnectionProtocol: class {
func rollbackToSavePointNamed(_ name: String) throws

init(info: ConnectionInfo)
var mostRecentError: Error? { get }

var mostRecentError: ConnectionError? { get }
}

public extension ConnectionProtocol {
public init?(uri: URI) {

public init?(uri: URL) {
guard let info = ConnectionInfo(uri: uri) else {
return nil
}
Expand All @@ -84,7 +61,7 @@ public extension ConnectionProtocol {

public func transaction<T>(handler: (Void) throws -> T) throws -> T {
try begin()

do {
let result = try handler()
try commit()
Expand All @@ -109,31 +86,35 @@ public extension ConnectionProtocol {
throw error
}
}


@discardableResult
func execute(_ statement: String) throws -> Result {
return try execute(statement, parameters: nil)
}

public func execute(_ query: Select) throws -> Result {
return try execute(QueryRenderer.renderStatement(query), parameters: query.sqlParameters)
}


@discardableResult
public func execute(_ query: Update) throws -> Result {
return try execute(QueryRenderer.renderStatement(query), parameters: query.sqlParameters)
}


@discardableResult
public func execute(_ query: Insert, returnInsertedRows: Bool = false) throws -> Result {
return try execute(QueryRenderer.renderStatement(query, forReturningInsertedRows: returnInsertedRows), parameters: query.sqlParameters)
}


@discardableResult
public func execute(_ query: Delete) throws -> Result {
return try execute(QueryRenderer.renderStatement(query), parameters: query.sqlParameters)
}

public func execute(_ statement: String, parameters: [ValueConvertible?]) throws -> Result {
return try execute(statement, parameters: parameters.map { $0?.sqlValue })
}

public func execute(_ statement: String, parameters: ValueConvertible?...) throws -> Result {
return try execute(statement, parameters: parameters)
}
Expand Down
24 changes: 0 additions & 24 deletions Sources/SQL/Core/FieldInfo.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
// FieldInfo.swift
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Formbound
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

public protocol FieldInfoProtocol: CustomStringConvertible {
var name: String { get }
var index: Int { get }
Expand Down
31 changes: 3 additions & 28 deletions Sources/SQL/Core/QualifiedField.swift
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
// QualifiedField.swift
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Formbound
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


public struct QualifiedField {
public let unqualifiedName: String
public var tableName: String?
public var alias: String?

public init(_ name: String, alias: String? = nil) {
let components = name.split(separator: ".")
if components.count == 2, let tableName = components.first, let fieldName = components.last {
Expand All @@ -38,10 +13,10 @@ public struct QualifiedField {
self.unqualifiedName = name
self.tableName = nil
}

self.alias = alias
}

func alias(_ alias: String) -> QualifiedField {
var new = self
new.alias = alias
Expand Down
Loading