Skip to content
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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go/ql/lib/change-notes/2025-01-09-beego-orm-models.md
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.
18 changes: 18 additions & 0 deletions go/ql/lib/ext/github.com.beego.beego.client.orm.model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ extensions:
- ["beego-orm", "github.com/beego/beego/client/orm"]
- ["beego-orm", "github.com/astaxie/beego/orm"]
- ["beego-orm", "github.com/beego/beego/orm"]
- addsTo:
pack: codeql/go-all
extensible: sourceModel
data:
- ["group:beego-orm", "DB", True, "Query", "", "", "ReturnValue[0]", "database", "manual"]
- ["group:beego-orm", "DB", True, "QueryContext", "", "", "ReturnValue[0]", "database", "manual"]
- ["group:beego-orm", "DB", True, "QueryRow", "", "", "ReturnValue", "database", "manual"]
- ["group:beego-orm", "DB", True, "QueryRowContext", "", "", "ReturnValue", "database", "manual"]
- ["group:beego-orm", "DQL", True, "Read", "", "", "Argument[0]", "database", "manual"]
- ["group:beego-orm", "DQL", True, "ReadWithCtx", "", "", "Argument[1]", "database", "manual"]
- ["group:beego-orm", "DQL", True, "ReadForUpdate", "", "", "Argument[0]", "database", "manual"]
- ["group:beego-orm", "DQL", True, "ReadForUpdateWithCtx", "", "", "Argument[1]", "database", "manual"]
- ["group:beego-orm", "DQL", True, "ReadOrCreate", "", "", "Argument[0]", "database", "manual"]
- ["group:beego-orm", "DQL", True, "ReadOrCreateWithCtx", "", "", "Argument[1]", "database", "manual"]
Comment on lines +17 to +22
Copy link
Contributor

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 of orm.NewOrm()). So you can keep the tests in the same file. Or you can put them in a separate file, if you prefer.

Copy link
Contributor Author

@egregius313 egregius313 Jan 10, 2025

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, and ReadOrCreate. The *Ctx variants appear to be new in v2.

- ["group:beego-orm", "Ormer", True, "Read", "", "", "Argument[0]", "database", "manual"]
- ["group:beego-orm", "Ormer", True, "ReadForUpdate", "", "", "Argument[0]", "database", "manual"]
- ["group:beego-orm", "Ormer", True, "ReadOrCreate", "", "", "Argument[0]", "database", "manual"]
- addsTo:
pack: codeql/go-all
extensible: sinkModel
Expand Down Expand Up @@ -40,3 +57,4 @@ extensions:
- ["group:beego-orm", "QueryBuilder", True, "Values", "", "", "Argument[0]", "sql-injection", "manual"]
- ["group:beego-orm", "QueryBuilder", True, "Where", "", "", "Argument[0]", "sql-injection", "manual"]
- ["group:beego-orm", "QuerySeter", True, "FilterRaw", "", "", "Argument[1]", "sql-injection", "manual"]

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
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading