@@ -16,7 +16,7 @@ class SQLiteGrammar extends Grammar
16
16
*
17
17
* @var array
18
18
*/
19
- protected $ modifiers = ['Nullable ' , 'Default ' , 'Increment ' ];
19
+ protected $ modifiers = ['VirtualAs ' , ' StoredAs ' , ' Nullable ' , 'Default ' , 'Increment ' ];
20
20
21
21
/**
22
22
* The columns available as serials.
@@ -137,7 +137,9 @@ public function compileAdd(Blueprint $blueprint, Fluent $command)
137
137
{
138
138
$ columns = $ this ->prefixArray ('add column ' , $ this ->getColumns ($ blueprint ));
139
139
140
- return collect ($ columns )->map (function ($ column ) use ($ blueprint ) {
140
+ return collect ($ columns )->reject (function ($ column ) {
141
+ return preg_match ('/as \(.*\) stored/ ' , $ column ) > 0 ;
142
+ })->map (function ($ column ) use ($ blueprint ) {
141
143
return 'alter table ' .$ this ->wrapTable ($ blueprint ).' ' .$ column ;
142
144
})->all ();
143
145
}
@@ -822,6 +824,47 @@ public function typeMultiPolygon(Fluent $column)
822
824
return 'multipolygon ' ;
823
825
}
824
826
827
+ /**
828
+ * Create the column definition for a generated, computed column type.
829
+ *
830
+ * @param \Illuminate\Support\Fluent $column
831
+ * @return void
832
+ *
833
+ * @throws \RuntimeException
834
+ */
835
+ protected function typeComputed (Fluent $ column )
836
+ {
837
+ throw new RuntimeException ('This database driver requires a type, see the virtualAs / storedAs modifiers. ' );
838
+ }
839
+
840
+ /**
841
+ * Get the SQL for a generated virtual column modifier.
842
+ *
843
+ * @param \Illuminate\Database\Schema\Blueprint $blueprint
844
+ * @param \Illuminate\Support\Fluent $column
845
+ * @return string|null
846
+ */
847
+ protected function modifyVirtualAs (Blueprint $ blueprint , Fluent $ column )
848
+ {
849
+ if (! is_null ($ column ->virtualAs )) {
850
+ return " as ( {$ column ->virtualAs }) " ;
851
+ }
852
+ }
853
+
854
+ /**
855
+ * Get the SQL for a generated stored column modifier.
856
+ *
857
+ * @param \Illuminate\Database\Schema\Blueprint $blueprint
858
+ * @param \Illuminate\Support\Fluent $column
859
+ * @return string|null
860
+ */
861
+ protected function modifyStoredAs (Blueprint $ blueprint , Fluent $ column )
862
+ {
863
+ if (! is_null ($ column ->storedAs )) {
864
+ return " as ( {$ column ->storedAs }) stored " ;
865
+ }
866
+ }
867
+
825
868
/**
826
869
* Get the SQL for a nullable column modifier.
827
870
*
@@ -831,7 +874,13 @@ public function typeMultiPolygon(Fluent $column)
831
874
*/
832
875
protected function modifyNullable (Blueprint $ blueprint , Fluent $ column )
833
876
{
834
- return $ column ->nullable ? ' null ' : ' not null ' ;
877
+ if (is_null ($ column ->virtualAs ) && is_null ($ column ->storedAs )) {
878
+ return $ column ->nullable ? ' null ' : ' not null ' ;
879
+ }
880
+
881
+ if ($ column ->nullable === false ) {
882
+ return ' not null ' ;
883
+ }
835
884
}
836
885
837
886
/**
@@ -843,7 +892,7 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
843
892
*/
844
893
protected function modifyDefault (Blueprint $ blueprint , Fluent $ column )
845
894
{
846
- if (! is_null ($ column ->default )) {
895
+ if (! is_null ($ column ->default ) && is_null ( $ column -> virtualAs ) && is_null ( $ column -> storedAs ) ) {
847
896
return ' default ' .$ this ->getDefaultValue ($ column ->default );
848
897
}
849
898
}
0 commit comments