Skip to content

Commit c64dbd1

Browse files
authored
Merge branch 'master' into master
2 parents 0a35c18 + 0ff5262 commit c64dbd1

19 files changed

+858
-24
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ before_install:
66
- gem install xcpretty --no-document
77
script:
88
- make test
9+
- cd CocoaPodsTests && make test
910
osx_image: xcode7.3

CocoaPodsTests/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gems/

CocoaPodsTests/Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'cocoapods'
4+
gem 'minitest'

CocoaPodsTests/Gemfile.lock

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
activesupport (4.2.6)
5+
i18n (~> 0.7)
6+
json (~> 1.7, >= 1.7.7)
7+
minitest (~> 5.1)
8+
thread_safe (~> 0.3, >= 0.3.4)
9+
tzinfo (~> 1.1)
10+
claide (1.0.0)
11+
cocoapods (1.0.0)
12+
activesupport (>= 4.0.2)
13+
claide (>= 1.0.0, < 2.0)
14+
cocoapods-core (= 1.0.0)
15+
cocoapods-deintegrate (>= 1.0.0, < 2.0)
16+
cocoapods-downloader (>= 1.0.0, < 2.0)
17+
cocoapods-plugins (>= 1.0.0, < 2.0)
18+
cocoapods-search (>= 1.0.0, < 2.0)
19+
cocoapods-stats (>= 1.0.0, < 2.0)
20+
cocoapods-trunk (>= 1.0.0, < 2.0)
21+
cocoapods-try (>= 1.0.0, < 2.0)
22+
colored (~> 1.2)
23+
escape (~> 0.0.4)
24+
fourflusher (~> 0.3.0)
25+
molinillo (~> 0.4.5)
26+
nap (~> 1.0)
27+
xcodeproj (>= 1.0.0, < 2.0)
28+
cocoapods-core (1.0.0)
29+
activesupport (>= 4.0.2)
30+
fuzzy_match (~> 2.0.4)
31+
nap (~> 1.0)
32+
cocoapods-deintegrate (1.0.0)
33+
cocoapods-downloader (1.0.0)
34+
cocoapods-plugins (1.0.0)
35+
nap
36+
cocoapods-search (1.0.0)
37+
cocoapods-stats (1.0.0)
38+
cocoapods-trunk (1.0.0)
39+
nap (>= 0.8, < 2.0)
40+
netrc (= 0.7.8)
41+
cocoapods-try (1.0.0)
42+
colored (1.2)
43+
escape (0.0.4)
44+
fourflusher (0.3.0)
45+
fuzzy_match (2.0.4)
46+
i18n (0.7.0)
47+
json (1.8.3)
48+
minitest (5.8.4)
49+
molinillo (0.4.5)
50+
nap (1.1.0)
51+
netrc (0.7.8)
52+
thread_safe (0.3.5)
53+
tzinfo (1.2.2)
54+
thread_safe (~> 0.1)
55+
xcodeproj (1.0.0)
56+
activesupport (>= 3)
57+
claide (>= 1.0.0, < 2.0)
58+
colored (~> 1.2)
59+
60+
PLATFORMS
61+
ruby
62+
63+
DEPENDENCIES
64+
cocoapods
65+
minitest

CocoaPodsTests/Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
test: install
2+
@set -e; \
3+
for test in *_test.rb; do \
4+
bundle exec ./$$test; \
5+
done
6+
7+
install:
8+
@bundle install --path gems
9+
10+
.PHONY: test install

CocoaPodsTests/integration_test.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'minitest/autorun'
4+
require_relative 'test_running_validator'
5+
6+
class IntegrationTest < Minitest::Test
7+
8+
def test_validate_project
9+
assert validator.validate, "validation failed: #{validator.failure_reason}"
10+
end
11+
12+
private
13+
14+
def validator
15+
@validator ||= TestRunningValidator.new(podspec, []).tap do |validator|
16+
validator.test_files = Dir["#{project_test_dir}/*.swift"]
17+
validator.config.verbose = true
18+
validator.no_clean = true
19+
validator.use_frameworks = true
20+
validator.fail_fast = true
21+
validator.local = true
22+
validator.allow_warnings = true
23+
end
24+
end
25+
26+
def podspec
27+
File.expand_path(File.dirname(__FILE__) + '/../SQLite.swift.podspec')
28+
end
29+
30+
def project_test_dir
31+
File.expand_path(File.dirname(__FILE__) + '/../SQLiteTests')
32+
end
33+
end
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
require 'cocoapods'
2+
require 'cocoapods/validator'
3+
require 'fileutils'
4+
5+
class TestRunningValidator < Pod::Validator
6+
APP_TARGET = 'App'
7+
TEST_TARGET = 'Tests'
8+
9+
attr_accessor :test_files
10+
11+
def create_app_project
12+
super.tap do
13+
project = Xcodeproj::Project.open(validation_dir + "#{APP_TARGET}.xcodeproj")
14+
create_test_target(project)
15+
end
16+
end
17+
18+
def install_pod
19+
super.tap do
20+
if local?
21+
FileUtils.ln_s file.dirname, validation_dir + "Pods/#{spec.name}"
22+
end
23+
end
24+
end
25+
26+
def podfile_from_spec(*args)
27+
super(*args).tap do |pod_file|
28+
add_test_target(pod_file)
29+
end
30+
end
31+
32+
def build_pod
33+
super
34+
Pod::UI.message "\Testing with xcodebuild.\n".yellow do
35+
run_tests
36+
end
37+
end
38+
39+
private
40+
def create_test_target(project)
41+
test_target = project.new_target(:unit_test_bundle, TEST_TARGET, consumer.platform_name, deployment_target)
42+
group = project.new_group(TEST_TARGET)
43+
test_target.add_file_references(test_files.map { |file| group.new_file(file) })
44+
project.save
45+
create_test_scheme(project, test_target)
46+
project
47+
end
48+
49+
def create_test_scheme(project, test_target)
50+
project.recreate_user_schemes
51+
test_scheme = Xcodeproj::XCScheme.new(test_scheme_path(project))
52+
test_scheme.add_test_target(test_target)
53+
test_scheme.save!
54+
end
55+
56+
def test_scheme_path(project)
57+
Xcodeproj::XCScheme.user_data_dir(project.path) + "#{TEST_TARGET}.xcscheme"
58+
end
59+
60+
def add_test_target(pod_file)
61+
app_target = pod_file.target_definitions[APP_TARGET]
62+
Pod::Podfile::TargetDefinition.new(TEST_TARGET, app_target)
63+
end
64+
65+
def run_tests
66+
command = %W(clean test -workspace #{APP_TARGET}.xcworkspace -scheme #{TEST_TARGET} -configuration Debug)
67+
case consumer.platform_name
68+
when :ios
69+
command += %w(CODE_SIGN_IDENTITY=- -sdk iphonesimulator)
70+
command += Fourflusher::SimControl.new.destination('iPhone 4s', deployment_target)
71+
when :osx
72+
command += %w(LD_RUNPATH_SEARCH_PATHS=@loader_path/../Frameworks)
73+
when :tvos
74+
command += %w(CODE_SIGN_IDENTITY=- -sdk appletvsimulator)
75+
command += Fourflusher::SimControl.new.destination('Apple TV 1080p', deployment_target)
76+
else
77+
return # skip watchos
78+
end
79+
80+
output, status = Dir.chdir(validation_dir) { _xcodebuild(command) }
81+
unless status.success?
82+
message = 'Returned an unsuccessful exit code.'
83+
if config.verbose?
84+
message += "\nXcode output: \n#{output}\n"
85+
else
86+
message += ' You can use `--verbose` for more information.'
87+
end
88+
error('xcodebuild', message)
89+
end
90+
end
91+
end

Documentation/Index.md

+50
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,26 @@ install SQLite.swift with Carthage:
111111
112112
3. Run `pod install`.
113113
114+
#### Requiring a specific version of SQLite
115+
116+
If you want to use a more recent version of SQLite than what is provided with the OS you can require the `standalone` subspec:
117+
118+
``` ruby
119+
pod 'SQLite.swift/standalone', '~> 0.10.1'
120+
```
121+
122+
By default this will use the most recent version of SQLite without any extras. If you want you can further customize this by adding another dependency to sqlite3 or one of its subspecs:
123+
124+
``` ruby
125+
pod 'SQLite.swift/standalone', '~> 0.10.1'
126+
pod 'sqlite3/fts5', '= 3.11.1' # SQLite 3.11.1 with FTS5 enabled
127+
```
128+
129+
See the [sqlite3 podspec][sqlite3pod] for more details.
130+
114131
[CocoaPods]: https://cocoapods.org
115132
[CocoaPods Installation]: https://guides.cocoapods.org/using/getting-started.html#getting-started
133+
[sqlite3pod]: https://github.com/clemensg/sqlite3pod
116134

117135

118136
### Manual
@@ -1381,6 +1399,22 @@ try db.run(emails.create(.FTS4([subject, body], tokenize: .Porter)))
13811399
// CREATE VIRTUAL TABLE "emails" USING fts4("subject", "body", tokenize=porter)
13821400
```
13831401

1402+
We can set the full range of parameters by creating a `FTS4Config` object.
1403+
1404+
``` swift
1405+
let emails = VirtualTable("emails")
1406+
let subject = Expression<String>("subject")
1407+
let body = Expression<String>("body")
1408+
let config = FTS4Config()
1409+
.column(subject)
1410+
.column(body, [.unindexed])
1411+
.languageId("lid")
1412+
.order(.Desc)
1413+
1414+
try db.run(emails.create(.FTS4(config))
1415+
// CREATE VIRTUAL TABLE "emails" USING fts4("subject", "body", notindexed="body", languageid="lid", order="desc")
1416+
```
1417+
13841418
Once we insert a few rows, we can search using the `match` function, which takes a table or column as its first argument and a query string as its second.
13851419

13861420
``` swift
@@ -1396,6 +1430,22 @@ let replies = emails.filter(subject.match("Re:*"))
13961430
// SELECT * FROM "emails" WHERE "subject" MATCH 'Re:*'
13971431
```
13981432

1433+
### FTS5
1434+
1435+
When linking against a version of SQLite with [FTS5](http://www.sqlite.org/fts5.html) enabled we can create the virtual table
1436+
in a similar fashion.
1437+
1438+
```swift
1439+
let emails = VirtualTable("emails")
1440+
let subject = Expression<String>("subject")
1441+
let body = Expression<String>("body")
1442+
let config = FTS5Config()
1443+
.column(subject)
1444+
.column(body, [.unindexed])
1445+
1446+
try db.run(emails.create(.FTS5(config))
1447+
// CREATE VIRTUAL TABLE "emails" USING fts5("subject", "body" UNINDEXED)
1448+
```
13991449

14001450
## Executing Arbitrary SQL
14011451

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ These projects enhance or use SQLite.swift:
230230
Looking for something else? Try another Swift wrapper (or [FMDB][]):
231231
232232
- [Camembert](https://github.com/remirobert/Camembert)
233-
- [EonilSQLite3](https://github.com/Eonil/SQLite3)
233+
- [GRDB](https://github.com/groue/GRDB.swift)
234234
- [SQLiteDB](https://github.com/FahimF/SQLiteDB)
235235
- [Squeal](https://github.com/nerdyc/Squeal)
236236
- [SwiftData](https://github.com/ryanfowler/SwiftData)

SQLite.swift.podspec

+25-14
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,30 @@ Pod::Spec.new do |s|
2424
s.tvos.deployment_target = "9.0"
2525
s.osx.deployment_target = "10.9"
2626
s.watchos.deployment_target = "2.0"
27+
s.default_subspec = 'standard'
2728

28-
s.preserve_paths = 'CocoaPods/**/*'
29-
s.pod_target_xcconfig = {
30-
'SWIFT_INCLUDE_PATHS[sdk=macosx*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/macosx',
31-
'SWIFT_INCLUDE_PATHS[sdk=iphoneos*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/iphoneos',
32-
'SWIFT_INCLUDE_PATHS[sdk=iphonesimulator*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/iphonesimulator',
33-
'SWIFT_INCLUDE_PATHS[sdk=appletvos*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/appletvos',
34-
'SWIFT_INCLUDE_PATHS[sdk=appletvsimulator*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/appletvsimulator',
35-
'SWIFT_INCLUDE_PATHS[sdk=watchos*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/watchos',
36-
'SWIFT_INCLUDE_PATHS[sdk=watchsimulator*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/watchsimulator'
37-
}
38-
39-
s.libraries = 'sqlite3'
40-
s.source_files = 'SQLite/**/*.{c,h,m,swift}'
41-
s.private_header_files = 'SQLite/Core/fts3_tokenizer.h'
29+
s.subspec 'standard' do |ss|
30+
ss.source_files = 'SQLite/**/*.{c,h,m,swift}'
31+
ss.private_header_files = 'SQLite/Core/fts3_tokenizer.h'
32+
33+
ss.library = 'sqlite3'
34+
ss.preserve_paths = 'CocoaPods/**/*'
35+
ss.pod_target_xcconfig = {
36+
'SWIFT_INCLUDE_PATHS[sdk=macosx*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/macosx',
37+
'SWIFT_INCLUDE_PATHS[sdk=iphoneos*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/iphoneos',
38+
'SWIFT_INCLUDE_PATHS[sdk=iphonesimulator*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/iphonesimulator',
39+
'SWIFT_INCLUDE_PATHS[sdk=appletvos*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/appletvos',
40+
'SWIFT_INCLUDE_PATHS[sdk=appletvsimulator*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/appletvsimulator',
41+
'SWIFT_INCLUDE_PATHS[sdk=watchos*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/watchos',
42+
'SWIFT_INCLUDE_PATHS[sdk=watchsimulator*]' => '$(SRCROOT)/SQLite.swift/CocoaPods/watchsimulator'
43+
}
44+
end
45+
46+
s.subspec 'standalone' do |ss|
47+
ss.source_files = 'SQLite/**/*.{c,h,m,swift}'
48+
ss.private_header_files = 'SQLite/Core/fts3_tokenizer.h'
49+
ss.xcconfig = { 'OTHER_SWIFT_FLAGS' => '$(inherited) -DSQLITE_SWIFT_STANDALONE' }
50+
51+
ss.dependency 'sqlite3'
52+
end
4253
end

0 commit comments

Comments
 (0)