Skip to content

Commit da80749

Browse files
Add randomOrSeed() to Seedable
1 parent 0396c02 commit da80749

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/Alchemy/SQL/Database/Seeding/Seeder.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ extension Seedable where Self: Model {
2323

2424
return try await rows.insertReturnAll()
2525
}
26+
27+
public static func randomOrSeed() async throws -> Self {
28+
guard let random = try await random() else {
29+
return try await seed()
30+
}
31+
32+
return random
33+
}
2634
}
2735

2836
extension Faker {

0 commit comments

Comments
 (0)