Skip to content

Create and drop view#6097

Merged
jinzhu merged 4 commits intogo-gorm:masterfrom
black-06:view
Feb 27, 2023
Merged

Create and drop view#6097
jinzhu merged 4 commits intogo-gorm:masterfrom
black-06:view

Conversation

@black-06
Copy link
Copy Markdown
Contributor

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

create view #4966

It's different from issue's suggestion.
I found the unimplemented CreateView function in Migrator,
then I implemented it.

About ViewOption:

  • Query is a subquey
  • If Replace is true, exec CREATE OR REPLACE. sqlite may not support this.
  • If CheckOption is not empty, append to sql, e.g. WITH LOCAL CHECK OPTION

User Case Description

DB.Migrator().CreateView("users_pets", gorm.ViewOption{Query: DB.Model(&User{}).Select("users.id, users.name")})
CREATE VIEW `users_pets` AS SELECT users.id, users.name FROM `users`

@black-06 black-06 changed the title View Create and drop view Feb 23, 2023
Copy link
Copy Markdown
Member

@a631807682 a631807682 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add parameter checking, such as what happens without option.Query? can we add comments to explain how to use it?

sqlite may not support this.

It doesn't matter, just need to handle it in the sqlite driver

@black-06
Copy link
Copy Markdown
Contributor Author

Do we need to add parameter checking, such as what happens without option.Query? can we add comments to explain how to use it?

sqlite may not support this.

It doesn't matter, just need to handle it in the sqlite driver

done ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants