Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5d38037

Browse files
fluent property wrappers (vapor#120)
1 parent 918cfab commit 5d38037

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

‎Package.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
.library(name: "FluentPostgresDriver", targets: ["FluentPostgresDriver"]),
88
],
99
dependencies: [
10-
.package(url: "https://github.com/vapor/fluent-kit.git", from:"1.0.0-alpha"),
10+
.package(url: "https://github.com/vapor/fluent-kit.git", .branch("master")),
1111
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0-alpha"),
1212
],
1313
targets: [

‎Sources/FluentPostgresDriver/PostgresConverterDelegate.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ struct PostgresConverterDelegate: SQLConverterDelegate {
99
return SQLRaw("BOOL")
1010
case .data:
1111
return SQLRaw("BYTEA")
12+
case .datetime:
13+
return SQLRaw("TIMESTAMPTZ")
1214
default:
1315
return nil
1416
}

‎Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,22 @@ final class FluentPostgresDriverTests: XCTestCase {
113113
}
114114

115115
func testBlob() throws {
116-
struct Foo: Model {
117-
staticletshared=Foo()
118-
var id=Field<Int?>("id")
119-
vardata=Field<[UInt8]>("data")
116+
finalclass Foo: Model {
117+
@Fieldvarid:Int?
118+
@Fieldvar data:[UInt8]
119+
init(){}
120120
}
121121

122122
struct CreateFoo: Migration {
123123
func prepare(on database: Database) -> EventLoopFuture<Void> {
124-
return database.schema(Foo.self)
125-
.field(\.id, .int, .identifier(auto: true))
126-
.field(\.data, .data, .required)
124+
return Foo.schema(on: database)
125+
.field(\.$id, .int, .identifier(auto: true))
126+
.field(\.$data, .data, .required)
127127
.create()
128128
}
129129

130130
func revert(on database: Database) -> EventLoopFuture<Void> {
131-
return database.schema(Foo.self).delete()
131+
return Foo.schema(on: database).delete()
132132
}
133133
}
134134

@@ -137,19 +137,31 @@ final class FluentPostgresDriverTests: XCTestCase {
137137
}
138138

139139
func testSaveModelWithBool() throws {
140-
struct Organization: Model {
141-
static let shared = Organization()
142-
static let entity = "organizations"
143-
let id = Field<Int?>("id")
144-
let disabled = Field<Bool>("disabled")
140+
final class Organization: Model {
141+
@Field var id: Int?
142+
@Field var disabled: Bool
143+
init() { }
145144
}
146145

147-
try Organization.autoMigration().prepare(on: self.connectionPool).wait()
146+
struct CreateOrganization: Migration {
147+
func prepare(on database: Database) -> EventLoopFuture<Void> {
148+
return Organization.schema(on: database)
149+
.field(\.$id, .int, .identifier(auto: true))
150+
.field(\.$disabled, .bool, .required)
151+
.create()
152+
}
153+
154+
func revert(on database: Database) -> EventLoopFuture<Void> {
155+
return Organization.schema(on: database).delete()
156+
}
157+
}
158+
159+
try CreateOrganization().prepare(on: self.connectionPool).wait()
148160
defer {
149-
try! Organization.autoMigration().revert(on: self.connectionPool).wait()
161+
try! CreateOrganization().revert(on: self.connectionPool).wait()
150162
}
151163

152-
let new = Organization.row()
164+
let new = Organization()
153165
new.disabled = false
154166
try new.save(on: self.connectionPool).wait()
155167
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /