Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@black-06
Copy link
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
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
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