I started an intership last week and I will implement some APIs with Ballerina. For learning purposes I have created (based on the JDBC Client CRUD Operations Example on the Ballerina website) a DB client with some sample queries.
Here is some example code:
jdbc:Client testDB = new ({
url: "jdbc:mysql://localhost:3306/testDB?useLegacyDatetimeCode=false&serverTimezone=Europe/Vienna",
username: "testUser",
password: "password"
});
function db_getAllStudents() returns json {
var result = testDB->select("SELECT * FROM student;", Student);
if (result is table<record {}>) {
json jsonStudents = jsonutils:fromTable(result);
return jsonStudents;
}
}
When I run the code everything works without any problems.
But I get some warnings that the usage of jdbc:Client and the select function is deprecated:
warning: dsa/service:0.1.0::DBOperations.bal:6:1: usage of construct 'jdbc:Client' is deprecated
warning: dsa/service:0.1.0::DBOperations.bal:18:18: usage of construct 'testDB.select(SELECT * FROM
student;, Student)' is deprecated
Is there an alternative/newer construct to create a DB connection or to make select queries? I searched the official documentation but I could not find anything.