thanathip41 / tspace-mysql

tspace-mysql is an Object-Relational Mapping (ORM) tool designed to run seamlessly in Node.js and is fully compatible with TypeScript. It consistently supports the latest features in both TypeScript and JavaScript, providing additional functionalities to enhance your development experience.
MIT License
2 stars 0 forks source link

Having issue while fetching data for specific user.. #2

Open princevora opened 4 months ago

princevora commented 4 months ago

Hey, i recently found a bug or idk why is that happened to me for few times see the below is my code ` let user = await new Users().where("email", "=", email);

    const exists = await user.exists();
    if (!exists) {
        reject(ObjectResponse("No user found with this provided email", 401, true));
    }

    try {
        // get user data
        user = await user.first();

`

while my email is something like princevora...@gmail.com so up there, is a where query that checks for email, i have already made a instance of Users model on const user so the first intial query is like select * from where email = email.@gma..., so when i came to try catch and used user.first() to get the searched user why it is returning me like the below image even i haven't searched for it image

it should return the user that we seached for instead of the all users, i realized whenever you leave a variable an do like const exists = await user.exists() it reset's the query, its not setisfying to create a new instance every time..

thanathip41 commented 4 months ago

The query will reset every excuting ,

maybe you can like it const user = await new User().where("email", "=", email).first() if (user == null ) { reject(ObjectResponse("No user found with this provided email", 401, true)); }

// cosnole.log(user)

Thank you

princevora commented 4 months ago

Thanks about your reply, i just raised the issue because if we do it like this then exists() method that is available in your package will not represent its usage thats the main point. Some of the users may make a very strict validations so in that cases i think its useful so it should be changed i think if possible

Thanks for your time..

thanathip41 commented 4 months ago

Thank you for your feedback. it’s important to me. I will fix it soon.

Thanks a lot.

princevora commented 4 months ago

Hope it was helpful Thanks

thanathip41 commented 4 months ago

Thanks, I hope your can re try again.

example https://www.npmjs.com/package/tspace-mysql/v/1.6.6-dev.1#unset-statements

Thank you.

princevora commented 4 months ago

hey thanks for new version but i am still having trouble fetching specific users

see below query.. `// check if the user already exists. let user = new Users().where("email", "=", email);

    const exists = await user.exists();
    console.log("Users: ", user.toSQL());`

my email input is something like meetvora..@gmaial.com

i think all the things are okey as compare to new version when i creaeted a user instace i think its query should look like this

SELECTusers.id,users.username,users.email,users.password,users.created_at,users.updated_atFROMusers WHEREusers.email= 'meetvora..@gmail.com'

but after the instance used the exists method it returned me the query something like Users: SELECTusers.id,users.username,users.email,users.password,users.created_at,users.updated_atFROMusers if there are any issues in my code please correct me

thanathip41 commented 4 months ago

const exists = await user.exists(); // after that the instane will reset the "select statements"

// if you want to view the SQL for debug you can
const exists = await user.debug().exists();

// Now the query has changed because the "select statements" have been reset console.log("Users: ", user.toSQL());`

Thank you. Please provide any feedback if you encounter any problems