Skip to content

Commit

Permalink
First prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
BjoernKW committed Dec 18, 2022
1 parent fdd2356 commit 4723438
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 105 deletions.
9 changes: 0 additions & 9 deletions docker-compose.yml

This file was deleted.

24 changes: 0 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<description>Database management UI for Spring Boot</description>
<properties>
<java.version>17</java.version>
<testcontainers.version>1.17.6</testcontainers.version>
<bootstrap.version>5.2.3</bootstrap.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
Expand Down Expand Up @@ -80,17 +79,6 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -107,18 +95,6 @@

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.jreleaser</groupId>
<artifactId>jreleaser-maven-plugin</artifactId>
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/bjoernkw/schematic/Column.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bjoernkw.schematic;

class Column {

String columnName;

String dataType;

public String getColumnName() {
return columnName;
}

public void setColumnName(String columnName) {
this.columnName = columnName;
}

public String getDataType() {
return dataType;
}

public void setDataType(String dataType) {
this.dataType = dataType;
}
}
37 changes: 37 additions & 0 deletions src/main/java/com/bjoernkw/schematic/Table.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.bjoernkw.schematic;

import java.util.List;
import java.util.Map;

class Table {

String tableName;

List<Column> columns;

List<Map<String, Object>> entries;

public String getTableName() {
return tableName;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

public List<Column> getColumns() {
return columns;
}

public void setColumns(List<Column> columns) {
this.columns = columns;
}

public List<Map<String, Object>> getEntries() {
return entries;
}

public void setEntries(List<Map<String, Object>> entries) {
this.entries = entries;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bjoernkw.schematic.database;
package com.bjoernkw.schematic;

import io.github.wimdeblauwe.hsbt.mvc.HxRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
Expand All @@ -15,15 +14,20 @@

@Controller
@RequestMapping("/tables")
@RequiredArgsConstructor
public class TablesController {

private static final String VIEW_MODEL_NAME = "tables";

private final JdbcTemplate jdbcTemplate;

public TablesController(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

@GetMapping
public String listTables(Model model) {
model.addAttribute(
"tables",
VIEW_MODEL_NAME,
getTables()
);

Expand All @@ -36,7 +40,7 @@ public String dropTable(@PathVariable String tableName, Model model) {
jdbcTemplate.execute("DROP TABLE " + tableName);

model.addAttribute(
"tables",
VIEW_MODEL_NAME,
getTables()
);

Expand All @@ -49,7 +53,7 @@ public String truncateTable(@PathVariable String tableName, Model model) {
jdbcTemplate.execute("TRUNCATE TABLE " + tableName);

model.addAttribute(
"tables",
VIEW_MODEL_NAME,
getTables()
);

Expand All @@ -58,7 +62,7 @@ public String truncateTable(@PathVariable String tableName, Model model) {

private List<Table> getTables() {
List<Table> tables = jdbcTemplate.query(
"SELECT table_name FROM INFORMATION_SCHEMA.Tables WHERE table_schema = 'public'",
"SELECT table_name FROM INFORMATION_SCHEMA.Tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'",
new BeanPropertyRowMapper<>(Table.class)
);
tables.forEach(table -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.bjoernkw.schematic.autoconfiguration;

import com.bjoernkw.schematic.TablesController;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;

@AutoConfiguration
@ConditionalOnWebApplication
public class SchematicAutoConfiguration {

private final JdbcTemplate jdbcTemplate;

public SchematicAutoConfiguration(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

@Bean
@ConditionalOnMissingBean
public TablesController tablesController() {
return new TablesController(jdbcTemplate);
}
}
11 changes: 0 additions & 11 deletions src/main/java/com/bjoernkw/schematic/database/Column.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/com/bjoernkw/schematic/database/IndexController.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/com/bjoernkw/schematic/database/Table.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.bjoernkw.schematic.autoconfiguration.SchematicAutoConfiguration=
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.bjoernkw.schematic.autoconfiguration.SchematicAutoConfiguration
12 changes: 0 additions & 12 deletions src/main/resources/application.yml

This file was deleted.

2 changes: 0 additions & 2 deletions src/main/resources/data.sql

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/resources/schema.sql

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/templates/fragments/tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns:hx="https://github.com/wimdeblauwe/htmx-spring-boot-thymeleaf">
<table class="table" th:if="${tables}" th:fragment="tables">
<table class="table table-striped table-hover" th:if="${tables}" th:fragment="tables">
<tbody>
<tr th:each="table : ${tables}">
<td>
<strong>[[${table.tableName}]]</strong>
<table class="table" th:if="${table.columns}">
<table class="table table-striped table-hover" th:if="${table.columns}">
<tbody>
<tr>
<td th:each="column : ${table.columns}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@SpringBootApplication
public class SchematicApplication {

public static void main(String[] args) {
SpringApplication.run(SchematicApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(SchematicApplication.class, args);
}

}
Empty file removed src/test/resources/application.yml
Empty file.

0 comments on commit 4723438

Please sign in to comment.