Skip to content

Commit db5bcba

Browse files
committed
add missing foreign key actions, fixes #76
1 parent 8a37a5d commit db5bcba

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
extension PostgreSQLQuery {
2+
/// In addition, when the data in the referenced columns is changed, certain actions are performed on the data in this table's
3+
/// columns. The ON DELETE clause specifies the action to perform when a referenced row in the referenced table is being deleted.
4+
/// Likewise, the ON UPDATE clause specifies the action to perform when a referenced column in the referenced table is being updated
5+
/// to a new value. If the row is updated, but the referenced column is not actually changed, no action is done. Referential actions
6+
/// other than the NO ACTION check cannot be deferred, even if the constraint is declared deferrable. There are the following possible
7+
/// actions for each clause.
8+
///
9+
/// https://www.postgresql.org/docs/10/static/sql-createtable.html.
210
public enum ForeignKeyAction {
3-
case nullify
11+
/// Produce an error indicating that the deletion or update would create a foreign key constraint violation.
12+
/// If the constraint is deferred, this error will be produced at constraint check time if there still exist
13+
/// any referencing rows. This is the default action.
14+
case noAction
15+
/// Produce an error indicating that the deletion or update would create a foreign key constraint violation.
16+
/// This is the same as NO ACTION except that the check is not deferrable.
17+
case restrict
18+
/// Delete any rows referencing the deleted row, or update the values of the referencing column(s) to the new
19+
// values of the referenced columns, respectively.
20+
case cascade
21+
/// Set the referencing column(s) to null.
22+
case setNull
23+
/// Set the referencing column(s) to their default values. (There must be a row in the referenced table matching
24+
/// the default values, if they are not null, or the operation will fail.)
25+
case setDefault
426
}
527
}
628

729
extension PostgreSQLSerializer {
830
internal func serialize(_ action: PostgreSQLQuery.ForeignKeyAction) -> String {
931
switch action {
10-
case .nullify: return "NULLIFY"
32+
case .noAction: return "NO ACTION"
33+
case .restrict: return "RESTRICT"
34+
case .cascade: return "CASCADE"
35+
case .setNull: return "SET NULL"
36+
case .setDefault: return "SET DEFAULT"
1137
}
1238
}
1339
}

0 commit comments

Comments
 (0)