Skip to content

Commit 993295a

Browse files
committed
Don't use qualified table name when creating an index
1 parent b43a31f commit 993295a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

SQLite/Typed/Query.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,13 @@ extension QueryType {
744744
])
745745
}
746746

747+
func tableName(qualified qualified: Bool) -> Expressible {
748+
if qualified {
749+
return tableName()
750+
}
751+
return Expression<Void>(clauses.from.alias ?? clauses.from.name)
752+
}
753+
747754
func database(namespace name: String) -> Expressible {
748755
let name = Expression<Void>(name)
749756

SQLite/Typed/Schema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ extension Table {
134134
let clauses: [Expressible?] = [
135135
create("INDEX", indexName(columns), unique ? .Unique : nil, ifNotExists),
136136
Expression<Void>(literal: "ON"),
137-
tableName(),
137+
tableName(qualified: false),
138138
"".wrap(columns) as Expression<Void>
139139
]
140140

SQLiteTests/SchemaTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,10 @@ class SchemaTests : XCTestCase {
724724
"CREATE UNIQUE INDEX IF NOT EXISTS \"index_table_on_int64\" ON \"table\" (\"int64\")",
725725
table.createIndex([int64], unique: true, ifNotExists: true)
726726
)
727+
XCTAssertEqual(
728+
"CREATE UNIQUE INDEX IF NOT EXISTS \"main\".\"index_table_on_int64\" ON \"table\" (\"int64\")",
729+
Table("table", database: "main").createIndex([int64], unique: true, ifNotExists: true)
730+
)
727731
}
728732

729733
func test_dropIndex_compilesCreateIndexExpression() {

0 commit comments

Comments
 (0)