Spaces:
Sleeping
Sleeping
Create models/User.js
Browse files- models/User.js +13 -0
models/User.js
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const db = require('../database');
|
2 |
+
|
3 |
+
const User = {
|
4 |
+
create: (username, password, role = 'user', callback) => {
|
5 |
+
const sql = `INSERT INTO users (username, password, role) VALUES (?, ?, ?)`;
|
6 |
+
db.query(sql, [username, password, role], callback);
|
7 |
+
},
|
8 |
+
findByUsername: (username, callback) => {
|
9 |
+
db.query('SELECT * FROM users WHERE username = ?', [username], callback);
|
10 |
+
}
|
11 |
+
};
|
12 |
+
|
13 |
+
module.exports = User;
|