Skip to content

Commit

Permalink
Merge pull request #29 from vapor/rc
Browse files Browse the repository at this point in the history
sqlite 3.0 rc
  • Loading branch information
tanner0101 authored Feb 24, 2018
2 parents e6adb92 + 4a998e5 commit 951e4f1
Show file tree
Hide file tree
Showing 40 changed files with 1,640 additions and 641 deletions.
37 changes: 0 additions & 37 deletions .circleci/config.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Sources/main.swift
.build
Packages
Database
*.xcodeproj
Package.pins
Package.resolved
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Qutheory, LLC
Copyright (c) 2018 Qutheory, LLC

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 All @@ -18,4 +18,4 @@ 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.
SOFTWARE.
17 changes: 13 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// swift-tools-version:4.0
import PackageDescription

let package = Package(
name: "SQLite",
targets: [
Target(name: "SQLite", dependencies: ["CSQLite"])
products: [
.library(name: "SQLite", targets: ["SQLite"]),
],
dependencies: [
.Package(url: "https://github.com/vapor/core.git", majorVersion: 2),
.Package(url: "https://github.com/vapor/node.git", majorVersion: 2),
// ⏱ Promises and reactive-streams in Swift built for high-performance and scalability.
.package(url: "https://github.com/vapor/async.git", from: "1.0.0-rc"),

// 🌎 Utility package containing tools for byte manipulation, Codable, OS APIs, and debugging.
.package(url: "https://github.com/vapor/core.git", from: "3.0.0-rc"),
],
targets: [
.target(name: "CSQLite"),
.target(name: "SQLite", dependencies: ["Async", "Bits", "CodableKit", "CSQLite", "Debugging"]),
.testTarget(name: "SQLiteTests", dependencies: ["SQLite"]),
]
)
19 changes: 0 additions & 19 deletions Package@swift-4.swift

This file was deleted.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<p align="center">
<h1>SQLite 3 for Swift</h1>
<img src="https://user-images.githubusercontent.com/1342803/36616582-4deeba86-18b2-11e8-8ed6-dfaba8bd6cba.png" height="64" alt="SQLite">
<br>
<br>
<a href="https://docs.vapor.codes/2.0/core/package/">
<img src="http://img.shields.io/badge/read_the-docs-92A8D1.svg" alt="Documentation">
<a href="http://docs.vapor.codes/3.0/">
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation">
</a>
<a href="http://vapor.team">
<img src="http://vapor.team/badge.svg" alt="Slack Team">
</a>
<a href="LICENSE">
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://circleci.com/gh/vapor/core">
<img src="https://circleci.com/gh/vapor/core.svg?style=shield" alt="Continuous Integration">
<a href="https://circleci.com/gh/vapor/fluent">
<img src="https://circleci.com/gh/vapor/fluent.svg?style=shield" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-3.1-brightgreen.svg" alt="Swift 3.1">
<img src="http://img.shields.io/badge/swift-4.1-brightgreen.svg" alt="Swift 4.1">
</a>
</p>
25 changes: 0 additions & 25 deletions SQLite.podspec

This file was deleted.

99 changes: 99 additions & 0 deletions Sources/SQLite/Data/SQLiteData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import Foundation

/// All possibles cases for SQLite data.
public enum SQLiteData {
case integer(Int)
case float(Double)
case text(String)
case blob(Foundation.Data)
case null
}

extension SQLiteData {
/// Returns an Int if the data is case .integer
public var integer: Int? {
switch self {
case .integer(let int):
return int
default:
return nil
}
}

/// Returns a String if the data is case .text
public var text: String? {
switch self {
case .text(let string):
return string
default:
return nil
}
}

/// Returns a float if the data is case .double
public var float: Double? {
switch self {
case .float(let double):
return double
default:
return nil
}
}

/// Returns Foundation.Data if the data is case .blob
public var blob: Foundation.Data? {
switch self {
case .blob(let data):
return data
default:
return nil
}
}

/// Returns true if the data == .null
public var isNull: Bool {
switch self {
case .null:
return true
default:
return false
}
}
}

extension SQLiteData: CustomStringConvertible {
/// Description of data
public var description: String {
switch self {
case .blob(let data):
return data.description
case .float(let float):
return float.description
case .integer(let int):
return int.description
case .null:
return "<null>"
case .text(let text):
return text
}
}
}

public protocol SQLiteDataConvertible {
static func convertFromSQLiteData(_ data: SQLiteData) throws -> Self
func convertToSQLiteData() throws -> SQLiteData
}


extension Data: SQLiteDataConvertible {
public static func convertFromSQLiteData(_ data: SQLiteData) throws -> Data {
switch data {
case .blob(let data): return data
default: throw SQLiteError(problem: .warning, reason: "Could not convert to Data: \(data)", source: .capture())
}
}

public func convertToSQLiteData() throws -> SQLiteData {
return .blob(self)
}
}
24 changes: 24 additions & 0 deletions Sources/SQLite/Data/SQLiteDataDecoder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public final class SQLiteDataDecoder: Decoder {
public var codingPath: [CodingKey]
public var userInfo: [CodingUserInfoKey: Any]
public let data: SQLiteData

public init(data: SQLiteData) {
self.codingPath = []
self.userInfo = [:]
self.data = data
}

public func container<Key: CodingKey>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
fatalError("unsupported")
}

public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
fatalError("unsupported")
}

public func singleValueContainer() -> SingleValueDecodingContainer {
return DataDecodingContainer(decoder: self)
}
}

83 changes: 83 additions & 0 deletions Sources/SQLite/Data/SQLiteDataDecodingContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
internal final class DataDecodingContainer: SingleValueDecodingContainer {
var codingPath: [CodingKey] {
return decoder.codingPath
}

let decoder: SQLiteDataDecoder
init(decoder: SQLiteDataDecoder) {
self.decoder = decoder
}

func decodeNil() -> Bool {
return decoder.data.isNull
}

func decode(_ type: Bool.Type) throws -> Bool {
fatalError("unsupported")
}

func decode(_ type: Int.Type) throws -> Int {
guard let int = decoder.data.fuzzyInt else {
fatalError("todo")
}
return int
}

func decode(_ type: Int8.Type) throws -> Int8 {
fatalError("unsupported")
}

func decode(_ type: Int16.Type) throws -> Int16 {
fatalError("unsupported")
}

func decode(_ type: Int32.Type) throws -> Int32 {
fatalError("unsupported")
}

func decode(_ type: Int64.Type) throws -> Int64 {
fatalError("unsupported")
}

func decode(_ type: UInt.Type) throws -> UInt {
fatalError("unsupported")
}

func decode(_ type: UInt8.Type) throws -> UInt8 {
fatalError("unsupported")
}

func decode(_ type: UInt16.Type) throws -> UInt16 {
fatalError("unsupported")
}

func decode(_ type: UInt32.Type) throws -> UInt32 {
fatalError("unsupported")
}

func decode(_ type: UInt64.Type) throws -> UInt64 {
fatalError("unsupported")
}

func decode(_ type: Float.Type) throws -> Float {
fatalError("unsupported")
}

func decode(_ type: Double.Type) throws -> Double {
guard let double = decoder.data.fuzzyDouble else {
fatalError("todo")
}
return double
}

func decode(_ type: String.Type) throws -> String {
guard let string = decoder.data.fuzzyString else {
fatalError("todo")
}
return string
}

func decode<T: Decodable>(_ type: T.Type) throws -> T {
return try T(from: decoder)
}
}
Loading

0 comments on commit 951e4f1

Please sign in to comment.