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

Prepare SQift 4.0 #16

Merged
merged 4 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os: osx
osx_image: xcode10
osx_image: xcode10.1
branches:
only:
- master
Expand All @@ -14,13 +14,12 @@ env:
- TVOS_FRAMEWORK_SCHEME="SQift tvOS CI"
- WATCHOS_FRAMEWORK_SCHEME="SQift watchOS"
matrix:
- DESTINATION="OS=12.0,name=iPhone XS" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="YES"
- DESTINATION="OS=12.1,name=iPhone XS" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="YES"
- DESTINATION="OS=11.3,name=iPhone X" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=10.3.1,name=iPhone 7" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=9.3,name=iPhone 4S" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="arch=x86_64" SCHEME="$MACOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=12.0,name=Apple TV 4K" SCHEME="$TVOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=5.0,name=Apple Watch Series 4 - 44mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=12.1,name=Apple TV 4K" SCHEME="$TVOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=5.1,name=Apple Watch Series 4 - 44mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"

before_install:
- gem update bundler
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
`SQift` adheres to [Semantic Versioning](http://semver.org/).

#### 4.x Releases

- `4.0.x` Releases - [4.0.0](#400)

#### 3.x Releases

- `3.3.x` Releases - [3.3.0](#330)
Expand Down Expand Up @@ -34,6 +38,22 @@ All notable changes to this project will be documented in this file.

---

## [4.0.0](https://github.com/Nike-Inc/SQift/releases/tag/4.0.0)

jereme marked this conversation as resolved.
Show resolved Hide resolved
#### Added
- Migration Guide for SQift 4 and added it to the README.
- Added by [Jereme Claussen](https://github.com/jereme)

#### Updated
- Deployment targets to iOS 9.0, Mac OSX 10.11, WatchOS 2.0 and tvOS 9.0.
- Added by [Jereme Claussen](https://github.com/jereme)
jereme marked this conversation as resolved.
Show resolved Hide resolved

#### Removed
- `Connection.trace` in favor of `Connection.traceEvent()`
- Added by [Jereme Claussen](https://github.com/jereme)
jereme marked this conversation as resolved.
Show resolved Hide resolved

---

## [3.3.0](https://github.com/Nike-Inc/SQift/releases/tag/3.3.0)

Released on 2018-11-30. All issues associated with this milestone can be found using this
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ SQift is a lightweight Swift wrapper for SQLite.

## Requirements

- iOS 9.0+, macOS 10.11+, tvOS 9.0+, watchOS 2.0+
- iOS 10.0+, macOS 10.12+, tvOS 10.0+, watchOS 3.0+
- Xcode 9.3+
- Swift 4.1+

## Migration Guides

- [SQift 4.0 Migration Guide](Documentation/SQift%204.0%20Migration%20Guide.md)

## Communication

- Need help? Open an issue.
Expand Down Expand Up @@ -86,7 +90,7 @@ $ brew install carthage
To integrate SQift into your Xcode project using Carthage, specify it in your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile):

```
github "Nike-Inc/SQift" ~> 3.0
github "Nike-Inc/SQift" ~> 4.0
```

Run `carthage update` to build the framework and drag the built `SQift.framework` into your Xcode project.
Expand Down Expand Up @@ -487,13 +491,15 @@ try connection.transaction {
### Tracing

When debugging SQL statements, sometimes it can be helpful to be able to print out what is actually being executed by SQLite.
SQift allows you to do this through the `trace`and `traceEvent` APIs by registering a closure to run for each statement execution.
SQift allows you to do this through the `traceEvent` API by registering a closure to run for each statement execution.

```swift
let connection = try Connection(storageLocation: storageLocation)

connection.trace { sql in
print(sql)
connection.traceEvent { event in
if case .statement(_, let sql) = sql {
print(sql)
}
}
jereme marked this conversation as resolved.
Show resolved Hide resolved

try connection.execute("CREATE TABLE employees(id INTEGER PRIMARY KEY, name TEXT)")
Expand Down
68 changes: 68 additions & 0 deletions SQift 4.0 Migration Guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SQift 4.0 Migration Guide

SQift 4.0 is the latest major release of SQift, a lightweight Swift wrapper for SQLite. As a major release following Semantic Versioning
conventions, 4.0 introduces multiple API-breaking changes that one should be aware of.

This guide is provided in order to ease the transition of existing applications using SQift 3.x to the latest APIs, as well as explain the
design and structure of new and changed functionality.

## Requirements

SQift 4.0 officially supports iOS 10.0+, macOS 10.12+, tvOS 10.0+, watchOS 3.0+, Xcode 9.3+ and Swift 4.1.

## Why a Major Bump?

With the introduction of watchOS 5.0, applications are no longer able to consumer frameworks with a deployment target of less than 3.0.
This exposes SQift's use of APIs that SQlite3 has slated for deprecation. It seemed best at this point, to bring all deployment targets up
one major revision and fully deprecate the use older APIs.

---

## Breaking API Changes

SQift 4.0 contains a very minor breaking change with how tracing can be performed.

### Event Tracing

With SQlite3's deprecation of the `sqlite3_trace` API, so goes SQift's `Connection.trace()` method. Instead you must leverage
the `traceEvent` API, which will require a little bit of extra code to achieve your previous results.

In SQift 3.2, you could trace the execution of SQL statements simply with code similar to the following:

```swift
let connection = try Connection(storageLocation: storageLocation)

connection.trace { sql in
print(sql)
}
```

In SQift 4.0, you will use the `traceEvent()` API, which returns a different type of object internally. You would write the above example as:

```swift
let connection = try Connection(storageLocation: storageLocation)

connection.traceEvent { event in
if case .statement(_, let sql) = sql {
print(sql)
}
}
```

In addition to this, you can pass a mask into `traceEvent` to restrict which event types are traced. The default mask is:

```swift
UInt32(SQLITE_TRACE_STMT | SQLITE_TRACE_PROFILE | SQLITE_TRACE_ROW | SQLITE_TRACE_CLOSE)`
```

If you wanted to only trace statements, your code would look like:

```swift
let connection = try Connection(storageLocation: storageLocation)

connection.traceEvent(mask: Connection.TraceEvent.statementMask) { event in
if case .statement(_, let sql) = sql {
print(sql)
}
}
```
jereme marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 5 additions & 5 deletions SQift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SQift"
s.version = "3.3.0"
s.version = "4.0.0"
s.license = "MIT"
s.summary = "A lightweight Swift wrapper for SQLite."
s.homepage = "https://github.com/Nike-Inc/SQift"
Expand All @@ -10,10 +10,10 @@ Pod::Spec.new do |s|
s.source_files = "Source/**/*.swift"
s.swift_version = "4.2"

s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.11"
s.tvos.deployment_target = "9.0"
s.watchos.deployment_target = "2.0"
s.ios.deployment_target = "10.0"
s.osx.deployment_target = "10.12"
s.tvos.deployment_target = "10.0"
s.watchos.deployment_target = "3.0"

s.libraries = "sqlite3"
end
20 changes: 16 additions & 4 deletions SQift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1E65A75F21B1C19C007F75F3 /* SQift 4.0 Migration Guide.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "SQift 4.0 Migration Guide.md"; sourceTree = "<group>"; };
4C13EF9E1F7C116D0069CF58 /* ProcessInfoExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProcessInfoExtension.swift; sourceTree = "<group>"; };
4C29B2E41BFB25C00086A2EF /* SQift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SQift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4C29B2ED1BFB25C00086A2EF /* SQift Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SQift Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -608,6 +609,7 @@
children = (
4CE5E8691F59E89700D47037 /* CHANGELOG.md */,
4CE5E86A1F59E89700D47037 /* README.md */,
1E65A75F21B1C19C007F75F3 /* SQift 4.0 Migration Guide.md */,
);
name = Documentation;
sourceTree = "<group>";
Expand Down Expand Up @@ -1188,6 +1190,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
OTHER_LDFLAGS = "-lsqlite3";
PRODUCT_BUNDLE_IDENTIFIER = com.nike.SQift;
PRODUCT_NAME = SQift;
Expand Down Expand Up @@ -1215,6 +1218,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
OTHER_LDFLAGS = "-lsqlite3";
PRODUCT_BUNDLE_IDENTIFIER = com.nike.SQift;
PRODUCT_NAME = SQift;
Expand Down Expand Up @@ -1286,6 +1290,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 10.0;
};
name = Debug;
};
Expand All @@ -1312,6 +1317,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 10.0;
};
name = Release;
};
Expand All @@ -1331,6 +1337,7 @@
PRODUCT_NAME = "SQift Tests";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
TVOS_DEPLOYMENT_TARGET = 10.0;
};
name = Debug;
};
Expand All @@ -1350,6 +1357,7 @@
PRODUCT_NAME = "SQift Tests";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
TVOS_DEPLOYMENT_TARGET = 10.0;
};
name = Release;
};
Expand Down Expand Up @@ -1380,6 +1388,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 3.0;
};
name = Debug;
};
Expand All @@ -1406,6 +1415,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -1470,8 +1480,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MACOSX_DEPLOYMENT_TARGET = 10.11;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1526,8 +1536,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MACOSX_DEPLOYMENT_TARGET = 10.11;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -1558,6 +1568,7 @@
);
INFOPLIST_FILE = "Source/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1582,6 +1593,7 @@
GCC_PREPROCESSOR_DEFINITIONS = "SQLITE_HAS_CODEC=1";
INFOPLIST_FILE = "Source/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
7 changes: 1 addition & 6 deletions Source/Connection/Functions/Function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,7 @@ extension Connection {
data.withUnsafeBytes { sqlite3_result_blob64(context, $0, UInt64(data.count), SQLITE_TRANSIENT) }

case .zeroData(let length):
if #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) {
sqlite3_result_zeroblob64(context, length)
} else {
let clampedLength = Int32(exactly: length) ?? Int32.max
sqlite3_result_zeroblob(context, clampedLength)
}
sqlite3_result_zeroblob64(context, length)

case .error(let message, let code):
sqlite3_result_error(context, message, Int32(message.utf8.count))
Expand Down
32 changes: 0 additions & 32 deletions Source/Connection/Functions/Trace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ extension Connection {
///
/// - connectionClosed: Invoked when a database connection closes. The `connection` is a pointer to the database
/// connection.
@available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *)
public enum TraceEvent: CustomStringConvertible {
case statement(statement: String, sql: SQL)
case profile(statement: String, seconds: Double)
Expand Down Expand Up @@ -83,7 +82,6 @@ extension Connection {
}
}

@available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *)
private class TraceEventBox {
let closure: (TraceEvent) -> Void

Expand Down Expand Up @@ -139,43 +137,13 @@ extension Connection {
}
}

// MARK: - Tracing

/// Registers the callback with SQLite to be called each time a statement calls step.
///
/// For more details, please refer to the [documentation](https://www.sqlite.org/c3ref/profile.html).
///
/// - Parameter closure: The closure called when SQLite internally calls step on a statement.
@available(*, deprecated: 3.3, message: "The `trace` API will be removed in SQift 4.0. Please use `traceEvent` instead.")
public func trace(_ closure: ((String) -> Void)?) {
guard let closure = closure else {
sqlite3_trace(handle, nil, nil)
traceBox = nil
return
}

let box = TraceBox(closure)
traceBox = box

sqlite3_trace(
handle,
{ (boxPointer: UnsafeMutableRawPointer?, data: UnsafePointer<Int8>?) in
guard let boxPointer = boxPointer else { return }
let box = Unmanaged<TraceBox>.fromOpaque(boxPointer).takeUnretainedValue()
box.trace(data)
},
Unmanaged<TraceBox>.passUnretained(box).toOpaque()
)
}

/// Registers the callback with SQLite to be called each time a statement calls step.
///
/// For more details, please refer to the [documentation](https://www.sqlite.org/c3ref/trace_v2.html).
///
/// - Parameters:
/// - mask: The bitwise OR-ed mask of trace event constants.
/// - closure: The closure called when SQLite internally calls step on a statement.
@available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *)
public func traceEvent(mask: UInt32? = nil, closure: ((TraceEvent) -> Void)?) {
guard let closure = closure else {
sqlite3_trace_v2(handle, 0, nil, nil)
Expand Down
1 change: 0 additions & 1 deletion Source/Connection/Statement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class Statement {
///
/// Note that this API can return `nil` if there is insufficient memory to hold the result, or if the result would
/// exceed the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
@available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *)
public var expandedSQL: SQL? {
guard let expandedSQL = sqlite3_expanded_sql(handle) else { return nil }
return SQL(cString: expandedSQL)
Expand Down
Loading