Skip to content

Commit

Permalink
Merge pull request #265 from kaneeldias/postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
kaneeldias authored Nov 30, 2023
2 parents e850636 + 18d623b commit cca5690
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "persist"
version = "1.2.0"
version = "1.2.1"
authors = ["Ballerina"]
keywords = ["persist"]
repository = "https://github.com/ballerina-platform/module-ballerina-persist"
Expand All @@ -15,5 +15,5 @@ graalvmCompatible = true
[[platform.java17.dependency]]
groupId = "io.ballerina.persist"
artifactId = "persist-native"
version = "1.2.0"
path = "../native/build/libs/persist-native-1.2.0.jar"
version = "1.2.1"
path = "../native/build/libs/persist-native-1.2.1-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "persist-compiler-plugin"
class = "io.ballerina.stdlib.persist.compiler.PersistCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/persist-compiler-plugin-1.2.0.jar"
path = "../compiler-plugin/build/libs/persist-compiler-plugin-1.2.1-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ modules = [
[[package]]
org = "ballerina"
name = "persist"
version = "1.2.0"
version = "1.2.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- [Added compiler plugin validations for Postgresql as a datasource](https://github.com/ballerina-platform/ballerina-library/issues/5829)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,50 @@ public void validateEntityFieldTypeForMssql() {
);
}

@Test
public void validateEntityFieldTypeForPostgresql() {
List<Diagnostic> diagnostics = getErrorDiagnostics("project_6", "field-types.bal", 10);
testDiagnostic(
diagnostics,
new String[]{
PERSIST_306.getCode(),
PERSIST_305.getCode(),
PERSIST_306.getCode(),
PERSIST_306.getCode(),
PERSIST_305.getCode(),
PERSIST_305.getCode(),
PERSIST_306.getCode(),
PERSIST_305.getCode(),
PERSIST_306.getCode(),
PERSIST_306.getCode(),
},
new String[]{
"an entity does not support boolean array field type",
"an entity does not support json-typed field",
"an entity does not support json array field type",
"an entity does not support time:Civil array field type",
"an entity does not support union-typed field",
"an entity does not support error-typed field",
"an entity does not support error array field type",
"an entity does not support mysql:Client-typed field",
"an entity does not support mysql:Client array field type",
"an entity does not support enum array field type"
},
new String[]{
"(18:4,18:13)",
"(20:4,20:8)",
"(21:4,21:10)",
"(24:4,24:16)",
"(25:4,25:21)",
"(27:4,27:9)",
"(28:4,28:11)",
"(30:4,30:16)",
"(31:4,31:18)",
"(34:4,34:12)"
}
);
}

@Test
public void validateEntityFieldTypeForGoogleSheets() {
List<Diagnostic> diagnostics = getErrorDiagnostics("project_3", "field-types.bal", 12);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
org = "root"
name = "project_2"
version = "0.1.0"

[persist]
datastore = "postgresql"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import ballerina/time;
import ballerinax/mysql;
import ballerina/persist as _;

public enum Gender {
M,
F
}

public type MedicalNeed record {|
readonly int needId;
boolean booleanTest;
int itemId;
float floatTest;
decimal decimalTest;
string beneficiaryId;
byte[] beneficiaryIdByteArray;

boolean[] booleanArray;

json jsonTest;
json[] jsonArray;

time:Civil period;
time:Civil[] periodArray;
time:Civil|string unionType;

error errorType;
error[] errorArrayType;

mysql:Client clientType;
mysql:Client[] clientArrayType;

Gender gender;
Gender[] genderArray;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static final class Datastores {

public static final String MYSQL = "mysql";
public static final String MSSQL = "mssql";
public static final String POSTGRESQL = "postgresql";
public static final String IN_MEMORY = "inmemory";
public static final String GOOGLE_SHEETS = "googlesheets";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static boolean isValidSimpleType(String type, String datastore) {
return isValidMysqlType(type);
case Constants.Datastores.MSSQL:
return isValidMssqlType(type);
case Constants.Datastores.POSTGRESQL:
return isValidPostgresqlType(type);
case Constants.Datastores.IN_MEMORY:
return isValidInMemoryType(type);
case Constants.Datastores.GOOGLE_SHEETS:
Expand All @@ -107,6 +109,8 @@ public static boolean isValidArrayType(String type, String datastore) {
return isValidMysqlArrayType(type);
case Constants.Datastores.MSSQL:
return isValidMssqlArrayType(type);
case Constants.Datastores.POSTGRESQL:
return isValidPostgresqlArrayType(type);
case Constants.Datastores.IN_MEMORY:
return isValidInMemoryArrayType(type);
case Constants.Datastores.GOOGLE_SHEETS:
Expand All @@ -122,6 +126,8 @@ public static boolean isValidImportedType(String modulePrefix, String identifier
return isValidMysqlImportedType(modulePrefix, identifier);
case Constants.Datastores.MSSQL:
return isValidMssqlImportedType(modulePrefix, identifier);
case Constants.Datastores.POSTGRESQL:
return isValidPostgresqlImportedType(modulePrefix, identifier);
case Constants.Datastores.IN_MEMORY:
return isValidInMemoryImportedType(modulePrefix, identifier);
case Constants.Datastores.GOOGLE_SHEETS:
Expand Down Expand Up @@ -159,6 +165,20 @@ public static boolean isValidMssqlType(String type) {
}
}

public static boolean isValidPostgresqlType(String type) {
switch (type) {
case INT:
case BOOLEAN:
case DECIMAL:
case FLOAT:
case STRING:
case ENUM:
return true;
default:
return false;
}
}

public static boolean isValidInMemoryType(String type) {
return true;
}
Expand Down Expand Up @@ -195,6 +215,15 @@ public static boolean isValidMssqlArrayType(String type) {
}
}

public static boolean isValidPostgresqlArrayType(String type) {
switch (type) {
case BYTE:
return true;
default:
return false;
}
}

public static boolean isValidInMemoryArrayType(String type) {
return true;
}
Expand Down Expand Up @@ -233,6 +262,21 @@ public static boolean isValidMssqlImportedType(String modulePrefix, String ident
}
}

public static boolean isValidPostgresqlImportedType(String modulePrefix, String identifier) {
if (!modulePrefix.equals(TIME_MODULE)) {
return false;
}
switch (identifier) {
case DATE:
case TIME_OF_DAY:
case UTC:
case CIVIL:
return true;
default:
return false;
}
}

public static boolean isValidInMemoryImportedType(String modulePrefix, String identifier) {
return true;
}
Expand Down

0 comments on commit cca5690

Please sign in to comment.