66
77use CalebDW \SqlEntities \Contracts \SqlEntity ;
88use CalebDW \SqlEntities \Function_ ;
9+ use CalebDW \SqlEntities \Trigger ;
910use CalebDW \SqlEntities \View ;
1011use Illuminate \Database \Connection ;
1112use Illuminate \Support \Str ;
@@ -23,6 +24,7 @@ public function compileCreate(SqlEntity $entity): string
2324 {
2425 $ statement = match (true ) {
2526 $ entity instanceof Function_ => $ this ->compileFunctionCreate ($ entity ),
27+ $ entity instanceof Trigger => $ this ->compileTriggerCreate ($ entity ),
2628 $ entity instanceof View => $ this ->compileViewCreate ($ entity ),
2729
2830 default => throw new InvalidArgumentException (
@@ -38,6 +40,7 @@ public function compileDrop(SqlEntity $entity): string
3840 {
3941 $ statement = match (true ) {
4042 $ entity instanceof Function_ => $ this ->compileFunctionDrop ($ entity ),
43+ $ entity instanceof Trigger => $ this ->compileTriggerDrop ($ entity ),
4144 $ entity instanceof View => $ this ->compileViewDrop ($ entity ),
4245
4346 default => throw new InvalidArgumentException (
@@ -53,6 +56,7 @@ public function supportsEntity(SqlEntity $entity): bool
5356 {
5457 return match (true ) {
5558 $ entity instanceof Function_ => true ,
59+ $ entity instanceof Trigger => true ,
5660 $ entity instanceof View => true ,
5761 default => false ,
5862 };
@@ -67,6 +71,15 @@ protected function compileFunctionDrop(Function_ $entity): string
6771 SQL ;
6872 }
6973
74+ abstract protected function compileTriggerCreate (Trigger $ entity ): string ;
75+
76+ protected function compileTriggerDrop (Trigger $ entity ): string
77+ {
78+ return <<<SQL
79+ DROP TRIGGER IF EXISTS {$ entity ->name ()}
80+ SQL ;
81+ }
82+
7083 abstract protected function compileViewCreate (View $ entity ): string ;
7184
7285 protected function compileViewDrop (View $ entity ): string
0 commit comments