Skip to content

Commit

Permalink
Merge pull request #313 from kaneeldias/x
Browse files Browse the repository at this point in the history
  • Loading branch information
kaneeldias authored Oct 18, 2023
2 parents f998b22 + dbb9bdf commit 667d06c
Show file tree
Hide file tree
Showing 22 changed files with 676 additions and 58 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- [Fix the logic in persist client generation with respect to refColumns in the joinMetadata](https://github.com/ballerina-platform/persist-tools/issues/312)

## [1.2.0] - 2023-09-19

Expand All @@ -24,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Updated error messages to be consistent across all data sources](https://github.com/ballerina-platform/ballerina-standard-library/issues/4360)
- [Removed constraint ID from foreign keys in generated SQL scripts](https://github.com/ballerina-platform/ballerina-standard-library/issues/4581)


## [1.0.0] - 2021-06-01

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,11 @@ public void testGenerateEntityDotSeperatedModuleNames() {
executeCommand("tool_test_generate_64", GENERATE);
assertGeneratedSources("tool_test_generate_64");
}

@Test(enabled = true)
@Description("The model has multiple relations of various types")
public void testGenerateEntitiesWithMultipleRelations() {
executeCommand("tool_test_generate_65", GENERATE);
assertGeneratedSources("tool_test_generate_65");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
org = "foo"
name = "persist_generate_65"
version = "0.1.0"
distribution = "2201.3.0"

[build-options]
observabilityIncluded = false

[persist]
datastore = "mysql"
module = "persist_generate_65"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/io;

public function main() {
io:println("hello");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/persist as _;

type Book record {|
readonly string bookId;
string title;
string author;
decimal price;
int stock;
OrderItem? orderitem;
|};

type Order record {|
readonly string orderId;
string customerId;
string createdAt;
decimal totalPrice;
OrderItem[] orderItems;
Payment? payment;
|};

type OrderItem record {|
readonly string orderItemId;
int quantity;
decimal price;
Book book;
Order 'order;
|};

type Payment record {|
readonly string paymentId;
decimal paymentAmount;
string paymentDate;
Order 'order;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public isolated client class Client {
keyFields: ["empNo"],
joinMetadata: {
department: {entity: Department, fieldName: "department", refTable: "Department", refColumns: ["deptNo"], joinColumns: ["departmentDeptNo"], 'type: psql:ONE_TO_MANY},
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["employeeEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["workspaceEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
}
},
[WORKSPACE] : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public isolated client class Client {
"workspaces[].locationBuildingCode": {relation: {entityName: "workspaces", refField: "locationBuildingCode"}}
},
keyFields: ["buildingCode"],
joinMetadata: {workspaces: {entity: 'Workspace, fieldName: "workspaces", refTable: "'Workspace", refColumns: ["locationBuildingCode"], joinColumns: ["'buildingCode"], 'type: psql:MANY_TO_ONE}}
joinMetadata: {workspaces: {entity: 'Workspace, fieldName: "workspaces", refTable: "'Workspace", refColumns: ["locationBuildingCode"], joinColumns: ["buildingCode"], 'type: psql:MANY_TO_ONE}}
},
[DEPARTMENT] : {
entityName: "Department",
Expand Down Expand Up @@ -116,7 +116,7 @@ public isolated client class Client {
},
keyFields: ["workspaceId"],
joinMetadata: {
location: {entity: 'Building, fieldName: "location", refTable: "'Building", refColumns: ["'buildingCode"], joinColumns: ["locationBuildingCode"], 'type: psql:ONE_TO_MANY},
location: {entity: 'Building, fieldName: "location", refTable: "'Building", refColumns: ["buildingCode"], joinColumns: ["locationBuildingCode"], 'type: psql:ONE_TO_MANY},
employee: {entity: 'Employee, fieldName: "employee", refTable: "'Employee", refColumns: ["workspaceWorkspaceId"], joinColumns: ["workspaceId"], 'type: psql:ONE_TO_ONE}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public isolated client class Client {
keyFields: ["empNo"],
joinMetadata: {
department: {entity: Department, fieldName: "department", refTable: "Department", refColumns: ["deptNo"], joinColumns: ["departmentDeptNo"], 'type: psql:ONE_TO_MANY},
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["employeeEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["workspaceEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
}
},
[WORKSPACE] : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public isolated client class Client {
keyFields: ["empNo"],
joinMetadata: {
department: {entity: Department, fieldName: "department", refTable: "Department", refColumns: ["deptNo"], joinColumns: ["departmentDeptNo"], 'type: psql:ONE_TO_MANY},
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["employeeEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["workspaceEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
}
},
[WORKSPACE] : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public isolated client class Client {
keyFields: ["empNo"],
joinMetadata: {
department: {entity: Department, fieldName: "department", refTable: "Department", refColumns: ["deptNo"], joinColumns: ["departmentDeptNo"], 'type: psql:ONE_TO_MANY},
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["employeeEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["workspaceEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
}
},
[WORKSPACE] : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public isolated client class Client {
keyFields: ["id"],
joinMetadata: {
posts: {entity: Post, fieldName: "posts", refTable: "Post", refColumns: ["userId"], joinColumns: ["id"], 'type: psql:MANY_TO_ONE},
leader: {entity: Follow, fieldName: "leader", refTable: "Follow", refColumns: ["userId"], joinColumns: ["id"], 'type: psql:ONE_TO_ONE},
follower: {entity: Follow, fieldName: "follower", refTable: "Follow", refColumns: ["userId"], joinColumns: ["id"], 'type: psql:ONE_TO_ONE}
leader: {entity: Follow, fieldName: "leader", refTable: "Follow", refColumns: ["leaderId"], joinColumns: ["id"], 'type: psql:ONE_TO_ONE},
follower: {entity: Follow, fieldName: "follower", refTable: "Follow", refColumns: ["followerId"], joinColumns: ["id"], 'type: psql:ONE_TO_ONE}
}
},
[POST] : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public isolated client class Client {
keyFields: ["empNo"],
joinMetadata: {
department: {entity: Department, fieldName: "department", refTable: "Department", refColumns: ["deptNo"], joinColumns: ["departmentDeptNo"], 'type: psql:ONE_TO_MANY},
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["employeeEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["workspaceEmpNo"], joinColumns: ["empNo"], 'type: psql:ONE_TO_ONE}
}
},
[WORKSPACE] : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
org = "foo"
name = "persist_generate_65"
version = "0.1.0"
distribution = "2201.3.0"

[build-options]
observabilityIncluded = false

[persist]
datastore = "mysql"
module = "persist_generate_65"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[persist_generate_65]
host = "localhost"
port = 3306
user = "root"
password = ""
database = ""

Loading

0 comments on commit 667d06c

Please sign in to comment.