-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go: database
source models for github.com/beego/beego/client/orm
#18465
Merged
egregius313
merged 7 commits into
github:main
from
egregius313:egregius313/go/mad/database/beego-orm
Jan 10, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
baec4ad
beego models
egregius313 592b46b
Change note
egregius313 46f9448
Add `Ormer` models for v1 of the beego ORM
egregius313 4bd43b4
Reword change note to be more general
egregius313 bff2433
Rename test functions to include package name
egregius313 43771d8
Fix formatting
egregius313 0f03835
Fix provenance in test
egregius313 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* `database` local source models have been added for the Beego ORM package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/test_beego_orm.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package test | ||
|
||
import ( | ||
oldOrm "github.com/astaxie/beego/orm" | ||
"github.com/beego/beego/v2/client/orm" | ||
) | ||
|
||
func test_beego_DB(db orm.DB) { | ||
rows, err := db.Query("SELECT * FROM users") // $ source | ||
ignore(rows, err) | ||
|
||
rows, err = db.QueryContext(nil, "SELECT * FROM users") // $ source | ||
ignore(rows, err) | ||
|
||
row := db.QueryRow("SELECT * FROM users") // $ source | ||
ignore(row) | ||
|
||
row = db.QueryRowContext(nil, "SELECT * FROM users") // $ source | ||
ignore(row) | ||
} | ||
|
||
func test_beego_Ormer() { | ||
o := oldOrm.NewOrm() | ||
o.Read(&User{}) // $ source | ||
o.ReadForUpdate(&User{}) // $ source | ||
o.ReadOrCreate(&User{}, "name") // $ source | ||
} | ||
|
||
func test_beego_DQL() { | ||
o := orm.NewOrm() | ||
o.Read(&User{}) // $ source | ||
o.ReadWithCtx(nil, &User{}) // $ source | ||
o.ReadForUpdate(&User{}) // $ source | ||
o.ReadForUpdateWithCtx(nil, &User{}) // $ source | ||
o.ReadOrCreate(&User{}, "name") // $ source | ||
o.ReadOrCreateWithCtx(nil, &User{}, "name") // $ source | ||
} |
150 changes: 150 additions & 0 deletions
150
...semmle/go/dataflow/flowsources/local/database/vendor/github.com/astaxie/beego/orm/stub.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this in the last review, but in older versions (2/3 of the package paths), this type was called
Ormer
(here and here). These models should be duplicated for that type. I would just use the same package group, as the name isn't used in later versions.Please also add tests for it. You'll need to make new stubs for one of the other package paths. Go makes it easy to import two versions of the same library in the same file - you just give one of them a different name (as in
import "github.com/astaxie/beego/orm" oldorm
) and use that when referring to them (oldorm.NewOrm()
instead oform.NewOrm()
). So you can keep the tests in the same file. Or you can put them in a separate file, if you prefer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added models for
Ormer::Read
,ReadForUpdate
, andReadOrCreate
. The*Ctx
variants appear to be new in v2.