forked from Zaid-Ajaj/Npgsql.FSharp.Analyzer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better suggestions and code fixes for non-nullable parameters
- Loading branch information
Showing
7 changed files
with
452 additions
and
45 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,16 @@ | ||
module SelectWithInnerJoins | ||
|
||
open Npgsql.FSharp | ||
|
||
let [<Literal>] usersWithRoles = """ | ||
SELECT * FROM users | ||
JOIN user_roles ON users.user_id = user_roles.user_id | ||
WHERE users.user_id = @user_id AND role_description = @role | ||
""" | ||
|
||
let usersAndTheirRoles connectionString = | ||
connectionString | ||
|> Sql.connect | ||
|> Sql.query usersWithRoles | ||
|> Sql.parameters [ "@user_id", Sql.intOrNone None; "@role", Sql.text "User" ] | ||
|> Sql.execute (fun read -> read.int "user_id") |
10 changes: 10 additions & 0 deletions
10
tests/examples/hashing/selectWithNonNullableColumnComparison.fs
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,10 @@ | ||
module SelectWithNonNullableColumnComparison | ||
|
||
open Npgsql.FSharp | ||
|
||
let findUsernames connectionString = | ||
connectionString | ||
|> Sql.connect | ||
|> Sql.query "SELECT * FROM users WHERE user_id = @user_id AND username = @username" | ||
|> Sql.parameters [ "@user_id", Sql.intOrNone None; "@username", Sql.text "User" ] | ||
|> Sql.execute (fun read -> read.int "user_id") |
22 changes: 22 additions & 0 deletions
22
tests/examples/hashing/updateQueryWithParametersInAssignments.fs
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,22 @@ | ||
module UpdateQueryWithParametersInAssignments | ||
|
||
open Npgsql.FSharp | ||
open System | ||
|
||
let [<Literal>] updateUsernameQuery = """ | ||
UPDATE users | ||
SET username = @username, last_login = @last_login | ||
WHERE user_id = @user_id | ||
RETURNING * | ||
""" | ||
|
||
let usersAndTheirRoles connectionString = | ||
connectionString | ||
|> Sql.connect | ||
|> Sql.query updateUsernameQuery | ||
|> Sql.parameters [ | ||
"@user_id", Sql.intOrNone (Some 10) | ||
"@username", Sql.textOrNone (Some "John") | ||
"@last_login", Sql.timestamptz DateTime.Now | ||
] | ||
|> Sql.execute (fun read -> read.int "user_id") |