Skip to content

Commit

Permalink
Add support for postgresql data types
Browse files Browse the repository at this point in the history
  • Loading branch information
kaneeldias committed Nov 29, 2023
1 parent d501b4f commit 264bdff
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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);

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 @@ 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);

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 @@ 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);

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 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;

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 isValidMssqlArrayType(String type) {
}
}

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 isValidMssqlImportedType(String modulePrefix, String ident
}
}

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

0 comments on commit 264bdff

Please sign in to comment.