77use CalebDW \SqlEntities \Contracts \SqlEntity ;
88use CalebDW \SqlEntities \View ;
99use Illuminate \Database \Connection ;
10+ use Illuminate \Support \Str ;
1011use InvalidArgumentException ;
1112
1213abstract class Grammar
@@ -18,24 +19,28 @@ public function __construct(
1819
1920 public function compileCreate (SqlEntity $ entity ): string
2021 {
21- return match (true ) {
22+ $ statement = match (true ) {
2223 $ entity instanceof View => $ this ->compileViewCreate ($ entity ),
2324
2425 default => throw new InvalidArgumentException (
2526 sprintf ('Unsupported entity [%s]. ' , $ entity ::class),
2627 ),
2728 };
29+
30+ return $ this ->clean ($ statement );
2831 }
2932
3033 public function compileDrop (SqlEntity $ entity ): string
3134 {
32- return match (true ) {
35+ $ statement = match (true ) {
3336 $ entity instanceof View => $ this ->compileViewDrop ($ entity ),
3437
3538 default => throw new InvalidArgumentException (
3639 sprintf ('Unsupported entity [%s]. ' , $ entity ::class),
3740 ),
3841 };
42+
43+ return $ this ->clean ($ statement );
3944 }
4045
4146 abstract protected function compileViewCreate (View $ entity ): string ;
@@ -47,14 +52,14 @@ protected function compileViewDrop(View $entity): string
4752 SQL ;
4853 }
4954
50- /** @param list<string>|null $columns */
51- protected function compileColumnsList (?array $ columns ): string
55+ /** @param list<string>|null $values */
56+ protected function compileList (?array $ values ): string
5257 {
53- if ($ columns === null ) {
58+ if ($ values === null ) {
5459 return '' ;
5560 }
5661
57- return ' ( ' . implode (', ' , $ columns ) . ') ' ;
62+ return '( ' . implode (', ' , $ values ) . ') ' ;
5863 }
5964
6065 protected function compileCheckOption (string |true |null $ option ): string
@@ -71,4 +76,12 @@ protected function compileCheckOption(string|true|null $option): string
7176
7277 return "WITH {$ option } CHECK OPTION " ;
7378 }
79+
80+ protected function clean (string $ value ): string
81+ {
82+ return Str::of ($ value )
83+ ->replaceMatches ('/ +/ ' , ' ' )
84+ ->trim ()
85+ ->value ();
86+ }
7487}
0 commit comments