Open dikovmaxim opened 1 year ago
Hello, thanks for opening this issue!
I noticed that, while most fields become null
after you restart your application, the logged_in
field goes from false
to true
. I don't see where this is possible in the code you provide, so I suggest:
logged_in
to true
and make sure they don't affect the other fieldssurreal sql
to inspect the contents of the database to see whether the database or your application has an issueFinally, it would be interesting to see any DEFINE TABLE
or DEFINE FIELD
statements you are using (if applicable).
In addition to @finnbear comment, could you get a list of field definitions with INFO FOR TABLE users
?
Thank you for your response:
This is the Select * from users output:
[{"time":"7.8992ms","status":"OK","result":[{"id":"users:dikoma15","logged_in":true,"username":"myusername"}]}]
And this is the output for INFO FOR TABLE users;
[{"time":"3.2342ms","status":"OK","result":{"ev":{},"fd":{},"ft":{},"ix":{}}}]
Alrighty, raises some more questions for me:
Hi again. I checked everything and did multiple debugs agan. The problem is not in database but in api. You see, this code:
const query = "SELECT username, email, surname, lastname, type, token, logged_in, class, timetable, password FROM users WHERE username = "myusername";";
const params = {
//username: username,
};
const result = await db.query(query, params);
works just fine, but when i try to use prepared statement, like:
const query = "SELECT username, email, surname, lastname, type, token, logged_in, class, timetable, password FROM users WHERE username = "$username";";
const params = {
username: username,
};
const result = await db.query(query, params);
or
const query = "SELECT username, email, surname, lastname, type, token, logged_in, class, timetable, password FROM users WHERE username = $username;";
const params = {
username: username,
};
const result = await db.query(query, params);
, it stops working
I continued debugging, and after I ran this code here, an error occured again:
result:
Maybe I am doing something wrong. I really like SurrealDB, but such bugs are driving me nuts...
@kearfy could you take a look?
@dikovmaxim
what will happen if you remove:
if (result.length < 0 || result[0].result.length < 1) {
return null;
}
and change:
return result[0].result[0];
to
return result[0][0]
It's just a guess from my side as its hard to reproduce your problem, as you provide only part of your code. But I'm pretty sure that is problem how you accessing response data.
If the above will not help, just try to find a minimal code that will result with your problem. For example, start with:
Check what is returned from SurrealDB, (do not wrap it in any extra functions):
const query = 'SELECT username, email, surname, lastname, type, token, logged_in, class, timetable, password FROM users WHERE username = $username;';
const params = {
username: 'test' // make sure that user with username = 'test' exists in database
};
const test = async () => {
try {
const result = await db.query(query, params);
console.log({ response: result[0][0] });
} catch (error) {
console.error('error:', error);
}
};
Then check what is logged out. Is it error or result? Is it an array or object?
I think that kind of the problem can be as well a mismatch with the permissions on table or authentication itself or even typo on table name (is it users? or user?). Let us know what is returned from the above code and then will be much easier to determine where the problem is.
I think the problem here was the example in docs not updated to v0.11.0
changes. @kearfy this little change should prevent similar problems (if I am right with guessing): surrealdb/docs.surrealdb.com#451
Describe the bug
Hi. I am pretty new to Surreal, so excuse me if I'm asking a dumb question, but I wasnt abe to find enough Information in docs. When I am creating a user, and then requesting it using Typescript and surrealdb.js, the user is created and is can be queried just normal:![image](https://github.com/surrealdb/surrealdb/assets/48867428/d2b072ce-c5a6-43ae-8f50-a648221a6862)
But when I restart the application and query it again, this is the object I get:![image](https://github.com/surrealdb/surrealdb/assets/48867428/fe084549-dc54-4c2b-8127-0624be5e73be)
Maybe it has something to do with the way Ts, or better to say Js Runtime is sting the data, but I have no Idea, why such a bug happens. Here is the code to create a user:![image](https://github.com/surrealdb/surrealdb/assets/48867428/734df0cd-0135-44a5-a6b3-6e6e714565b8)
And here is the code I am sing to query it:![image](https://github.com/surrealdb/surrealdb/assets/48867428/dedcd620-6fd5-4241-9889-62a7d476b495)
Maybe I kinda misunderstood the Surrealdb SQL syntax. Before using this code I covered it with tests and this is why I was sure everything should work just fine.
P.S. I also tried Select * ...
Here are the code snippets in case you want to copy them: ` try { const query = " SELECT username, email, surname, lastname, type, token, logged_in, class, timetable, password FROM type::table($tb) WHERE username = $username";
let created = await db.create("users:"+username,{ username: username, password: password, email: email, surname: surname, lastname: lastname, type: type, token: '', logged_in: false, class: null, timetable: null });
Steps to reproduce
Execute the SELECT statement
Expected behaviour
It always should return the![image](https://github.com/surrealdb/surrealdb/assets/48867428/d2b072ce-c5a6-43ae-8f50-a648221a6862)
SurrealDB version
1.0.0-beta.9+20230402.5eafebd for windows on x86_64
Contact Details
dikovmax04@gmail.com.
Is there an existing issue for this?
Code of Conduct