Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
2
Indexable
Never
class UserService {
    constructor(dbConnection) {
      this.dbConnection = dbConnection;
      
    }
    
    createUser(user) {
      const { name, email } = user;
      const queryC = `insert into  user (name, email) values ('${name}', '${email}')`;
      this.dbConnection.query(queryC, (error, result) => {
        if (error) {
          console.error('Error creating user:', error);
        } else {
          console.log('User created successfully');
        }
      });
      
    }
    deleteUser(id){
      
      const queryD = `delete from user where id = ${id}`;
      this.dbConnection.query(queryD, (error, result) => {
        if (error) {
          console.error('Error creating user:', error);
        } else {
          console.log('User delete successfully');
        }
      });
    }

    selectAll(){
        const queryS = `select * from user`
        this.dbConnection.query(queryS, (error, rows) => {
          if (error) {
            console.error('Error creating user:', error);
          } else {
            console.log('Table selected successfully');
            let table = rows
            console.log(table)
          }
        });
    }
    }
    
  
  module.exports = UserService;