-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from vapor/fk-action
replace conflict resolution with SQLForeignKeyAction
- Loading branch information
Showing
5 changed files
with
76 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/// RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT | ||
public protocol SQLForeignKeyAction: SQLSerializable { | ||
/// Produce an error indicating that the deletion or update would create a foreign key constraint violation. | ||
/// If the constraint is deferred, this error will be produced at constraint check time if there still exist any referencing rows. | ||
/// This is the default action. | ||
static var noAction: Self { get } | ||
|
||
/// Produce an error indicating that the deletion or update would create a foreign key constraint violation. | ||
static var restrict: Self { get } | ||
|
||
/// Delete any rows referencing the deleted row, or update the values of the referencing column(s) to the new values of the referenced columns, respectively. | ||
static var cascade: Self { get } | ||
|
||
/// Set the referencing column(s) to null. | ||
static var setNull: Self { get } | ||
|
||
/// Set the referencing column(s) to their default values. | ||
/// (There must be a row in the referenced table matching the default values, if they are not null, or the operation will fail.) | ||
static var setDefault: Self { get } | ||
} | ||
|
||
/// Generic implementation of `SQLForeignKeyAction` suitable as a common-denominator for all SQL flavors. | ||
public enum GenericSQLForeignKeyAction: SQLForeignKeyAction { | ||
/// See `SQLForeignKeyAction`. | ||
public typealias `Self` = GenericSQLForeignKeyAction | ||
|
||
/// See `SQLForeignKeyAction`. | ||
public static var noAction: Self { return ._noAction } | ||
|
||
/// See `SQLForeignKeyAction`. | ||
public static var restrict: Self { return ._restrict } | ||
|
||
/// See `SQLForeignKeyAction`. | ||
public static var cascade: Self { return ._cascade } | ||
|
||
/// See `SQLForeignKeyAction`. | ||
public static var setNull: Self { return ._setNull } | ||
|
||
/// See `SQLForeignKeyAction`. | ||
public static var setDefault: Self { return ._setDefault } | ||
|
||
case _noAction | ||
case _restrict | ||
case _cascade | ||
case _setNull | ||
case _setDefault | ||
|
||
/// See `SQLSerializable`. | ||
public func serialize(_ binds: inout [Encodable]) -> String { | ||
switch self { | ||
case ._noAction: return "NO ACTION" | ||
case ._restrict: return "RESTRICT" | ||
case ._cascade: return "CASCADE" | ||
case ._setNull: return "SET NULL" | ||
case ._setDefault: return "SET DEFAULT" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters