Skip to content

Commit 6f3eef7

Browse files
committed
Basic R*Tree module support
Signed-off-by: Stephen Celis <stephen@stephencelis.com>
1 parent c82559f commit 6f3eef7

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

SQLite Tests/RTreeTests.swift

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import XCTest
2+
import SQLite
3+
4+
class RTreeTests: XCTestCase {
5+
6+
let id = Expression<Int64>("id")
7+
let minX = Expression<Double>("minX")
8+
let maxX = Expression<Double>("maxX")
9+
let minY = Expression<Double>("minY")
10+
let maxY = Expression<Double>("maxY")
11+
12+
let db = Database()
13+
var index: Query { return db["index"] }
14+
15+
func test_createVtable_usingRtree_createsVirtualTable() {
16+
ExpectExecution(db, "CREATE VIRTUAL TABLE \"index\" USING rtree(\"id\", \"minX\", \"maxX\", \"minY\", \"maxY\")", db.create(vtable: index, using: rtree(id, minX, maxX, minY, maxY)))
17+
}
18+
19+
}

SQLite.xcodeproj/project.pbxproj

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
DCAFEAD31AABC818000C21A1 /* FTS.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAFEAD21AABC818000C21A1 /* FTS.swift */; };
2626
DCAFEAD41AABC818000C21A1 /* FTS.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAFEAD21AABC818000C21A1 /* FTS.swift */; };
2727
DCAFEAD71AABEFA7000C21A1 /* FTSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAFEAD61AABEFA7000C21A1 /* FTSTests.swift */; };
28+
DCBE28411ABDF18F0042A3FC /* RTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCBE28401ABDF18F0042A3FC /* RTree.swift */; };
29+
DCBE28421ABDF18F0042A3FC /* RTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCBE28401ABDF18F0042A3FC /* RTree.swift */; };
30+
DCBE28451ABDF2A80042A3FC /* RTreeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCBE28441ABDF2A80042A3FC /* RTreeTests.swift */; };
2831
DCC6B36F1A9191C300734B78 /* Query.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAD429619E2E0F1004A51DF /* Query.swift */; };
2932
DCC6B3701A9191C300734B78 /* Statement.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC37743A19C8D6C0004FCF85 /* Statement.swift */; };
3033
DCC6B3711A9191C300734B78 /* Expression.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC650B9519F0CDC3002FBE91 /* Expression.swift */; };
@@ -106,6 +109,8 @@
106109
DCAD429919E2EE50004A51DF /* QueryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryTests.swift; sourceTree = "<group>"; };
107110
DCAFEAD21AABC818000C21A1 /* FTS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS.swift; sourceTree = "<group>"; };
108111
DCAFEAD61AABEFA7000C21A1 /* FTSTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTSTests.swift; sourceTree = "<group>"; };
112+
DCBE28401ABDF18F0042A3FC /* RTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RTree.swift; sourceTree = "<group>"; };
113+
DCBE28441ABDF2A80042A3FC /* RTreeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RTreeTests.swift; sourceTree = "<group>"; };
109114
DCC6B3801A9191C300734B78 /* SQLite.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SQLite.framework; sourceTree = BUILT_PRODUCTS_DIR; };
110115
DCC6B3921A9191D100734B78 /* SQLiteCipher Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SQLiteCipher Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
111116
DCC6B3961A91938F00734B78 /* sqlcipher.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = sqlcipher.xcodeproj; path = sqlcipher/sqlcipher.xcodeproj; sourceTree = "<group>"; };
@@ -161,6 +166,7 @@
161166
DCAD429619E2E0F1004A51DF /* Query.swift */,
162167
DC109CE01A0C4D970070988E /* Schema.swift */,
163168
DCAFEAD21AABC818000C21A1 /* FTS.swift */,
169+
DCBE28401ABDF18F0042A3FC /* RTree.swift */,
164170
);
165171
name = "Query Building";
166172
sourceTree = "<group>";
@@ -186,6 +192,7 @@
186192
DCAD429919E2EE50004A51DF /* QueryTests.swift */,
187193
DC109CE31A0C4F5D0070988E /* SchemaTests.swift */,
188194
DCAFEAD61AABEFA7000C21A1 /* FTSTests.swift */,
195+
DCBE28441ABDF2A80042A3FC /* RTreeTests.swift */,
189196
DC37740319C8CBB3004FCF85 /* Supporting Files */,
190197
);
191198
path = "SQLite Tests";
@@ -477,6 +484,7 @@
477484
DC37743B19C8D6C0004FCF85 /* Statement.swift in Sources */,
478485
DC37743819C8D693004FCF85 /* Value.swift in Sources */,
479486
DC650B9619F0CDC3002FBE91 /* Expression.swift in Sources */,
487+
DCBE28411ABDF18F0042A3FC /* RTree.swift in Sources */,
480488
DCAD429719E2E0F1004A51DF /* Query.swift in Sources */,
481489
DC109CE11A0C4D970070988E /* Schema.swift in Sources */,
482490
DCC6B3A81A91975700734B78 /* Functions.swift in Sources */,
@@ -496,6 +504,7 @@
496504
DCAD429A19E2EE50004A51DF /* QueryTests.swift in Sources */,
497505
DC109CE41A0C4F5D0070988E /* SchemaTests.swift in Sources */,
498506
DCC6B3A71A91974B00734B78 /* FunctionsTests.swift in Sources */,
507+
DCBE28451ABDF2A80042A3FC /* RTreeTests.swift in Sources */,
499508
);
500509
runOnlyForDeploymentPostprocessing = 0;
501510
};
@@ -512,6 +521,7 @@
512521
DCC6B3A91A91975C00734B78 /* Functions.swift in Sources */,
513522
DCAFEAD41AABC818000C21A1 /* FTS.swift in Sources */,
514523
DCC6B3751A9191C300734B78 /* SQLite-Bridging.c in Sources */,
524+
DCBE28421ABDF18F0042A3FC /* RTree.swift in Sources */,
515525
DCC6B3A41A9194A800734B78 /* Cipher.swift in Sources */,
516526
);
517527
runOnlyForDeploymentPostprocessing = 0;

SQLite/RTree.swift

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// SQLite.swift
3+
// https://github.com/stephencelis/SQLite.swift
4+
// Copyright (c) 2014-2015 Stephen Celis.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
//
24+
25+
public func rtree<T: Value, U: Value where T.Datatype == Int64, U.Datatype == Double>(primaryKey: Expression<T>, columns: Expression<U>...) -> Expression<()> {
26+
var definitions: [Expressible] = [primaryKey]
27+
definitions.extend(columns.map { $0 })
28+
return wrap(__FUNCTION__, Expression<()>.join(", ", definitions))
29+
}

0 commit comments

Comments
 (0)