From ee4b6c17d54e0587b3c2e8f7b614de656f44f205 Mon Sep 17 00:00:00 2001 From: tanner0101 Date: Fri, 22 Jun 2018 17:35:34 -0400 Subject: [PATCH 1/2] add CREATE and DROP index queries --- Sources/SQLite/SQL/SQLiteDropIndex.swift | 39 ++++++++++++++++++++++++ Sources/SQLite/SQL/SQLiteGeneric.swift | 8 +++++ Sources/SQLite/SQL/SQLiteQuery.swift | 24 +++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 Sources/SQLite/SQL/SQLiteDropIndex.swift diff --git a/Sources/SQLite/SQL/SQLiteDropIndex.swift b/Sources/SQLite/SQL/SQLiteDropIndex.swift new file mode 100644 index 0000000..2542672 --- /dev/null +++ b/Sources/SQLite/SQL/SQLiteDropIndex.swift @@ -0,0 +1,39 @@ +public struct SQLiteDropIndex: SQLDropIndex { + public var identifier: SQLiteIdentifier + + /// See `SQLSerializable`. + public func serialize(_ binds: inout [Encodable]) -> String { + var sql: [String] = [] + sql.append("DROP INDEX") + sql.append(identifier.serialize(&binds)) + return sql.joined(separator: " ") + } +} + +public final class SQLiteDropIndexBuilder: SQLQueryBuilder + where Connection: DatabaseQueryable, Connection.Query == SQLiteQuery +{ + /// `AlterTable` query being built. + public var dropIndex: SQLiteDropIndex + + /// See `SQLQueryBuilder`. + public var connection: Connection + + /// See `SQLQueryBuilder`. + public var query: SQLiteQuery { + return .dropIndex(dropIndex) + } + + /// Creates a new `SQLCreateIndexBuilder`. + public init(_ dropIndex: SQLiteDropIndex, on connection: Connection) { + self.dropIndex = dropIndex + self.connection = connection + } +} + + +extension DatabaseQueryable where Query == SQLiteQuery { + public func drop(index identifier: SQLiteIdentifier) -> SQLiteDropIndexBuilder { + return .init(SQLiteDropIndex(identifier: identifier), on: self) + } +} diff --git a/Sources/SQLite/SQL/SQLiteGeneric.swift b/Sources/SQLite/SQL/SQLiteGeneric.swift index c725bff..3c152c8 100644 --- a/Sources/SQLite/SQL/SQLiteGeneric.swift +++ b/Sources/SQLite/SQL/SQLiteGeneric.swift @@ -21,6 +21,11 @@ public typealias SQLiteColumnIdentifier = GenericSQLColumnIdentifier< SQLiteTableIdentifier, SQLiteIdentifier > +/// See `SQLQuery`. +public typealias SQLiteCreateIndex = GenericSQLCreateIndex< + SQLiteIndexModifier, SQLiteIdentifier, SQLiteTableIdentifier +> + /// See `SQLQuery`. public typealias SQLiteDelete = GenericSQLDelete< SQLiteTableIdentifier, SQLiteExpression @@ -54,6 +59,9 @@ public typealias SQLiteGroupBy = GenericSQLGroupBy /// See `SQLQuery`. public typealias SQLiteIdentifier = GenericSQLIdentifier +/// See `SQLQuery`. +public typealias SQLiteIndexModifier = GenericSQLIndexModifier + /// See `SQLQuery`. public typealias SQLiteInsert = GenericSQLInsert< SQLiteTableIdentifier, SQLiteColumnIdentifier, SQLiteExpression diff --git a/Sources/SQLite/SQL/SQLiteQuery.swift b/Sources/SQLite/SQL/SQLiteQuery.swift index 6e8456b..71d05b7 100644 --- a/Sources/SQLite/SQL/SQLiteQuery.swift +++ b/Sources/SQLite/SQL/SQLiteQuery.swift @@ -1,6 +1,9 @@ public enum SQLiteQuery: SQLQuery { /// See `SQLQuery`. public typealias AlterTable = SQLiteAlterTable + + /// See `SQLQuery`. + public typealias CreateIndex = SQLiteCreateIndex /// See `SQLQuery`. public typealias CreateTable = SQLiteCreateTable @@ -8,6 +11,9 @@ public enum SQLiteQuery: SQLQuery { /// See `SQLQuery`. public typealias Delete = SQLiteDelete + /// See `SQLQuery`. + public typealias DropIndex = SQLiteDropIndex + /// See `SQLQuery`. public typealias DropTable = SQLiteDropTable @@ -27,6 +33,11 @@ public enum SQLiteQuery: SQLQuery { public static func alterTable(_ alterTable: SQLiteAlterTable) -> SQLiteQuery { return ._alterTable(alterTable) } + + /// See `SQLQuery`. + public static func createIndex(_ createIndex: SQLiteCreateIndex) -> SQLiteQuery { + return ._createIndex(createIndex) + } /// See `SQLQuery`. public static func createTable(_ createTable: SQLiteCreateTable) -> SQLiteQuery { @@ -38,6 +49,11 @@ public enum SQLiteQuery: SQLQuery { return ._delete(delete) } + /// See `SQLQuery`. + public static func dropIndex(_ dropIndex: SQLiteDropIndex) -> SQLiteQuery { + return ._dropIndex(dropIndex) + } + /// See `SQLQuery`. public static func dropTable(_ dropTable: SQLiteDropTable) -> SQLiteQuery { return ._dropTable(dropTable) @@ -65,6 +81,9 @@ public enum SQLiteQuery: SQLQuery { /// See `SQLQuery`. case _alterTable(SQLiteAlterTable) + + /// See `SQLQuery`. + case _createIndex(SQLiteCreateIndex) /// See `SQLQuery`. case _createTable(SQLiteCreateTable) @@ -72,6 +91,9 @@ public enum SQLiteQuery: SQLQuery { /// See `SQLQuery`. case _delete(SQLiteDelete) + /// See `SQLQuery`. + case _dropIndex(SQLiteDropIndex) + /// See `SQLQuery`. case _dropTable(SQLiteDropTable) @@ -91,8 +113,10 @@ public enum SQLiteQuery: SQLQuery { public func serialize(_ binds: inout [Encodable]) -> String { switch self { case ._alterTable(let alterTable): return alterTable.serialize(&binds) + case ._createIndex(let createIndex): return createIndex.serialize(&binds) case ._createTable(let createTable): return createTable.serialize(&binds) case ._delete(let delete): return delete.serialize(&binds) + case ._dropIndex(let dropIndex): return dropIndex.serialize(&binds) case ._dropTable(let dropTable): return dropTable.serialize(&binds) case ._insert(let insert): return insert.serialize(&binds) case ._select(let select): return select.serialize(&binds) From 045d010a84ad82329aae93f7deff49afda253049 Mon Sep 17 00:00:00 2001 From: tanner0101 Date: Fri, 22 Jun 2018 18:24:49 -0400 Subject: [PATCH 2/2] cleanup circle.yml --- circle.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/circle.yml b/circle.yml index 8467fc2..bcdd080 100644 --- a/circle.yml +++ b/circle.yml @@ -1,14 +1,6 @@ version: 2 jobs: - macos: - macos: - xcode: "9.2" - steps: - - checkout - - run: swift build - - run: swift test - linux: docker: - image: codevapor/swift:4.1 @@ -20,7 +12,6 @@ jobs: - run: name: Run unit tests command: swift test - linux-release: docker: - image: codevapor/swift:4.1 @@ -29,8 +20,6 @@ jobs: - run: name: Compile code with optimizations command: swift build -c release - - linux-fluent: docker: - image: codevapor/swift:4.1 @@ -47,8 +36,6 @@ jobs: name: Run Fluent SQLite unit tests command: swift test working_directory: ~/fluent-sqlite - - workflows: version: 2 tests: @@ -56,8 +43,6 @@ workflows: - linux - linux-fluent - linux-release - # - macos - nightly: triggers: - schedule: @@ -68,5 +53,3 @@ workflows: - master jobs: - linux - # - macos -