-
-
Notifications
You must be signed in to change notification settings - Fork 31
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 #29 from vapor/rc
sqlite 3.0 rc
- Loading branch information
Showing
40 changed files
with
1,640 additions
and
641 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
Sources/main.swift | ||
.build | ||
Packages | ||
Database | ||
*.xcodeproj | ||
Package.pins | ||
Package.resolved |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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"]), | ||
] | ||
) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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> |
This file was deleted.
Oops, something went wrong.
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,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) | ||
} | ||
} |
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 @@ | ||
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) | ||
} | ||
} | ||
|
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,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) | ||
} | ||
} |
Oops, something went wrong.