mirror of
https://github.com/vapor/template.git
synced 2025-05-15 18:23:20 +08:00
Compare commits
6 Commits
72e42f9848
...
3c1e20e228
Author | SHA1 | Date | |
---|---|---|---|
|
3c1e20e228 | ||
|
7605eb3491 | ||
|
45c24b320c | ||
|
b36c0ef752 | ||
|
0fa0788056 | ||
|
c1f81a18a9 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,5 +8,4 @@ db.sqlite
|
||||
.swiftpm
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
.vscode
|
||||
!.env.example
|
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["swiftlang.swift-vscode", "Vapor.vapor-vscode"]
|
||||
}
|
@ -39,11 +39,9 @@ let package = Package(
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
)
|
||||
],
|
||||
swiftLanguageModes: [.v5]
|
||||
]
|
||||
)
|
||||
|
||||
var swiftSettings: [SwiftSetting] { [
|
||||
.enableUpcomingFeature("DisableOutwardActorInference"),
|
||||
.enableExperimentalFeature("StrictConcurrency"),
|
||||
.enableUpcomingFeature("ExistentialAny"),
|
||||
] }
|
||||
|
@ -2,7 +2,7 @@ import Fluent
|
||||
import Vapor
|
||||
|
||||
struct TodoController: RouteCollection {
|
||||
func boot(routes: RoutesBuilder) throws {
|
||||
func boot(routes: any RoutesBuilder) throws {
|
||||
let todos = routes.grouped("todos")
|
||||
|
||||
todos.get(use: self.index)
|
||||
|
@ -1,14 +1,14 @@
|
||||
import Fluent
|
||||
|
||||
struct CreateTodo: AsyncMigration {
|
||||
func prepare(on database: Database) async throws {
|
||||
func prepare(on database: any Database) async throws {
|
||||
try await database.schema("todos")
|
||||
.id()
|
||||
.field("title", .string, .required)
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: Database) async throws {
|
||||
func revert(on database: any Database) async throws {
|
||||
try await database.schema("todos").delete()
|
||||
}
|
||||
}
|
||||
|
@ -16,19 +16,17 @@ public func configure(_ app: Application) async throws {
|
||||
password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
|
||||
database: Environment.get("DATABASE_NAME") ?? "vapor_database",
|
||||
tls: .prefer(try .init(configuration: .clientDefault)))
|
||||
), as: .psql){{/fluent.db.is_postgres}}{{#fluent.db.is_mysql}} app.databases.use(DatabaseConfigurationFactory.mysql(
|
||||
), as: .psql){{/fluent.db.is_postgres}}{{#fluent.db.is_mysql}}app.databases.use(DatabaseConfigurationFactory.mysql(
|
||||
hostname: Environment.get("DATABASE_HOST") ?? "localhost",
|
||||
port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? MySQLConfiguration.ianaPortNumber,
|
||||
username: Environment.get("DATABASE_USERNAME") ?? "vapor_username",
|
||||
password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
|
||||
database: Environment.get("DATABASE_NAME") ?? "vapor_database"
|
||||
), as: .mysql){{/fluent.db.is_mysql}}{{#fluent.db.is_sqlite}} app.databases.use(DatabaseConfigurationFactory.sqlite(.file("db.sqlite")), as: .sqlite){{/fluent.db.is_sqlite}}
|
||||
), as: .mysql){{/fluent.db.is_mysql}}{{#fluent.db.is_sqlite}}app.databases.use(DatabaseConfigurationFactory.sqlite(.file("db.sqlite")), as: .sqlite){{/fluent.db.is_sqlite}}
|
||||
|
||||
app.migrations.add(CreateTodo()){{/fluent}}{{#leaf}}
|
||||
|
||||
app.views.use(.leaf)
|
||||
|
||||
{{/leaf}}
|
||||
app.views.use(.leaf){{/leaf}}
|
||||
|
||||
// register routes
|
||||
try routes(app)
|
||||
|
@ -4,7 +4,7 @@
|
||||
func routes(_ app: Application) throws {
|
||||
{{#leaf}}app.get { req async throws in
|
||||
try await req.view.render("index", ["title": "Hello Vapor!"])
|
||||
}{{/leaf}}{{^leaf}} app.get { req async in
|
||||
}{{/leaf}}{{^leaf}}app.get { req async in
|
||||
"It works!"
|
||||
}{{/leaf}}
|
||||
|
||||
|
@ -11,14 +11,13 @@ struct {{name}}Tests {
|
||||
private func withApp(_ test: (Application) async throws -> ()) async throws {
|
||||
let app = try await Application.make(.testing)
|
||||
do {
|
||||
try await configure(app)
|
||||
{{#fluent}}try await app.autoMigrate()
|
||||
{{/fluent}} try await test(app)
|
||||
{{#fluent}}try await app.autoRevert()
|
||||
{{/fluent}} }
|
||||
catch {
|
||||
try await configure(app){{#fluent}}
|
||||
try await app.autoMigrate(){{/fluent}}
|
||||
try await test(app){{#fluent}}
|
||||
try await app.autoRevert(){{/fluent}}
|
||||
} catch {
|
||||
{{#fluent}}try? await app.autoRevert()
|
||||
{{/fluent}} try await app.asyncShutdown()
|
||||
{{/fluent}}try await app.asyncShutdown()
|
||||
throw error
|
||||
}
|
||||
try await app.asyncShutdown()
|
||||
|
@ -91,3 +91,6 @@ files:
|
||||
dynamic: true
|
||||
- .gitignore
|
||||
- .dockerignore
|
||||
- folder: .vscode
|
||||
files:
|
||||
- extensions.json
|
||||
|
Loading…
x
Reference in New Issue
Block a user