From 481b531c6906e11d8efcc7c36ea89b7e572e6ce7 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Tue, 18 Oct 2022 22:14:04 +0200 Subject: [PATCH 01/11] Run on macOS 12 Bump deployment targets Disable watchOS validation CocoaPods/CocoaPods#11558 Adjust deployment targets for Xcode 14 --- .github/workflows/build.yml | 4 ++-- Package.swift | 8 ++++---- SQLite.swift.podspec | 8 ++++---- SQLite.xcodeproj/project.pbxproj | 30 ++++++++++++++++++++++-------- Tests/SPM/Package.swift | 8 ++++---- run-tests.sh | 4 ++-- 6 files changed, 38 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1659d9d..beec5ca2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,10 +2,10 @@ name: Build and test on: [push, pull_request] env: IOS_SIMULATOR: iPhone 12 - IOS_VERSION: "15.2" + IOS_VERSION: "16.0" jobs: build: - runs-on: macos-11 + runs-on: macos-12 steps: - uses: actions/checkout@v2 - name: Install diff --git a/Package.swift b/Package.swift index 9664e99a..de40367a 100644 --- a/Package.swift +++ b/Package.swift @@ -4,10 +4,10 @@ import PackageDescription let package = Package( name: "SQLite.swift", platforms: [ - .iOS(.v9), - .macOS(.v10_10), - .watchOS(.v3), - .tvOS(.v9) + .iOS(.v11), + .macOS(.v10_13), + .watchOS(.v4), + .tvOS(.v11) ], products: [ .library( diff --git a/SQLite.swift.podspec b/SQLite.swift.podspec index f32282d3..4edddd67 100644 --- a/SQLite.swift.podspec +++ b/SQLite.swift.podspec @@ -18,10 +18,10 @@ Pod::Spec.new do |s| s.default_subspec = 'standard' s.swift_versions = ['5'] - ios_deployment_target = '9.0' - tvos_deployment_target = '9.1' - osx_deployment_target = '10.10' - watchos_deployment_target = '3.0' + ios_deployment_target = '11.0' + tvos_deployment_target = '11.0' + osx_deployment_target = '10.13' + watchos_deployment_target = '4.0' s.ios.deployment_target = ios_deployment_target s.tvos.deployment_target = tvos_deployment_target diff --git a/SQLite.xcodeproj/project.pbxproj b/SQLite.xcodeproj/project.pbxproj index 3d62e980..def32855 100644 --- a/SQLite.xcodeproj/project.pbxproj +++ b/SQLite.xcodeproj/project.pbxproj @@ -1263,6 +1263,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; + TVOS_DEPLOYMENT_TARGET = 11.0; }; name = Debug; }; @@ -1284,6 +1285,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; + TVOS_DEPLOYMENT_TARGET = 11.0; }; name = Release; }; @@ -1297,6 +1299,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; + TVOS_DEPLOYMENT_TARGET = 11.0; }; name = Debug; }; @@ -1310,6 +1313,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; + TVOS_DEPLOYMENT_TARGET = 11.0; }; name = Release; }; @@ -1333,6 +1337,7 @@ SKIP_INSTALL = YES; SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; TARGETED_DEVICE_FAMILY = 4; + WATCHOS_DEPLOYMENT_TARGET = 4.0; }; name = Debug; }; @@ -1356,6 +1361,7 @@ SKIP_INSTALL = YES; SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; TARGETED_DEVICE_FAMILY = 4; + WATCHOS_DEPLOYMENT_TARGET = 4.0; }; name = Release; }; @@ -1408,8 +1414,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.10; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = ""; @@ -1417,10 +1423,10 @@ SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3"; - TVOS_DEPLOYMENT_TARGET = 9.1; + TVOS_DEPLOYMENT_TARGET = 11.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; - WATCHOS_DEPLOYMENT_TARGET = 3.0; + WATCHOS_DEPLOYMENT_TARGET = 4.0; }; name = Debug; }; @@ -1467,19 +1473,19 @@ 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.10; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_NAME = ""; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3"; - TVOS_DEPLOYMENT_TARGET = 9.1; + TVOS_DEPLOYMENT_TARGET = 11.0; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; - WATCHOS_DEPLOYMENT_TARGET = 3.0; + WATCHOS_DEPLOYMENT_TARGET = 4.0; }; name = Release; }; @@ -1496,6 +1502,7 @@ GCC_TREAT_WARNINGS_AS_ERRORS = YES; INFOPLIST_FILE = "$(SRCROOT)/Sources/SQLite/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 0.14.0; PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLite; @@ -1519,6 +1526,7 @@ GCC_TREAT_WARNINGS_AS_ERRORS = YES; INFOPLIST_FILE = "$(SRCROOT)/Sources/SQLite/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 0.14.0; PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLite; @@ -1533,6 +1541,7 @@ buildSettings = { GCC_TREAT_WARNINGS_AS_ERRORS = YES; INFOPLIST_FILE = Tests/SQLiteTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLiteTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1545,6 +1554,7 @@ buildSettings = { GCC_TREAT_WARNINGS_AS_ERRORS = YES; INFOPLIST_FILE = Tests/SQLiteTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLiteTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1567,6 +1577,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/SQLite/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLite; PRODUCT_NAME = SQLite; SDKROOT = macosx; @@ -1591,6 +1602,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/SQLite/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLite; PRODUCT_NAME = SQLite; SDKROOT = macosx; @@ -1608,6 +1620,7 @@ GCC_TREAT_WARNINGS_AS_ERRORS = YES; INFOPLIST_FILE = Tests/SQLiteTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLiteTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -1623,6 +1636,7 @@ GCC_TREAT_WARNINGS_AS_ERRORS = YES; INFOPLIST_FILE = Tests/SQLiteTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLiteTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; diff --git a/Tests/SPM/Package.swift b/Tests/SPM/Package.swift index 3e329552..51f176f4 100644 --- a/Tests/SPM/Package.swift +++ b/Tests/SPM/Package.swift @@ -6,10 +6,10 @@ import PackageDescription let package = Package( name: "test", platforms: [ - .iOS(.v9), - .macOS(.v10_10), - .watchOS(.v3), - .tvOS(.v9) + .iOS(.v11), + .macOS(.v10_13), + .watchOS(.v4), + .tvOS(.v11) ], dependencies: [ // for testing from same repository diff --git a/run-tests.sh b/run-tests.sh index 49330c12..c54300ee 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -8,9 +8,9 @@ if [ -n "$BUILD_SCHEME" ]; then fi elif [ -n "$VALIDATOR_SUBSPEC" ]; then if [ "$VALIDATOR_SUBSPEC" == "none" ]; then - pod lib lint --no-subspecs --fail-fast + pod lib lint --no-subspecs --fail-fast --platforms=ios,osx,tvos else - pod lib lint --subspec="${VALIDATOR_SUBSPEC}" --fail-fast + pod lib lint --subspec="${VALIDATOR_SUBSPEC}" --fail-fast --platforms=ios,osx,tvos fi elif [ -n "$CARTHAGE_PLATFORM" ]; then cd Tests/Carthage && make test CARTHAGE_PLATFORM="$CARTHAGE_PLATFORM" From a2897d5512f897e566247808bf7d87b2f033b5e7 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 12:45:26 +0200 Subject: [PATCH 02/11] Run on macos-13 --- .github/workflows/build.yml | 4 ++-- .gitignore | 1 + Package.swift | 2 +- Tests/SPM/Package.swift | 7 ++----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index beec5ca2..ae806ecc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,10 +2,10 @@ name: Build and test on: [push, pull_request] env: IOS_SIMULATOR: iPhone 12 - IOS_VERSION: "16.0" + IOS_VERSION: "16.4" jobs: build: - runs-on: macos-12 + runs-on: macos-13 steps: - uses: actions/checkout@v2 - name: Install diff --git a/.gitignore b/.gitignore index 5882e0cb..b7d43ec9 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ DerivedData # Swift Package Manager .build Packages/ +.swiftpm/ diff --git a/Package.swift b/Package.swift index de40367a..70bde7ef 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:5.7 import PackageDescription let package = Package( diff --git a/Tests/SPM/Package.swift b/Tests/SPM/Package.swift index 51f176f4..3c446ae6 100644 --- a/Tests/SPM/Package.swift +++ b/Tests/SPM/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:5.7 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -18,9 +18,6 @@ let package = Package( // .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.1") ], targets: [ - .target( - name: "test", - dependencies: [.product(name: "SQLite", package: "SQLite.swift")] - ) + .executableTarget(name: "test", dependencies: [.product(name: "SQLite", package: "SQLite.swift")]) ] ) From 85f1d443e9b758aaeea3fc5c9b3abef67675931b Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 15:09:30 +0200 Subject: [PATCH 03/11] Automatically download swiftlint / xcbeautifier, lint fixes --- .gitignore | 3 + .swiftlint.yml | 5 +- Makefile | 81 +++++++++++++------ Sources/SQLite/Core/Backup.swift | 2 +- Sources/SQLite/Helpers.swift | 1 + Sources/SQLite/Schema/SchemaReader.swift | 2 +- Sources/SQLite/Typed/Query.swift | 2 +- Tests/.swiftlint.yml | 4 +- Tests/SQLiteTests/Schema/SchemaTests.swift | 2 + .../Typed/CustomFunctionsTests.swift | 16 ++-- 10 files changed, 80 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index b7d43ec9..e7b2ad4d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ DerivedData # Carthage /Carthage/ +# Makefile +bin/ + # Swift Package Manager .build Packages/ diff --git a/.swiftlint.yml b/.swiftlint.yml index d40be28e..e728e191 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -4,6 +4,7 @@ disabled_rules: # rule identifiers to exclude from running - large_tuple - closure_parameter_position - inclusive_language # sqlite_master etc. + - blanket_disable_command included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`. - Sources - Tests @@ -26,8 +27,8 @@ identifier_name: - SQLITE_TRANSIENT type_body_length: - warning: 260 - error: 260 + warning: 350 + error: 350 function_body_length: warning: 60 diff --git a/Makefile b/Makefile index 74bf5d18..73b33f97 100644 --- a/Makefile +++ b/Makefile @@ -1,41 +1,76 @@ -BUILD_TOOL = xcodebuild +XCODEBUILD = xcodebuild BUILD_SCHEME = SQLite Mac -IOS_SIMULATOR = iPhone 12 -IOS_VERSION = 15.0 +IOS_SIMULATOR = iPhone 14 +IOS_VERSION = 16.4 + +# tool settings +SWIFTLINT_VERSION=0.52.2 +SWIFTLINT=bin/swiftlint-$(SWIFTLINT_VERSION) +SWIFTLINT_URL=https://github.com/realm/SwiftLint/releases/download/$(SWIFTLINT_VERSION)/portable_swiftlint.zip +XCBEAUTIFY_VERSION=0.20.0 +XCBEAUTIFY=bin/xcbeautify-$(XCBEAUTIFY_VERSION) +ifeq ($(shell uname), Linux) + XCBEAUTIFY_PLATFORM=x86_64-unknown-linux-gnu.tar.xz +else + XCBEAUTIFY_PLATFORM=universal-apple-macosx.zip +endif +XCBEAUTIFY_URL=https://github.com/tuist/xcbeautify/releases/download/$(XCBEAUTIFY_VERSION)/xcbeautify-$(XCBEAUTIFY_VERSION)-$(XCBEAUTIFY_PLATFORM) +CURL_OPTS=--fail --silent -L --retry 3 + ifeq ($(BUILD_SCHEME),SQLite iOS) BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" -destination "platform=iOS Simulator,name=$(IOS_SIMULATOR),OS=$(IOS_VERSION)" else BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" endif -XCPRETTY := $(shell command -v xcpretty) -TEST_ACTIONS := clean build build-for-testing test-without-building +test: $(XCBEAUTIFY) + set -o pipefail; \ + $(XCODEBUILD) $(BUILD_ARGUMENTS) test | $(XCBEAUTIFY) -default: test +build: $(XCBEAUTIFY) + set -o pipefail; \ + $(XCODEBUILD) $(BUILD_ARGUMENTS) | $(XCBEAUTIFY) -build: - $(BUILD_TOOL) $(BUILD_ARGUMENTS) +lint: $(SWIFTLINT) + $< --strict -lint: - swiftlint --strict -lint-fix: - swiftlint lint fix - -test: -ifdef XCPRETTY - @set -o pipefail && $(BUILD_TOOL) $(BUILD_ARGUMENTS) $(TEST_ACTIONS) | $(XCPRETTY) -c -else - $(BUILD_TOOL) $(BUILD_ARGUMENTS) $(TEST_ACTIONS) -endif +lint-fix: $(SWIFTLINT) + $< lint fix clean: - $(BUILD_TOOL) $(BUILD_ARGUMENTS) clean + $(XCODEBUILD) $(BUILD_ARGUMENTS) clean repl: - @$(BUILD_TOOL) $(BUILD_ARGUMENTS) -derivedDataPath $(TMPDIR)/SQLite.swift > /dev/null && \ - swift -F '$(TMPDIR)/SQLite.swift/Build/Products/Debug' + @$(XCODEBUILD) $(BUILD_ARGUMENTS) -derivedDataPath $(TMPDIR)/SQLite.swift > /dev/null && \ + swift repl -F '$(TMPDIR)/SQLite.swift/Build/Products/Debug' sloc: - @zsh -c "grep -vE '^ *//|^$$' Sources/**/*.{swift,h,m} | wc -l" + @zsh -c "grep -vE '^ *//|^$$' Sources/**/*.{swift,h} | wc -l" + +$(SWIFTLINT): + set -e ; \ + curl $(CURL_OPTS) $(SWIFTLINT_URL) -o swiftlint.zip; \ + unzip -o swiftlint.zip swiftlint; \ + mkdir -p bin; \ + mv swiftlint $@ && rm -f swiftlint.zip + +$(XCBEAUTIFY): + set -e; \ + FILE=$(XCBEAUTIFY_PLATFORM); \ + curl $(CURL_OPTS) $(XCBEAUTIFY_URL) -o $$FILE; \ + case "$${FILE#*.}" in \ + "zip") \ + unzip -o $$FILE xcbeautify; \ + ;; \ + "tar.xz") \ + tar -xvf $$FILE xcbeautify; \ + ;; \ + *) \ + echo "unknown extension $${FILE#*.}!"; \ + exit 1; \ + ;; \ + esac; \ + mkdir -p bin; \ + mv xcbeautify $@ && rm -f $$FILE; .PHONY: test clean repl sloc diff --git a/Sources/SQLite/Core/Backup.swift b/Sources/SQLite/Core/Backup.swift index 84ebf1e0..0eebbdd5 100644 --- a/Sources/SQLite/Core/Backup.swift +++ b/Sources/SQLite/Core/Backup.swift @@ -140,7 +140,7 @@ public final class Backup { /// - Parameter pagesToCopy: The maximal number of pages to copy in one step /// /// - Throws: `Result.Error` if step fails. - // + /// /// See: public func step(pagesToCopy pages: Pages = .all) throws { let status = sqlite3_backup_step(handle, pages.number) diff --git a/Sources/SQLite/Helpers.swift b/Sources/SQLite/Helpers.swift index e3d37e11..79d057d6 100644 --- a/Sources/SQLite/Helpers.swift +++ b/Sources/SQLite/Helpers.swift @@ -38,6 +38,7 @@ public func *(_: Expression?, _: Expression?) -> Expression [ColumnDefinition] { + public func columnDefinitions(table: String) throws -> [ColumnDefinition] { func parsePrimaryKey(column: String) throws -> ColumnDefinition.PrimaryKey? { try createTableSQL(name: table).flatMap { .init(sql: $0) } } diff --git a/Sources/SQLite/Typed/Query.swift b/Sources/SQLite/Typed/Query.swift index feff2f69..c59b728f 100644 --- a/Sources/SQLite/Typed/Query.swift +++ b/Sources/SQLite/Typed/Query.swift @@ -1105,7 +1105,7 @@ extension Connection { return value(try scalar(expression.template, expression.bindings)) } - public func scalar(_ query: Select) throws -> V.ValueType? { + public func scalar(_ query: Select) throws -> V.ValueType? { let expression = query.expression guard let value = try scalar(expression.template, expression.bindings) as? V.Datatype else { return nil } return V.fromDatatypeValue(value) diff --git a/Tests/.swiftlint.yml b/Tests/.swiftlint.yml index 3537085c..81d6c314 100644 --- a/Tests/.swiftlint.yml +++ b/Tests/.swiftlint.yml @@ -6,8 +6,8 @@ disabled_rules: - identifier_name type_body_length: - warning: 800 - error: 800 + warning: 1000 + error: 1000 function_body_length: warning: 200 diff --git a/Tests/SQLiteTests/Schema/SchemaTests.swift b/Tests/SQLiteTests/Schema/SchemaTests.swift index a7de8bcf..4f4a49d1 100644 --- a/Tests/SQLiteTests/Schema/SchemaTests.swift +++ b/Tests/SQLiteTests/Schema/SchemaTests.swift @@ -72,6 +72,7 @@ class SchemaTests: XCTestCase { } // thoroughness test for ambiguity + // swiftlint:disable:next function_body_length func test_column_compilesColumnDefinitionExpression() { XCTAssertEqual( "CREATE TABLE \"table\" (\"int64\" INTEGER NOT NULL)", @@ -390,6 +391,7 @@ class SchemaTests: XCTestCase { ) } + // swiftlint:disable:next function_body_length func test_column_withStringExpression_compilesCollatedColumnDefinitionExpression() { XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL COLLATE RTRIM)", diff --git a/Tests/SQLiteTests/Typed/CustomFunctionsTests.swift b/Tests/SQLiteTests/Typed/CustomFunctionsTests.swift index c4eb51e6..0f46b380 100644 --- a/Tests/SQLiteTests/Typed/CustomFunctionsTests.swift +++ b/Tests/SQLiteTests/Typed/CustomFunctionsTests.swift @@ -5,8 +5,8 @@ import SQLite #if !os(Linux) class CustomFunctionNoArgsTests: SQLiteTestCase { - typealias FunctionNoOptional = () -> Expression - typealias FunctionResultOptional = () -> Expression + typealias FunctionNoOptional = () -> Expression + typealias FunctionResultOptional = () -> Expression func testFunctionNoOptional() throws { let _: FunctionNoOptional = try db.createFunction("test", deterministic: true) { @@ -26,9 +26,9 @@ class CustomFunctionNoArgsTests: SQLiteTestCase { } class CustomFunctionWithOneArgTests: SQLiteTestCase { - typealias FunctionNoOptional = (Expression) -> Expression + typealias FunctionNoOptional = (Expression) -> Expression typealias FunctionLeftOptional = (Expression) -> Expression - typealias FunctionResultOptional = (Expression) -> Expression + typealias FunctionResultOptional = (Expression) -> Expression typealias FunctionLeftResultOptional = (Expression) -> Expression func testFunctionNoOptional() throws { @@ -65,12 +65,12 @@ class CustomFunctionWithOneArgTests: SQLiteTestCase { } class CustomFunctionWithTwoArgsTests: SQLiteTestCase { - typealias FunctionNoOptional = (Expression, Expression) -> Expression - typealias FunctionLeftOptional = (Expression, Expression) -> Expression + typealias FunctionNoOptional = (Expression, Expression) -> Expression + typealias FunctionLeftOptional = (Expression, Expression) -> Expression typealias FunctionRightOptional = (Expression, Expression) -> Expression - typealias FunctionResultOptional = (Expression, Expression) -> Expression + typealias FunctionResultOptional = (Expression, Expression) -> Expression typealias FunctionLeftRightOptional = (Expression, Expression) -> Expression - typealias FunctionLeftResultOptional = (Expression, Expression) -> Expression + typealias FunctionLeftResultOptional = (Expression, Expression) -> Expression typealias FunctionRightResultOptional = (Expression, Expression) -> Expression typealias FunctionLeftRightResultOptional = (Expression, Expression) -> Expression From 4a0ab2a7445712e71ff803e020b74f9557ae64a8 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 15:14:36 +0200 Subject: [PATCH 04/11] Fix simulator version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ae806ecc..ac705e4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: Build and test on: [push, pull_request] env: - IOS_SIMULATOR: iPhone 12 + IOS_SIMULATOR: "iPhone 14" IOS_VERSION: "16.4" jobs: build: From e4f4ddff5f124652421d7cd99512181bed86b0e7 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 15:22:26 +0200 Subject: [PATCH 05/11] Use newer Xcode --- .github/workflows/build.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac705e4e..fbe4ec49 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,13 +8,11 @@ jobs: runs-on: macos-13 steps: - uses: actions/checkout@v2 - - name: Install + - name: "Select Xcode" run: | - gem update bundler - gem install xcpretty --no-document - brew update - brew outdated carthage || brew upgrade carthage - brew outdated swiftlint || brew upgrade swiftlint + xcode-select -p + xcode-select -s /Applications/Xcode-14.3.app/Contents/Developer + xcode-select -p - name: "Lint" run: make lint - name: "Run tests (PACKAGE_MANAGER_COMMAND: test)" From 1bc58a5477cc47856d1e6a31b834f1cc0f66c00b Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 15:28:43 +0200 Subject: [PATCH 06/11] Fix path --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbe4ec49..8c893c77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: - name: "Select Xcode" run: | xcode-select -p - xcode-select -s /Applications/Xcode-14.3.app/Contents/Developer + xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer xcode-select -p - name: "Lint" run: make lint From 79bab4610b74cc7a8dee118a6b9ebce769aaec61 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 15:33:04 +0200 Subject: [PATCH 07/11] sudo --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c893c77..15f325ed 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: - name: "Select Xcode" run: | xcode-select -p - xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer + sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer xcode-select -p - name: "Lint" run: make lint From b028fcdda1489a3bb0c738f8809154f9c4be7f5b Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 17:48:05 +0200 Subject: [PATCH 08/11] Try Xcode 14.2 --- .github/workflows/build.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 15f325ed..242a9021 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build and test on: [push, pull_request] env: IOS_SIMULATOR: "iPhone 14" - IOS_VERSION: "16.4" + IOS_VERSION: "16.2" jobs: build: runs-on: macos-13 @@ -11,8 +11,7 @@ jobs: - name: "Select Xcode" run: | xcode-select -p - sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer - xcode-select -p + sudo xcode-select -s /Applications/Xcode_14.2.app/Contents/Developer - name: "Lint" run: make lint - name: "Run tests (PACKAGE_MANAGER_COMMAND: test)" From 101109848902bb2c7061286c86f15a638d6d5a17 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 22:28:40 +0200 Subject: [PATCH 09/11] Update docs --- .github/workflows/build.yml | 2 ++ CHANGELOG.md | 5 +++++ Documentation/Index.md | 31 ++++++++++++++----------------- README.md | 5 +---- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 242a9021..9cc2f56e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,6 +9,8 @@ jobs: steps: - uses: actions/checkout@v2 - name: "Select Xcode" + # Currently only works with Xcode 14.2: + # https://github.com/CocoaPods/CocoaPods/issues/11839 run: | xcode-select -p sudo xcode-select -s /Applications/Xcode_14.2.app/Contents/Developer diff --git a/CHANGELOG.md b/CHANGELOG.md index fc759118..970b4ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +0.15.0 (unreleased) +======================================== + +* New minimum deployment targets: iOS/tvOS 11.0, watchOS 4.0 + 0.14.1 (01-11-2022), [diff][diff-0.14.1] ======================================== diff --git a/Documentation/Index.md b/Documentation/Index.md index 583d5def..5d72aa4b 100644 --- a/Documentation/Index.md +++ b/Documentation/Index.md @@ -77,9 +77,6 @@ ## Installation -> _Note:_ SQLite.swift requires Swift 5 (and -> [Xcode 10.2](https://developer.apple.com/xcode/downloads/)) or greater. - ### Swift Package Manager The [Swift Package Manager][] is a tool for managing the distribution of @@ -1142,11 +1139,11 @@ let query = managers chain.with(chain, recursive: true, as: query) // WITH RECURSIVE // "chain" AS ( -// SELECT * FROM "managers" WHERE "id" = 8 -// UNION -// SELECT * from "chain" +// SELECT * FROM "managers" WHERE "id" = 8 +// UNION +// SELECT * from "chain" // JOIN "managers" ON "chain"."manager_id" = "managers"."id" -// ) +// ) // SELECT * FROM "chain" ``` @@ -1156,7 +1153,7 @@ Column names and a materialization hint can optionally be provided. // Add a "level" column to the query representing manager's position in the chain let level = Expression("level") -let queryWithLevel = +let queryWithLevel = managers .select(id, managerId, 0) .where(id == 8) @@ -1166,18 +1163,18 @@ let queryWithLevel = .join(managers, on: chain[managerId] == managers[id]) ) -chain.with(chain, - columns: [id, managerId, level], +chain.with(chain, + columns: [id, managerId, level], recursive: true, hint: .materialize, as: queryWithLevel) // WITH RECURSIVE // "chain" ("id", "manager_id", "level") AS MATERIALIZED ( -// SELECT ("id", "manager_id", 0) FROM "managers" WHERE "id" = 8 -// UNION -// SELECT ("manager"."id", "manager"."manager_id", "level" + 1) FROM "chain" +// SELECT ("id", "manager_id", 0) FROM "managers" WHERE "id" = 8 +// UNION +// SELECT ("manager"."id", "manager"."manager_id", "level" + 1) FROM "chain" // JOIN "managers" ON "chain"."manager_id" = "managers"."id" -// ) +// ) // SELECT * FROM "chain" ``` @@ -1266,7 +1263,7 @@ let count = try db.scalar(users.filter(name != nil).count) We can upsert rows into a table by calling a [query’s](#queries) `upsert` function with a list of [setters](#setters)—typically [typed column expressions](#expressions) and values (which can also be expressions)—each -joined by the `<-` operator. Upserting is like inserting, except if there is a +joined by the `<-` operator. Upserting is like inserting, except if there is a conflict on the specified column value, SQLite will perform an update on the row instead. ```swift @@ -1957,7 +1954,7 @@ for row in stmt.bind(kUTTypeImage) { /* ... */ } ``` > _Note:_ Prepared queries can be reused, and long lived prepared queries should be `reset()` after each use. Otherwise, the transaction (either [implicit or explicit](https://www.sqlite.org/lang_transaction.html#implicit_versus_explicit_transactions)) will be held open until the query is reset or finalized. This can affect performance. Statements are reset automatically during `deinit`. -> +> > ```swift > someObj.statement = try db.prepare("SELECT * FROM attachments WHERE typeConformsTo(UTI, ?)") > for row in someObj.statement.bind(kUTTypeImage) { /* ... */ } @@ -2134,7 +2131,7 @@ using the following functions. } } ``` - + - `run` prepares a single `Statement` object from a SQL string, optionally binds values to it (using the statement’s `bind` function), executes, and returns the statement. diff --git a/README.md b/README.md index 90333b16..e6e5a894 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ API. // Wrap everything in a do...catch to handle errors do { // ... - + let stmt = try db.prepare("INSERT INTO users (email) VALUES (?)") for email in ["betty@icloud.com", "cathy@icloud.com"] { try stmt.run(email) @@ -119,9 +119,6 @@ interactively, from the Xcode project’s playground. ## Installation -> _Note:_ Version 0.11.6 and later requires Swift 5 (and [Xcode](https://developer.apple.com/xcode/downloads/) 10.2) or greater. -> Version 0.11.5 requires Swift 4.2 (and [Xcode](https://developer.apple.com/xcode/downloads/) 10.1) or greater. - ### Swift Package Manager The [Swift Package Manager][] is a tool for managing the distribution of From ab3c598db29a7a2db3e06e9642736cb18e670a0e Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 21 May 2023 23:59:35 +0200 Subject: [PATCH 10/11] Use shorthand optional binding --- .swiftlint.yml | 2 ++ Sources/SQLite/Core/Connection+Attach.swift | 2 +- Sources/SQLite/Core/Connection.swift | 18 +++++------ Sources/SQLite/Core/Result.swift | 4 +-- Sources/SQLite/Extensions/FTS4.swift | 16 +++++----- Sources/SQLite/Extensions/FTS5.swift | 6 ++-- Sources/SQLite/Helpers.swift | 2 +- Sources/SQLite/Schema/SchemaDefinitions.swift | 2 +- Sources/SQLite/Schema/SchemaReader.swift | 4 +-- Sources/SQLite/Typed/Coding.swift | 12 ++++---- Sources/SQLite/Typed/CoreFunctions.swift | 30 +++++++++---------- Sources/SQLite/Typed/Operators.swift | 16 +++++----- 12 files changed, 58 insertions(+), 56 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index e728e191..1bb21cd5 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,3 +1,5 @@ +opt_in_rules: + - shorthand_optional_binding disabled_rules: # rule identifiers to exclude from running - todo - operator_whitespace diff --git a/Sources/SQLite/Core/Connection+Attach.swift b/Sources/SQLite/Core/Connection+Attach.swift index 47e6af5e..8a25e51d 100644 --- a/Sources/SQLite/Core/Connection+Attach.swift +++ b/Sources/SQLite/Core/Connection+Attach.swift @@ -13,7 +13,7 @@ extension Connection { #if SQLITE_SWIFT_SQLCIPHER /// See https://www.zetetic.net/sqlcipher/sqlcipher-api/#attach public func attach(_ location: Location, as schemaName: String, key: String? = nil) throws { - if let key = key { + if let key { try run("ATTACH DATABASE ? AS ? KEY ?", location.description, schemaName, key) } else { try run("ATTACH DATABASE ? AS ?", location.description, schemaName) diff --git a/Sources/SQLite/Core/Connection.swift b/Sources/SQLite/Core/Connection.swift index 26cadea4..f2c3b781 100644 --- a/Sources/SQLite/Core/Connection.swift +++ b/Sources/SQLite/Core/Connection.swift @@ -414,7 +414,7 @@ public final class Connection { /// times it’s been called for this lock. If it returns `true`, it will /// try again. If it returns `false`, no further attempts will be made. public func busyHandler(_ callback: ((_ tries: Int) -> Bool)?) { - guard let callback = callback else { + guard let callback else { sqlite3_busy_handler(handle, nil, nil) busyHandler = nil return @@ -449,7 +449,7 @@ public final class Connection { @available(watchOS, deprecated: 3.0) @available(tvOS, deprecated: 10.0) fileprivate func trace_v1(_ callback: ((String) -> Void)?) { - guard let callback = callback else { + guard let callback else { sqlite3_trace(handle, nil /* xCallback */, nil /* pCtx */) trace = nil return @@ -458,7 +458,7 @@ public final class Connection { callback(String(cString: pointer.assumingMemoryBound(to: UInt8.self))) } sqlite3_trace(handle, { (context: UnsafeMutableRawPointer?, SQL: UnsafePointer?) in - if let context = context, let SQL = SQL { + if let context, let SQL { unsafeBitCast(context, to: Trace.self)(SQL) } }, @@ -469,7 +469,7 @@ public final class Connection { @available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) fileprivate func trace_v2(_ callback: ((String) -> Void)?) { - guard let callback = callback else { + guard let callback else { // If the X callback is NULL or if the M mask is zero, then tracing is disabled. sqlite3_trace_v2(handle, 0 /* mask */, nil /* xCallback */, nil /* pCtx */) trace = nil @@ -485,7 +485,7 @@ public final class Connection { // callback was invoked. The C argument is a copy of the context pointer. // The P and X arguments are pointers whose meanings depend on T. (_: UInt32, context: UnsafeMutableRawPointer?, pointer: UnsafeMutableRawPointer?, _: UnsafeMutableRawPointer?) in - if let pointer = pointer, + if let pointer, let expandedSQL = sqlite3_expanded_sql(OpaquePointer(pointer)) { unsafeBitCast(context, to: Trace.self)(expandedSQL) sqlite3_free(expandedSQL) @@ -507,7 +507,7 @@ public final class Connection { /// `.Insert`, `.Update`, or `.Delete`), database name, table name, and /// rowid. public func updateHook(_ callback: ((_ operation: Operation, _ db: String, _ table: String, _ rowid: Int64) -> Void)?) { - guard let callback = callback else { + guard let callback else { sqlite3_update_hook(handle, nil, nil) updateHook = nil return @@ -535,7 +535,7 @@ public final class Connection { /// committed. If this callback throws, the transaction will be rolled /// back. public func commitHook(_ callback: (() throws -> Void)?) { - guard let callback = callback else { + guard let callback else { sqlite3_commit_hook(handle, nil, nil) commitHook = nil return @@ -562,7 +562,7 @@ public final class Connection { /// - Parameter callback: A callback invoked when a transaction is rolled /// back. public func rollbackHook(_ callback: (() -> Void)?) { - guard let callback = callback else { + guard let callback else { sqlite3_rollback_hook(handle, nil, nil) rollbackHook = nil return @@ -650,7 +650,7 @@ public final class Connection { try check(sqlite3_create_collation_v2(handle, collation, SQLITE_UTF8, unsafeBitCast(box, to: UnsafeMutableRawPointer.self), { (callback: UnsafeMutableRawPointer?, _, lhs: UnsafeRawPointer?, _, rhs: UnsafeRawPointer?) in /* xCompare */ - if let lhs = lhs, let rhs = rhs { + if let lhs, let rhs { return unsafeBitCast(callback, to: Collation.self)(lhs, rhs) } else { fatalError("sqlite3_create_collation_v2 callback called with NULL pointer") diff --git a/Sources/SQLite/Core/Result.swift b/Sources/SQLite/Core/Result.swift index 9fe47ada..ee59e5d1 100644 --- a/Sources/SQLite/Core/Result.swift +++ b/Sources/SQLite/Core/Result.swift @@ -51,13 +51,13 @@ extension Result: CustomStringConvertible { public var description: String { switch self { case let .error(message, errorCode, statement): - if let statement = statement { + if let statement { return "\(message) (\(statement)) (code: \(errorCode))" } else { return "\(message) (code: \(errorCode))" } case let .extendedError(message, extendedCode, statement): - if let statement = statement { + if let statement { return "\(message) (\(statement)) (extended code: \(extendedCode))" } else { return "\(message) (extended code: \(extendedCode))" diff --git a/Sources/SQLite/Extensions/FTS4.swift b/Sources/SQLite/Extensions/FTS4.swift index 8e91e453..c02cfdc1 100644 --- a/Sources/SQLite/Extensions/FTS4.swift +++ b/Sources/SQLite/Extensions/FTS4.swift @@ -98,7 +98,7 @@ public struct Tokenizer { separators: Set = []) -> Tokenizer { var arguments = [String]() - if let removeDiacritics = removeDiacritics { + if let removeDiacritics { arguments.append("remove_diacritics=\(removeDiacritics ? 1 : 0)".quote()) } @@ -208,13 +208,13 @@ open class FTSConfig { func options() -> Options { var options = Options() options.append(formatColumnDefinitions()) - if let tokenizer = tokenizer { + if let tokenizer { options.append("tokenize", value: Expression(literal: tokenizer.description)) } options.appendCommaSeparated("prefix", values: prefixes.sorted().map { String($0) }) if isContentless { options.append("content", value: "") - } else if let externalContentSchema = externalContentSchema { + } else if let externalContentSchema { options.append("content", value: externalContentSchema.tableName()) } return options @@ -306,19 +306,19 @@ open class FTS4Config: FTSConfig { for (column, _) in (columnDefinitions.filter { $0.options.contains(.unindexed) }) { options.append("notindexed", value: column) } - if let languageId = languageId { + if let languageId { options.append("languageid", value: languageId) } - if let compressFunction = compressFunction { + if let compressFunction { options.append("compress", value: compressFunction) } - if let uncompressFunction = uncompressFunction { + if let uncompressFunction { options.append("uncompress", value: uncompressFunction) } - if let matchInfo = matchInfo { + if let matchInfo { options.append("matchinfo", value: matchInfo.rawValue) } - if let order = order { + if let order { options.append("order", value: order.rawValue) } return options diff --git a/Sources/SQLite/Extensions/FTS5.swift b/Sources/SQLite/Extensions/FTS5.swift index 2e4f65fb..3e84e171 100644 --- a/Sources/SQLite/Extensions/FTS5.swift +++ b/Sources/SQLite/Extensions/FTS5.swift @@ -69,13 +69,13 @@ open class FTS5Config: FTSConfig { override func options() -> Options { var options = super.options() - if let contentRowId = contentRowId { + if let contentRowId { options.append("content_rowid", value: contentRowId) } - if let columnSize = columnSize { + if let columnSize { options.append("columnsize", value: Expression(value: columnSize)) } - if let detail = detail { + if let detail { options.append("detail", value: detail.rawValue) } return options diff --git a/Sources/SQLite/Helpers.swift b/Sources/SQLite/Helpers.swift index 79d057d6..adfadc8a 100644 --- a/Sources/SQLite/Helpers.swift +++ b/Sources/SQLite/Helpers.swift @@ -109,7 +109,7 @@ extension String { } func transcode(_ literal: Binding?) -> String { - guard let literal = literal else { return "NULL" } + guard let literal else { return "NULL" } switch literal { case let blob as Blob: diff --git a/Sources/SQLite/Schema/SchemaDefinitions.swift b/Sources/SQLite/Schema/SchemaDefinitions.swift index b314e5c0..2d38e1fb 100644 --- a/Sources/SQLite/Schema/SchemaDefinitions.swift +++ b/Sources/SQLite/Schema/SchemaDefinitions.swift @@ -170,7 +170,7 @@ public enum LiteralValue: Equatable, CustomStringConvertible { // swiftlint:enable identifier_name init(_ string: String?) { - guard let string = string else { + guard let string else { self = .NULL return } diff --git a/Sources/SQLite/Schema/SchemaReader.swift b/Sources/SQLite/Schema/SchemaReader.swift index 0c02ba9f..58a9b1bd 100644 --- a/Sources/SQLite/Schema/SchemaReader.swift +++ b/Sources/SQLite/Schema/SchemaReader.swift @@ -39,10 +39,10 @@ public class SchemaReader { type: ObjectDefinition.ObjectType? = nil, temp: Bool = false) throws -> [ObjectDefinition] { var query: QueryType = SchemaTable.get(for: connection, temp: temp) - if let name = name { + if let name { query = query.where(SchemaTable.nameColumn == name) } - if let type = type { + if let type { query = query.where(SchemaTable.typeColumn == type.rawValue) } return try connection.prepare(query).map { row -> ObjectDefinition in diff --git a/Sources/SQLite/Typed/Coding.swift b/Sources/SQLite/Typed/Coding.swift index b96bc64e..e7db03fb 100644 --- a/Sources/SQLite/Typed/Coding.swift +++ b/Sources/SQLite/Typed/Coding.swift @@ -215,7 +215,7 @@ private class SQLiteEncoder: Encoder { } func encodeIfPresent(_ value: Int?, forKey key: SQLiteEncoder.SQLiteKeyedEncodingContainer.Key) throws { - if let value = value { + if let value { try encode(value, forKey: key) } else if forcingNilValueSetters { encoder.setters.append(Expression(key.stringValue) <- nil) @@ -223,7 +223,7 @@ private class SQLiteEncoder: Encoder { } func encodeIfPresent(_ value: Bool?, forKey key: Key) throws { - if let value = value { + if let value { try encode(value, forKey: key) } else if forcingNilValueSetters { encoder.setters.append(Expression(key.stringValue) <- nil) @@ -231,7 +231,7 @@ private class SQLiteEncoder: Encoder { } func encodeIfPresent(_ value: Float?, forKey key: Key) throws { - if let value = value { + if let value { try encode(value, forKey: key) } else if forcingNilValueSetters { encoder.setters.append(Expression(key.stringValue) <- nil) @@ -239,7 +239,7 @@ private class SQLiteEncoder: Encoder { } func encodeIfPresent(_ value: Double?, forKey key: Key) throws { - if let value = value { + if let value { try encode(value, forKey: key) } else if forcingNilValueSetters { encoder.setters.append(Expression(key.stringValue) <- nil) @@ -247,7 +247,7 @@ private class SQLiteEncoder: Encoder { } func encodeIfPresent(_ value: String?, forKey key: MyKey) throws { - if let value = value { + if let value { try encode(value, forKey: key) } else if forcingNilValueSetters { encoder.setters.append(Expression(key.stringValue) <- nil) @@ -270,7 +270,7 @@ private class SQLiteEncoder: Encoder { } func encodeIfPresent(_ value: T?, forKey key: Key) throws where T: Swift.Encodable { - guard let value = value else { + guard let value else { guard forcingNilValueSetters else { return } diff --git a/Sources/SQLite/Typed/CoreFunctions.swift b/Sources/SQLite/Typed/CoreFunctions.swift index dc6a1044..4429bb5f 100644 --- a/Sources/SQLite/Typed/CoreFunctions.swift +++ b/Sources/SQLite/Typed/CoreFunctions.swift @@ -100,7 +100,7 @@ extension ExpressionType where UnderlyingType == Double { /// /// - Returns: A copy of the expression wrapped with the `round` function. public func round(_ precision: Int? = nil) -> Expression { - guard let precision = precision else { + guard let precision else { return Function.round.wrap([self]) } return Function.round.wrap([self, Int(precision)]) @@ -120,7 +120,7 @@ extension ExpressionType where UnderlyingType == Double? { /// /// - Returns: A copy of the expression wrapped with the `round` function. public func round(_ precision: Int? = nil) -> Expression { - guard let precision = precision else { + guard let precision else { return Function.round.wrap(self) } return Function.round.wrap([self, Int(precision)]) @@ -250,7 +250,7 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression appended with a `LIKE` query against /// the given pattern. public func like(_ pattern: String, escape character: Character? = nil) -> Expression { - guard let character = character else { + guard let character else { return "LIKE".infix(self, pattern) } return Expression("(\(template) LIKE ? ESCAPE ?)", bindings + [pattern, String(character)]) @@ -274,7 +274,7 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression appended with a `LIKE` query against /// the given pattern. public func like(_ pattern: Expression, escape character: Character? = nil) -> Expression { - guard let character = character else { + guard let character else { return Function.like.infix(self, pattern) } let like: Expression = Function.like.infix(self, pattern, wrap: false) @@ -349,7 +349,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression wrapped with the `ltrim` function. public func ltrim(_ characters: Set? = nil) -> Expression { - guard let characters = characters else { + guard let characters else { return Function.ltrim.wrap(self) } return Function.ltrim.wrap([self, String(characters)]) @@ -367,7 +367,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression wrapped with the `rtrim` function. public func rtrim(_ characters: Set? = nil) -> Expression { - guard let characters = characters else { + guard let characters else { return Function.rtrim.wrap(self) } return Function.rtrim.wrap([self, String(characters)]) @@ -385,7 +385,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression wrapped with the `trim` function. public func trim(_ characters: Set? = nil) -> Expression { - guard let characters = characters else { + guard let characters else { return Function.trim.wrap([self]) } return Function.trim.wrap([self, String(characters)]) @@ -409,7 +409,7 @@ extension ExpressionType where UnderlyingType == String { } public func substring(_ location: Int, length: Int? = nil) -> Expression { - guard let length = length else { + guard let length else { return Function.substr.wrap([self, location]) } return Function.substr.wrap([self, location, length]) @@ -475,7 +475,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression appended with a `LIKE` query against /// the given pattern. public func like(_ pattern: String, escape character: Character? = nil) -> Expression { - guard let character = character else { + guard let character else { return Function.like.infix(self, pattern) } return Expression("(\(template) LIKE ? ESCAPE ?)", bindings + [pattern, String(character)]) @@ -499,7 +499,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression appended with a `LIKE` query against /// the given pattern. public func like(_ pattern: Expression, escape character: Character? = nil) -> Expression { - guard let character = character else { + guard let character else { return Function.like.infix(self, pattern) } let like: Expression = Function.like.infix(self, pattern, wrap: false) @@ -574,7 +574,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `ltrim` function. public func ltrim(_ characters: Set? = nil) -> Expression { - guard let characters = characters else { + guard let characters else { return Function.ltrim.wrap(self) } return Function.ltrim.wrap([self, String(characters)]) @@ -592,7 +592,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `rtrim` function. public func rtrim(_ characters: Set? = nil) -> Expression { - guard let characters = characters else { + guard let characters else { return Function.rtrim.wrap(self) } return Function.rtrim.wrap([self, String(characters)]) @@ -610,7 +610,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `trim` function. public func trim(_ characters: Set? = nil) -> Expression { - guard let characters = characters else { + guard let characters else { return Function.trim.wrap(self) } return Function.trim.wrap([self, String(characters)]) @@ -649,7 +649,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `substr` function. public func substring(_ location: Int, length: Int? = nil) -> Expression { - guard let length = length else { + guard let length else { return Function.substr.wrap([self, location]) } return Function.substr.wrap([self, location, length]) @@ -726,7 +726,7 @@ extension String { /// - Returns: A copy of the expression appended with a `LIKE` query against /// the given pattern. public func like(_ pattern: Expression, escape character: Character? = nil) -> Expression { - guard let character = character else { + guard let character else { return Function.like.infix(self, pattern) } let like: Expression = Function.like.infix(self, pattern, wrap: false) diff --git a/Sources/SQLite/Typed/Operators.swift b/Sources/SQLite/Typed/Operators.swift index 5ffbbceb..1c611cbc 100644 --- a/Sources/SQLite/Typed/Operators.swift +++ b/Sources/SQLite/Typed/Operators.swift @@ -367,14 +367,14 @@ public func ==(lhs: Expression, rhs: V) -> Expression where V Operator.eq.infix(lhs, rhs) } public func ==(lhs: Expression, rhs: V?) -> Expression where V.Datatype: Equatable { - guard let rhs = rhs else { return "IS".infix(lhs, Expression(value: nil)) } + guard let rhs else { return "IS".infix(lhs, Expression(value: nil)) } return Operator.eq.infix(lhs, rhs) } public func ==(lhs: V, rhs: Expression) -> Expression where V.Datatype: Equatable { Operator.eq.infix(lhs, rhs) } public func ==(lhs: V?, rhs: Expression) -> Expression where V.Datatype: Equatable { - guard let lhs = lhs else { return "IS".infix(Expression(value: nil), rhs) } + guard let lhs else { return "IS".infix(Expression(value: nil), rhs) } return Operator.eq.infix(lhs, rhs) } @@ -394,14 +394,14 @@ public func ===(lhs: Expression, rhs: V) -> Expression where "IS".infix(lhs, rhs) } public func ===(lhs: Expression, rhs: V?) -> Expression where V.Datatype: Equatable { - guard let rhs = rhs else { return "IS".infix(lhs, Expression(value: nil)) } + guard let rhs else { return "IS".infix(lhs, Expression(value: nil)) } return "IS".infix(lhs, rhs) } public func ===(lhs: V, rhs: Expression) -> Expression where V.Datatype: Equatable { "IS".infix(lhs, rhs) } public func ===(lhs: V?, rhs: Expression) -> Expression where V.Datatype: Equatable { - guard let lhs = lhs else { return "IS".infix(Expression(value: nil), rhs) } + guard let lhs else { return "IS".infix(Expression(value: nil), rhs) } return "IS".infix(lhs, rhs) } @@ -421,14 +421,14 @@ public func !=(lhs: Expression, rhs: V) -> Expression where V Operator.neq.infix(lhs, rhs) } public func !=(lhs: Expression, rhs: V?) -> Expression where V.Datatype: Equatable { - guard let rhs = rhs else { return "IS NOT".infix(lhs, Expression(value: nil)) } + guard let rhs else { return "IS NOT".infix(lhs, Expression(value: nil)) } return Operator.neq.infix(lhs, rhs) } public func !=(lhs: V, rhs: Expression) -> Expression where V.Datatype: Equatable { Operator.neq.infix(lhs, rhs) } public func !=(lhs: V?, rhs: Expression) -> Expression where V.Datatype: Equatable { - guard let lhs = lhs else { return "IS NOT".infix(Expression(value: nil), rhs) } + guard let lhs else { return "IS NOT".infix(Expression(value: nil), rhs) } return Operator.neq.infix(lhs, rhs) } @@ -448,14 +448,14 @@ public func !==(lhs: Expression, rhs: V) -> Expression where "IS NOT".infix(lhs, rhs) } public func !==(lhs: Expression, rhs: V?) -> Expression where V.Datatype: Equatable { - guard let rhs = rhs else { return "IS NOT".infix(lhs, Expression(value: nil)) } + guard let rhs else { return "IS NOT".infix(lhs, Expression(value: nil)) } return "IS NOT".infix(lhs, rhs) } public func !==(lhs: V, rhs: Expression) -> Expression where V.Datatype: Equatable { "IS NOT".infix(lhs, rhs) } public func !==(lhs: V?, rhs: Expression) -> Expression where V.Datatype: Equatable { - guard let lhs = lhs else { return "IS NOT".infix(Expression(value: nil), rhs) } + guard let lhs else { return "IS NOT".infix(Expression(value: nil), rhs) } return "IS NOT".infix(lhs, rhs) } From 6aab9fcdc27c97f04b4153589908ec871b17ba55 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Mon, 22 May 2023 00:56:52 +0200 Subject: [PATCH 11/11] Re-enable watch tests --- run-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index c54300ee..49330c12 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -8,9 +8,9 @@ if [ -n "$BUILD_SCHEME" ]; then fi elif [ -n "$VALIDATOR_SUBSPEC" ]; then if [ "$VALIDATOR_SUBSPEC" == "none" ]; then - pod lib lint --no-subspecs --fail-fast --platforms=ios,osx,tvos + pod lib lint --no-subspecs --fail-fast else - pod lib lint --subspec="${VALIDATOR_SUBSPEC}" --fail-fast --platforms=ios,osx,tvos + pod lib lint --subspec="${VALIDATOR_SUBSPEC}" --fail-fast fi elif [ -n "$CARTHAGE_PLATFORM" ]; then cd Tests/Carthage && make test CARTHAGE_PLATFORM="$CARTHAGE_PLATFORM"