File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -437,6 +437,29 @@ WHERE TABLE_CATALOG = ? AND TABLE_NAME = ?`)
437
437
return columnTypes , execErr
438
438
}
439
439
440
+ func (m Migrator ) CreateView (name string , option gorm.ViewOption ) error {
441
+ if option .Query == nil {
442
+ return gorm .ErrSubQueryRequired
443
+ }
444
+
445
+ sql := new (strings.Builder )
446
+ sql .WriteString ("CREATE " )
447
+ if option .Replace {
448
+ sql .WriteString ("OR ALTER " )
449
+ }
450
+ sql .WriteString ("VIEW " )
451
+ m .QuoteTo (sql , name )
452
+ sql .WriteString (" AS " )
453
+
454
+ m .DB .Statement .AddVar (sql , option .Query )
455
+
456
+ if option .CheckOption != "" {
457
+ sql .WriteString (" " )
458
+ sql .WriteString (option .CheckOption )
459
+ }
460
+ return m .DB .Exec (m .Explain (sql .String (), m .DB .Statement .Vars ... )).Error
461
+ }
462
+
440
463
func (m Migrator ) CreateIndex (value interface {}, name string ) error {
441
464
return m .RunWithValue (value , func (stmt * gorm.Statement ) error {
442
465
var idx * schema.Index
You can’t perform that action at this time.
0 commit comments