Skip to content

Commit f422fd0

Browse files
author
Nicos
committed
add check username query
Relates to #2
1 parent f509e34 commit f422fd0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Queries/check_username.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const databaseConnection = require("../database/db_connections.js");
2+
3+
const check_username_exists = (username, cb) => {
4+
databaseConnection.query(
5+
`SELECT CASE WHEN EXISTS(SELECT username FROM users WHERE username = $1) THEN CAST (true AS BOOLEAN) ELSE CAST (false AS BOOLEAN) END`,
6+
[username],
7+
(err, res) => {
8+
if (err) cb(err);
9+
else cb(null, res.rows);
10+
}
11+
);
12+
};
13+
14+
module.exports = check_user_exists;

0 commit comments

Comments
 (0)