Skip to content

Commit

Permalink
fix-TableBuilder-schema不自动创建的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
aruis committed Sep 3, 2024
1 parent 80c0356 commit 5d62c34
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
@Path("/test")
public class TestController extends Scaffold implements ICURDAbility, ITableCreateAbility {

@Override
public String getSchemaName() {
return "test";
}

@Override
public String getMainTable() {
return "test_table";
Expand All @@ -18,7 +23,7 @@ public String getMainTable() {
@Override
public TableWrapper fitOutTable() {
return TableWrapper.withName(getMainTable())
.setSchema("public")
.setSchema(getSchemaName())
.setPrimaryKey(Column.ID_POSTGRES)
.addColumn(Column.of("name").setType("varchar"))
.addColumn(Column.of("t_create").setDefaultValue("now()"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public interface IMetadataAbility {

String getSchemaName();

String getMainTable();

default String getPK() {
Expand All @@ -21,11 +23,11 @@ default List<OrderColumn> getOrderColumns() {
}

default String getSelectOneRowSql() {
return "select * from " + getMainTable() + " where " + getPK() + "=:id";
return "select * from %s.%s where %s =:id".formatted(getSchemaName(), getMainTable(), getPK());
}

default String getSelectSql() {
return "select * from " + getMainTable();
return "select * from %s.%s".formatted(getSchemaName(), getMainTable());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public interface ISelectAbility extends IDatabaseAbility, IMetadataAbility {
@GET
@Path("/view")
default PageResult view(@QueryParam("page") int page, @QueryParam("limit") int limit, @QueryParam("orderField") String orderField, @QueryParam("orderType") String orderType) {

DBTable dbTable = getDatabase().getDBInfo().getTables().get(getMainTable());
DBTable dbTable = getDatabase().getDBInfo().getSchema(getSchemaName()).getTables().get(getMainTable());

List<OrderColumn> orderColumns = (orderField != null) ? List.of(new OrderColumn(orderField, orderType)) : getOrderColumns();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DBSchema getSchema(String schemaName) {
return schemas.stream()
.filter(schema -> schemaName.equals(schema.getName()))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Schema not found: " + schemaName));
.orElse(null);
}

public Map<String, DBTable> getTables() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class ModuleController implements ICURDAbility {
@Inject
IDatabaseAccess databaseAccess;

@Override
public String getSchemaName() {
return "platform";
}

@Override
public String getMainTable() {
return "app_module";
Expand Down

0 comments on commit 5d62c34

Please sign in to comment.