surrealdb.java
surrealdb.java copied to clipboard
Feature: Add a method that checks if database is connected or not
Is your feature request related to a problem?
if somehow the connection dropped, there is no way to check if the driver is still connected or not, and you wont notice it until the application throws a exception
Describe the solution
a easy solution would be to add a method called checkConnetion or something that refers to checking the connection, the method would be a boolean and would return true if database is connected else false
Alternative methods
Yes, for now i am using a alternative way to check if its connected or not
public boolean checkConnection() {
try {
driver.ping();
} catch (Exception e) {
return false;
}
return true;
}
SurrealDB version
1.0.0
Contact Details
Is there an existing issue for this?
- [X] I have searched the existing issues
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Thanks for opening!
Is there any reason why would you need to know that the connection is severed if you aren't using the client? Surely, you would only need that information once you tried using the client, like in the existing solution, no?
well i run a discord bot, and it uses surrealdb, well for some reason the database dropped the connection, its been happning for quite a while recently, and sometimes even the surrealdb it self crashes, with this connection check we can atleast either try to reconnect to database or notify the issue, and might aswell connect to a backup
as for the issue with connection dropping i have asked this in surrealdb's discord and the devs has replied to it, but still its being discussed there
Are you able to capture the logs for the database crashing? And open an issue in the surrealdb/surrealdb repo for it - the database certainly shouldn't be crashing.
RE the disconnects - tcp connections can drop at any point and the only way to determine that the connection is dropped is with a timeout on receiving data. So a is connected
doesn't particularly work, unless we are relying on heartbeats. I am not sure if the driver currently supports heartbeats, but could definitely look into it. Either way, I don't think the helper function would be particularly useful - you can't really action the boolean. We should have event handling of a failed connection instead.
public boolean checkConnection() { try { driver.ping(); } catch (Exception e) { return false; }
return true;
}
The implementation would be slightly different. The protocol already supports pings (and we should add that to the driver). We would then use that liveness as the value.
We can certainly add this method, as I can see people wanting it even though it's not quite necessary. It would certainly help in determining if a client passed as an argument has been connected or not. So we can add this.
it would be great if you guys add one, thanks in advance