Repository navigation
demo(dist1): VG001-VG003 across SQL/Go/Python #2
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Dist 1: VG001-VG003 | ||
|
|
||
| This demo bundle intentionally triggers: | ||
|
|
||
| - VG001 (`SELECT *`) | ||
| - VG002 (`UPDATE` without `WHERE`) | ||
| - VG003 (`DELETE` without `WHERE`) | ||
|
|
||
| Coverage in this bundle: | ||
|
|
||
| - SQL files | ||
| - Go `database/sql` | ||
| - Goqu | ||
| - Python ORM | ||
| - Python non-ORM (`session.execute(text(...))`) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package demo | ||
|
|
||
| import goqulib "github.com/doug-martin/goqu/v9" | ||
|
|
||
| func GoquViolations() { | ||
| _ = goqulib.L("SELECT * FROM users LIMIT 1") | ||
| _ = goqulib.L("UPDATE users SET active = false") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| _ = goqulib.L("DELETE FROM orders") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package demo | ||
|
|
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
| ) | ||
|
|
||
| func StdViolations(db *sql.DB) { | ||
| ctx := context.Background() | ||
| _, _ = db.QueryContext(ctx, "SELECT * FROM users LIMIT 1") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| _, _ = db.ExecContext(ctx, "UPDATE users SET active = false") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| _, _ = db.ExecContext(ctx, "DELETE FROM orders") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from sqlalchemy.orm import Session | ||
|
|
||
| from models import Order, User | ||
|
|
||
|
|
||
| def orm_recent_user(session: Session): | ||
| return session.query(User.id, User.email).filter(User.active.is_(True)).limit(1).all() | ||
|
|
||
|
|
||
| def orm_update_without_where(session: Session): | ||
| return session.query(User).update({"active": False}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
|
|
||
|
|
||
| def orm_delete_without_where(session: Session): | ||
| return session.query(Order).delete() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from sqlalchemy import text | ||
| from sqlalchemy.orm import Session | ||
|
|
||
|
|
||
| def raw_select_star(session: Session): | ||
| return session.execute(text("SELECT * FROM users LIMIT 1")).first() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| def raw_update_without_where(session: Session): | ||
| return session.execute(text("UPDATE users SET active = false")) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
|
|
||
|
|
||
| def raw_delete_without_where(session: Session): | ||
| return session.execute(text("DELETE FROM orders")) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| SELECT * FROM users LIMIT 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| UPDATE users SET active = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| DELETE FROM orders; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
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.
VG001: avoid SELECT *; project only required columns | Query:
SELECT * FROM users LIMIT 1