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

fix create/drop index functions #666

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BUILD_TOOL = xcodebuild
BUILD_SCHEME = SQLite Mac
IOS_SIMULATOR = iPhone 6s
IOS_VERSION = 10.3
IOS_VERSION = 10.3.1
ifeq ($(BUILD_SCHEME),SQLite iOS)
BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" -destination "platform=iOS Simulator,name=$(IOS_SIMULATOR),OS=$(IOS_VERSION)"
else
Expand Down
12 changes: 2 additions & 10 deletions Sources/SQLite/Typed/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ extension Table {

// MARK: - CREATE INDEX

public func createIndex(_ columns: Expressible...) -> String {
return createIndex(columns)
}

public func createIndex(_ columns: [Expressible], unique: Bool = false, ifNotExists: Bool = false) -> String {
public func createIndex(_ columns: Expressible..., unique: Bool = false, ifNotExists: Bool = false) -> String {
let clauses: [Expressible?] = [
create("INDEX", indexName(columns), unique ? .unique : nil, ifNotExists),
Expression<Void>(literal: "ON"),
Expand All @@ -144,11 +140,7 @@ extension Table {

// MARK: - DROP INDEX

public func dropIndex(_ columns: Expressible...) -> String {
return dropIndex(columns)
}

public func dropIndex(_ columns: [Expressible], ifExists: Bool = false) -> String {
public func dropIndex(_ columns: Expressible..., ifExists: Bool = false) -> String {
return drop("INDEX", indexName(columns), ifExists)
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/SQLiteTests/SchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -727,25 +727,25 @@ class SchemaTests : XCTestCase {

XCTAssertEqual(
"CREATE UNIQUE INDEX \"index_table_on_int64\" ON \"table\" (\"int64\")",
table.createIndex([int64], unique: true)
table.createIndex(int64, unique: true)
)
XCTAssertEqual(
"CREATE INDEX IF NOT EXISTS \"index_table_on_int64\" ON \"table\" (\"int64\")",
table.createIndex([int64], ifNotExists: true)
table.createIndex(int64, ifNotExists: true)
)
XCTAssertEqual(
"CREATE UNIQUE INDEX IF NOT EXISTS \"index_table_on_int64\" ON \"table\" (\"int64\")",
table.createIndex([int64], unique: true, ifNotExists: true)
table.createIndex(int64, unique: true, ifNotExists: true)
)
XCTAssertEqual(
"CREATE UNIQUE INDEX IF NOT EXISTS \"main\".\"index_table_on_int64\" ON \"table\" (\"int64\")",
qualifiedTable.createIndex([int64], unique: true, ifNotExists: true)
qualifiedTable.createIndex(int64, unique: true, ifNotExists: true)
)
}

func test_dropIndex_compilesCreateIndexExpression() {
XCTAssertEqual("DROP INDEX \"index_table_on_int64\"", table.dropIndex(int64))
XCTAssertEqual("DROP INDEX IF EXISTS \"index_table_on_int64\"", table.dropIndex([int64], ifExists: true))
XCTAssertEqual("DROP INDEX IF EXISTS \"index_table_on_int64\"", table.dropIndex(int64, ifExists: true))
}

func test_create_onView_compilesCreateViewExpression() {
Expand Down