Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostgreSQL data type validation #264

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@
return isValidMysqlType(type);
case Constants.Datastores.MSSQL:
return isValidMssqlType(type);
case Constants.Datastores.POSTGRESQL:
return isValidPostgresqlType(type);

Check warning on line 96 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L96

Added line #L96 was not covered by tests
case Constants.Datastores.IN_MEMORY:
return isValidInMemoryType(type);
case Constants.Datastores.GOOGLE_SHEETS:
Expand All @@ -107,6 +109,8 @@
return isValidMysqlArrayType(type);
case Constants.Datastores.MSSQL:
return isValidMssqlArrayType(type);
case Constants.Datastores.POSTGRESQL:
return isValidPostgresqlArrayType(type);

Check warning on line 113 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L113

Added line #L113 was not covered by tests
case Constants.Datastores.IN_MEMORY:
return isValidInMemoryArrayType(type);
case Constants.Datastores.GOOGLE_SHEETS:
Expand All @@ -122,6 +126,8 @@
return isValidMysqlImportedType(modulePrefix, identifier);
case Constants.Datastores.MSSQL:
return isValidMssqlImportedType(modulePrefix, identifier);
case Constants.Datastores.POSTGRESQL:
return isValidPostgresqlImportedType(modulePrefix, identifier);

Check warning on line 130 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L130

Added line #L130 was not covered by tests
case Constants.Datastores.IN_MEMORY:
return isValidInMemoryImportedType(modulePrefix, identifier);
case Constants.Datastores.GOOGLE_SHEETS:
Expand Down Expand Up @@ -159,6 +165,21 @@
}
}

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

Check warning on line 176 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L176

Added line #L176 was not covered by tests
default:
return false;

Check warning on line 178 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L178

Added line #L178 was not covered by tests
}
}


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

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

Check warning on line 222 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L222

Added line #L222 was not covered by tests
default:
return false;

Check warning on line 224 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L224

Added line #L224 was not covered by tests
}
}


public static boolean isValidInMemoryArrayType(String type) {
return true;
}
Expand Down Expand Up @@ -233,6 +264,22 @@
}
}

public static boolean isValidPostgresqlImportedType(String modulePrefix, String identifier) {
if (!modulePrefix.equals(TIME_MODULE)) {
return false;

Check warning on line 269 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L269

Added line #L269 was not covered by tests
}
switch (identifier) {
case DATE:
case TIME_OF_DAY:
case UTC:
case CIVIL:
return true;

Check warning on line 276 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L276

Added line #L276 was not covered by tests
default:
return false;

Check warning on line 278 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java#L278

Added line #L278 was not covered by tests
}
}


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