Skip to content

Commit 2f47c2f

Browse files
authored
Enum Support (vapor#167)
* enum support * enum
1 parent 4d6b9bb commit 2f47c2f

File tree

6 files changed

+42
-264
lines changed

6 files changed

+42
-264
lines changed

Sources/PostgresKit/Builders/PostgresCreateTypeBuilder.swift

-76
This file was deleted.

Sources/PostgresKit/Builders/PostgresDropTypeBuilder.swift

-64
This file was deleted.

Sources/PostgresKit/PostgresDialect.swift

+8
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ public struct PostgresDialect: SQLDialect {
2929
public var autoIncrementClause: SQLExpression {
3030
return SQLRaw("GENERATED BY DEFAULT AS IDENTITY")
3131
}
32+
33+
public var supportsAutoIncrement: Bool {
34+
true
35+
}
36+
37+
public var enumSyntax: SQLEnumSyntax {
38+
.typeName
39+
}
3240
}

Sources/PostgresKit/Query/PostgresCreateType.swift

-48
This file was deleted.

Sources/PostgresKit/Query/PostgresDropType.swift

-35
This file was deleted.

Tests/PostgresKitTests/PostgresKitTests.swift

+34-41
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,6 @@ class PostgresKitTests: XCTestCase {
3030
}
3131
}
3232
}
33-
34-
func testCreateEnumWithBuilder() throws {
35-
let conn = try PostgresConnection.test(on: self.eventLoop).wait()
36-
defer { try! conn.close().wait() }
37-
let db = conn.sql()
38-
39-
try db.create(enum: "meal", cases: "breakfast", "lunch", "dinner").run().wait()
40-
try db.raw("DROP TYPE meal;").run().wait()
41-
42-
try db.create(enum: SQLIdentifier("meal"), cases: "breakfast", "lunch", "dinner").run().wait()
43-
try db.raw("DROP TYPE meal;").run().wait()
44-
}
45-
46-
func testDropEnumWithBuilder() throws {
47-
let conn = try PostgresConnection.test(on: self.eventLoop).wait()
48-
defer { try! conn.close().wait() }
49-
let db = conn.sql()
50-
51-
// these two should work even if the type does not exist
52-
try db.drop(type: "meal").ifExists().run().wait()
53-
try db.drop(type: "meal").ifExists().cascade().run().wait()
54-
55-
try db.create(enum: "meal", cases: "breakfast", "lunch", "dinner").run().wait()
56-
try db.drop(type: "meal").ifExists().cascade().run().wait()
57-
58-
try db.create(enum: "meal", cases: "breakfast", "lunch", "dinner").run().wait()
59-
try db.drop(type: "meal").run().wait()
60-
61-
try db.create(enum: "meal", cases: "breakfast", "lunch", "dinner").run().wait()
62-
try db.drop(type: SQLIdentifier("meal")).run().wait()
63-
64-
try db.create(enum: "meal", cases: "breakfast", "lunch", "dinner").run().wait()
65-
try db.drop(type: "meal").cascade().run().wait()
66-
}
6733

6834
func testLeak() throws {
6935
struct Foo: Codable {
@@ -158,17 +124,44 @@ class PostgresKitTests: XCTestCase {
158124
XCTAssertEqual(test.baz, "baz")
159125
}
160126

161-
private var eventLoopGroup: EventLoopGroup!
162-
private var eventLoop: EventLoop {
163-
return self.eventLoopGroup.next()
127+
func testEnum() throws {
128+
try self.benchmark.testEnum()
164129
}
165-
130+
131+
var db: SQLDatabase {
132+
self.connection.sql()
133+
}
134+
var benchmark: SQLBenchmarker {
135+
.init(on: self.db)
136+
}
137+
var eventLoop: EventLoop {
138+
self.eventLoopGroup.next()
139+
}
140+
141+
var eventLoopGroup: EventLoopGroup!
142+
var connection: PostgresConnection!
143+
166144
override func setUp() {
167-
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
145+
XCTAssertTrue(isLoggingConfigured)
146+
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 2)
147+
self.connection = try! PostgresConnection.test(
148+
on: self.eventLoopGroup.next()
149+
).wait()
168150
}
169-
151+
170152
override func tearDown() {
171-
XCTAssertNoThrow(try self.eventLoopGroup.syncShutdownGracefully())
153+
try! self.connection.close().wait()
154+
self.connection = nil
155+
try! self.eventLoopGroup.syncShutdownGracefully()
172156
self.eventLoopGroup = nil
173157
}
174158
}
159+
160+
let isLoggingConfigured: Bool = {
161+
LoggingSystem.bootstrap { label in
162+
var handler = StreamLogHandler.standardOutput(label: label)
163+
handler.logLevel = .debug
164+
return handler
165+
}
166+
return true
167+
}()

0 commit comments

Comments
 (0)