diff --git a/ballerina/client.bal b/ballerina/client.bal index b5c79a54..7398bcf9 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -33,7 +33,7 @@ public isolated client class Client { # + connectionPool - The `sql:ConnectionPool` to be used for the connection. If there is no # `connectionPool` provided, the global connection pool (shared by all clients) will be used # + return - An `sql:Error` if the client creation fails - public isolated function init(string host = "localhost", string? user = (), string? password = (), string? database = (), + public isolated function init(string host = "localhost", string? user = "root", string? password = (), string? database = (), int port = 3306, Options? options = (), sql:ConnectionPool? connectionPool = ()) returns sql:Error? { ClientConfiguration clientConfig = { host: host, diff --git a/ballerina/tests/connection-init-test.bal b/ballerina/tests/connection-init-test.bal index 3f1c3010..a9fb1420 100644 --- a/ballerina/tests/connection-init-test.bal +++ b/ballerina/tests/connection-init-test.bal @@ -44,6 +44,15 @@ function testWithoutHost() returns error? { test:assertExactEquals(exitCode, (), "Initialising connection without host fails."); } +@test:Config { + groups: ["connection", "connection-init"] +} +function testWithoutUser() returns error? { + Client dbClient = check new(host = host, port = port, password = password, database = connectDB); + sql:Error? closeResult = dbClient.close(); + test:assertExactEquals(closeResult, (), "Initialising connection without user fails."); +} + @test:Config { groups: ["connection", "connection-init"] } diff --git a/changelog.md b/changelog.md index 3a37bad7..1e34c718 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +- [Change default username for client initialization to `root`](https://github.com/ballerina-platform/ballerina-standard-library/issues/2397) + ## [1.4.0] - 2022-05-30 diff --git a/docs/proposals/default-username-for-client-connections.md b/docs/proposals/default-username-for-client-connections.md new file mode 100644 index 00000000..ce2b5881 --- /dev/null +++ b/docs/proposals/default-username-for-client-connections.md @@ -0,0 +1,36 @@ +# Define default username for client connections + +_Owners_: @kaneeldias +_Reviewers_: @daneshk @niveathika +_Created_: 2022/04/25 +_Updated_: 2022/04/22 +_Edition_: Swan Lake +_Issues_: [#2397](https://github.com/ballerina-platform/ballerina-standard-library/issues/2397) + +## Summary +Define default username to be used when connecting to a MySQL database on client initialization. + +## History +The 1.3.x versions and below of the MySQL package defaulted to connecting to the database without a username +attached (i.e. an empty string). + +## Goals +- Define the default username to be used when connecting to a MySQL database on client initialization. + +## Motivation +The ability to connect to common databases with default credentials (as opposed to manually defining) would make the +developer experience much more quick, simple and user-friendly, especially in testing scenarios. + +## Description +For MySQL databases, the default username is `root`[[1]](https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html) + +Modify the [client initialization method](https://github.com/ballerina-platform/module-ballerinax-mysql/blob/c2651da46c098ea6ef4a79079dc26cbd4d7cf54b/ballerina/client.bal#L36-L37) +signature to use `root` as the default value for the username instead of `()`. + +```ballerina + public isolated function init(string host = "localhost", string? user = "root", string? password = (), string? database = (), + int port = 1433, string instance = "", Options? options = (), sql:ConnectionPool? connectionPool = ()) returns sql:Error? { +``` + +## References +[1] https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html diff --git a/docs/spec/spec.md b/docs/spec/spec.md index a0ddf841..739a7b0b 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -3,7 +3,7 @@ _Owners_: @daneshk @niveathika _Reviewers_: @daneshk _Created_: 2022/01/14 -_Updated_: 2022/03/23 +_Updated_: 2022/04/25 _Edition_: Swan Lake _Issue_: [#2289](https://github.com/ballerina-platform/ballerina-standard-library/issues/2289) @@ -60,7 +60,7 @@ lifetime of the client. # `connectionPool` provided, the global connection pool (shared by all # clients) will be used # + return - An `sql:Error` if the client creation fails -public isolated function init(string host = "localhost", string? user = (), +public isolated function init(string host = "localhost", string? user = "root", string? password = (), string? database = (), int port = 3306, Options? options = (), sql:ConnectionPool? connectionPool = ()) returns sql:Error?; ```