-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
132 deletions.
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
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 |
---|---|---|
@@ -1,33 +1,25 @@ | ||
CREATE OR REPLACE PROCEDURE create_user( | ||
p_username VARCHAR, | ||
p_hashed_password VARCHAR, | ||
p_fullname VARCHAR, | ||
p_email VARCHAR, | ||
OUT username_out VARCHAR, | ||
OUT hashed_password_out VARCHAR, | ||
OUT fullname_out VARCHAR, | ||
OUT email_out VARCHAR, | ||
INOUT p_username VARCHAR, | ||
INOUT p_hashed_password VARCHAR, | ||
INOUT p_fullname VARCHAR, | ||
INOUT p_email VARCHAR, | ||
OUT password_changed_at_out TIMESTAMP WITH TIME ZONE, | ||
OUT created_at_out TIMESTAMP WITH TIME ZONE | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
-- Insert new user and get the password_changed_at and created_at values | ||
INSERT INTO users (username, hashed_password, fullname, email) | ||
VALUES (p_username, p_hashed_password, p_fullname, p_email) | ||
RETURNING | ||
username, | ||
hashed_password, | ||
fullname, | ||
email, | ||
password_changed_at, | ||
created_at | ||
INTO | ||
username_out, | ||
hashed_password_out, | ||
fullname_out, | ||
email_out, | ||
password_changed_at_out, | ||
created_at_out; | ||
RETURNING password_changed_at, created_at | ||
INTO password_changed_at_out, created_at_out; | ||
|
||
-- Optionally update the input parameters with the inserted values | ||
SELECT username, hashed_password, fullname, email | ||
INTO p_username, p_hashed_password, p_fullname, p_email | ||
FROM users | ||
WHERE username = p_username; | ||
|
||
END; | ||
$$; |
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,36 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestGenerateParamPlaceholders(t *testing.T) { | ||
testCases := []struct { | ||
count int | ||
expectedResult string | ||
expectedErrorMsg string | ||
}{ | ||
{ | ||
count: 0, | ||
expectedResult: "", | ||
expectedErrorMsg: "", | ||
}, | ||
{ | ||
count: 3, | ||
expectedResult: "$1, $2, $3", | ||
expectedErrorMsg: "", | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(fmt.Sprintf("Count%d", testCase.count), func(t *testing.T) { | ||
result := generateParamPlaceholders(testCase.count) | ||
|
||
// Check if the result matches the expected value | ||
if result != testCase.expectedResult { | ||
t.Errorf("Expected: %s, Got: %s", testCase.expectedResult, result) | ||
} | ||
}) | ||
} | ||
} |
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