Skip to content

Commit dd568c2

Browse files
authored
Add proper documentation for generated client APIs (#420)
* [Automated] Update the native jar versions * Add documentation for generated client * Fix test cases * Update changelog * Fix adding unnecessary field descriptions for No-SQL client * Fix test cases
1 parent 0747f38 commit dd568c2

File tree

202 files changed

+18351
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+18351
-27
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
### Added
10+
11+
- [Add documentation for generated client](https://github.com/ballerina-platform/ballerina-library/issues/8467)
12+
913
### Changed
1014
- [Fix an SQL script generation order issue when there are multiple associations](https://github.com/ballerina-platform/ballerina-library/issues/7921)
1115

persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_1/modules/persist_client.bal

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// AUTO-GENERATED FILE. DO NOT MODIFY.
2+
23
// This file is an auto-generated file by Ballerina persistence layer for model.
34
// It should not be modified by hand.
5+
46
import ballerina/jballerina.java;
57
import ballerina/persist;
68
import ballerina/sql;
@@ -13,6 +15,7 @@ const WORKSPACE = "workspaces";
1315
const BUILDING = "buildings";
1416
const DEPARTMENT = "departments";
1517

18+
# MySQL persist client.
1619
public isolated client class Client {
1720
*persist:AbstractPersistClient;
1821

@@ -122,16 +125,33 @@ public isolated client class Client {
122125
};
123126
}
124127

128+
# Get rows from Employee table.
129+
#
130+
# + targetType - Defines which fields to retrieve from the results
131+
# + whereClause - SQL WHERE clause to filter the results (e.g., `column_name = value`)
132+
# + orderByClause - SQL ORDER BY clause to sort the results (e.g., `column_name ASC`)
133+
# + limitClause - SQL LIMIT clause to limit the number of results (e.g., `10`)
134+
# + groupByClause - SQL GROUP BY clause to group the results (e.g., `column_name`)
135+
# + return - A collection of matching records or an error
125136
isolated resource function get employees(EmployeeTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream<targetType, persist:Error?> = @java:Method {
126137
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor",
127138
name: "query"
128139
} external;
129140

141+
# Get row from Employee table.
142+
#
143+
# + empNo - The value of the primary key field empNo
144+
# + targetType - Defines which fields to retrieve from the result
145+
# + return - The matching record or an error
130146
isolated resource function get employees/[string empNo](EmployeeTargetType targetType = <>) returns targetType|persist:Error = @java:Method {
131147
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor",
132148
name: "queryOne"
133149
} external;
134150

151+
# Insert rows into Employee table.
152+
#
153+
# + data - A list of records to be inserted
154+
# + return - The primary key value(s) of the inserted rows or an error
135155
isolated resource function post employees(EmployeeInsert[] data) returns string[]|persist:Error {
136156
psql:SQLClient sqlClient;
137157
lock {
@@ -142,6 +162,11 @@ public isolated client class Client {
142162
select inserted.empNo;
143163
}
144164

165+
# Update row in Employee table.
166+
#
167+
# + empNo - The value of the primary key field empNo
168+
# + value - The record containing updated field values
169+
# + return - The updated record or an error
145170
isolated resource function put employees/[string empNo](EmployeeUpdate value) returns Employee|persist:Error {
146171
psql:SQLClient sqlClient;
147172
lock {
@@ -151,6 +176,10 @@ public isolated client class Client {
151176
return self->/employees/[empNo].get();
152177
}
153178

179+
# Delete row from Employee table.
180+
#
181+
# + empNo - The value of the primary key field empNo
182+
# + return - The deleted record or an error
154183
isolated resource function delete employees/[string empNo]() returns Employee|persist:Error {
155184
Employee result = check self->/employees/[empNo].get();
156185
psql:SQLClient sqlClient;
@@ -161,16 +190,33 @@ public isolated client class Client {
161190
return result;
162191
}
163192

193+
# Get rows from Workspace table.
194+
#
195+
# + targetType - Defines which fields to retrieve from the results
196+
# + whereClause - SQL WHERE clause to filter the results (e.g., `column_name = value`)
197+
# + orderByClause - SQL ORDER BY clause to sort the results (e.g., `column_name ASC`)
198+
# + limitClause - SQL LIMIT clause to limit the number of results (e.g., `10`)
199+
# + groupByClause - SQL GROUP BY clause to group the results (e.g., `column_name`)
200+
# + return - A collection of matching records or an error
164201
isolated resource function get workspaces(WorkspaceTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream<targetType, persist:Error?> = @java:Method {
165202
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor",
166203
name: "query"
167204
} external;
168205

206+
# Get row from Workspace table.
207+
#
208+
# + workspaceId - The value of the primary key field workspaceId
209+
# + targetType - Defines which fields to retrieve from the result
210+
# + return - The matching record or an error
169211
isolated resource function get workspaces/[string workspaceId](WorkspaceTargetType targetType = <>) returns targetType|persist:Error = @java:Method {
170212
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor",
171213
name: "queryOne"
172214
} external;
173215

216+
# Insert rows into Workspace table.
217+
#
218+
# + data - A list of records to be inserted
219+
# + return - The primary key value(s) of the inserted rows or an error
174220
isolated resource function post workspaces(WorkspaceInsert[] data) returns string[]|persist:Error {
175221
psql:SQLClient sqlClient;
176222
lock {
@@ -181,6 +227,11 @@ public isolated client class Client {
181227
select inserted.workspaceId;
182228
}
183229

230+
# Update row in Workspace table.
231+
#
232+
# + workspaceId - The value of the primary key field workspaceId
233+
# + value - The record containing updated field values
234+
# + return - The updated record or an error
184235
isolated resource function put workspaces/[string workspaceId](WorkspaceUpdate value) returns Workspace|persist:Error {
185236
psql:SQLClient sqlClient;
186237
lock {
@@ -190,6 +241,10 @@ public isolated client class Client {
190241
return self->/workspaces/[workspaceId].get();
191242
}
192243

244+
# Delete row from Workspace table.
245+
#
246+
# + workspaceId - The value of the primary key field workspaceId
247+
# + return - The deleted record or an error
193248
isolated resource function delete workspaces/[string workspaceId]() returns Workspace|persist:Error {
194249
Workspace result = check self->/workspaces/[workspaceId].get();
195250
psql:SQLClient sqlClient;
@@ -200,16 +255,33 @@ public isolated client class Client {
200255
return result;
201256
}
202257

258+
# Get rows from Building table.
259+
#
260+
# + targetType - Defines which fields to retrieve from the results
261+
# + whereClause - SQL WHERE clause to filter the results (e.g., `column_name = value`)
262+
# + orderByClause - SQL ORDER BY clause to sort the results (e.g., `column_name ASC`)
263+
# + limitClause - SQL LIMIT clause to limit the number of results (e.g., `10`)
264+
# + groupByClause - SQL GROUP BY clause to group the results (e.g., `column_name`)
265+
# + return - A collection of matching records or an error
203266
isolated resource function get buildings(BuildingTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream<targetType, persist:Error?> = @java:Method {
204267
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor",
205268
name: "query"
206269
} external;
207270

271+
# Get row from Building table.
272+
#
273+
# + buildingCode - The value of the primary key field buildingCode
274+
# + targetType - Defines which fields to retrieve from the result
275+
# + return - The matching record or an error
208276
isolated resource function get buildings/[string buildingCode](BuildingTargetType targetType = <>) returns targetType|persist:Error = @java:Method {
209277
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor",
210278
name: "queryOne"
211279
} external;
212280

281+
# Insert rows into Building table.
282+
#
283+
# + data - A list of records to be inserted
284+
# + return - The primary key value(s) of the inserted rows or an error
213285
isolated resource function post buildings(BuildingInsert[] data) returns string[]|persist:Error {
214286
psql:SQLClient sqlClient;
215287
lock {
@@ -220,6 +292,11 @@ public isolated client class Client {
220292
select inserted.buildingCode;
221293
}
222294

295+
# Update row in Building table.
296+
#
297+
# + buildingCode - The value of the primary key field buildingCode
298+
# + value - The record containing updated field values
299+
# + return - The updated record or an error
223300
isolated resource function put buildings/[string buildingCode](BuildingUpdate value) returns Building|persist:Error {
224301
psql:SQLClient sqlClient;
225302
lock {
@@ -229,6 +306,10 @@ public isolated client class Client {
229306
return self->/buildings/[buildingCode].get();
230307
}
231308

309+
# Delete row from Building table.
310+
#
311+
# + buildingCode - The value of the primary key field buildingCode
312+
# + return - The deleted record or an error
232313
isolated resource function delete buildings/[string buildingCode]() returns Building|persist:Error {
233314
Building result = check self->/buildings/[buildingCode].get();
234315
psql:SQLClient sqlClient;
@@ -239,16 +320,33 @@ public isolated client class Client {
239320
return result;
240321
}
241322

323+
# Get rows from Department table.
324+
#
325+
# + targetType - Defines which fields to retrieve from the results
326+
# + whereClause - SQL WHERE clause to filter the results (e.g., `column_name = value`)
327+
# + orderByClause - SQL ORDER BY clause to sort the results (e.g., `column_name ASC`)
328+
# + limitClause - SQL LIMIT clause to limit the number of results (e.g., `10`)
329+
# + groupByClause - SQL GROUP BY clause to group the results (e.g., `column_name`)
330+
# + return - A collection of matching records or an error
242331
isolated resource function get departments(DepartmentTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream<targetType, persist:Error?> = @java:Method {
243332
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor",
244333
name: "query"
245334
} external;
246335

336+
# Get row from Department table.
337+
#
338+
# + deptNo - The value of the primary key field deptNo
339+
# + targetType - Defines which fields to retrieve from the result
340+
# + return - The matching record or an error
247341
isolated resource function get departments/[string deptNo](DepartmentTargetType targetType = <>) returns targetType|persist:Error = @java:Method {
248342
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor",
249343
name: "queryOne"
250344
} external;
251345

346+
# Insert rows into Department table.
347+
#
348+
# + data - A list of records to be inserted
349+
# + return - The primary key value(s) of the inserted rows or an error
252350
isolated resource function post departments(DepartmentInsert[] data) returns string[]|persist:Error {
253351
psql:SQLClient sqlClient;
254352
lock {
@@ -259,6 +357,11 @@ public isolated client class Client {
259357
select inserted.deptNo;
260358
}
261359

360+
# Update row in Department table.
361+
#
362+
# + deptNo - The value of the primary key field deptNo
363+
# + value - The record containing updated field values
364+
# + return - The updated record or an error
262365
isolated resource function put departments/[string deptNo](DepartmentUpdate value) returns Department|persist:Error {
263366
psql:SQLClient sqlClient;
264367
lock {
@@ -268,6 +371,10 @@ public isolated client class Client {
268371
return self->/departments/[deptNo].get();
269372
}
270373

374+
# Delete row from Department table.
375+
#
376+
# + deptNo - The value of the primary key field deptNo
377+
# + return - The deleted record or an error
271378
isolated resource function delete departments/[string deptNo]() returns Department|persist:Error {
272379
Department result = check self->/departments/[deptNo].get();
273380
psql:SQLClient sqlClient;
@@ -278,14 +385,26 @@ public isolated client class Client {
278385
return result;
279386
}
280387

388+
# Execute a custom SQL query and return results.
389+
#
390+
# + sqlQuery - The SQL query to execute
391+
# + rowType - Defines the structure of the result rows
392+
# + return - A collection of result rows or an error
281393
remote isolated function queryNativeSQL(sql:ParameterizedQuery sqlQuery, typedesc<record {}> rowType = <>) returns stream<rowType, persist:Error?> = @java:Method {
282394
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor"
283395
} external;
284396

397+
# Execute a custom SQL command (INSERT, UPDATE, DELETE, etc.).
398+
#
399+
# + sqlQuery - The SQL command to execute
400+
# + return - The execution result or an error
285401
remote isolated function executeNativeSQL(sql:ParameterizedQuery sqlQuery) returns psql:ExecutionResult|persist:Error = @java:Method {
286402
'class: "io.ballerina.stdlib.persist.sql.datastore.MySQLProcessor"
287403
} external;
288404

405+
# Close the database client and release connections.
406+
#
407+
# + return - An error if closing fails
289408
public isolated function close() returns persist:Error? {
290409
error? result = self.dbClient.close();
291410
if result is error {

0 commit comments

Comments
 (0)