Skip to content

Commit

Permalink
Add randomOrSeed() to Seedable
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuawright11 committed Apr 20, 2022
1 parent 0396c02 commit da80749
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/Alchemy/SQL/Database/Seeding/Seeder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ extension Seedable where Self: Model {

return try await rows.insertReturnAll()
}

public static func randomOrSeed() async throws -> Self {
guard let random = try await random() else {
return try await seed()
}

return random
}
}

extension Faker {
Expand Down

0 comments on commit da80749

Please # to comment.