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

mysql functions are now being created #167

Merged
merged 2 commits into from
Jan 21, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.homihq.db2rest.rest.read;

import com.homihq.db2rest.rest.read.model.CountResponse;
import com.homihq.db2rest.rest.read.dto.CountResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.homihq.db2rest.rest.read.helper.*;

import com.homihq.db2rest.rest.read.model.CountResponse;
import com.homihq.db2rest.rest.read.dto.CountResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.homihq.db2rest.rest.read;

import com.homihq.db2rest.rest.read.model.QueryRequest;
import com.homihq.db2rest.rest.read.dto.QueryRequest;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -47,7 +47,7 @@ public Object findByJoinTable(@PathVariable String tableName,
@PostMapping(value = "/query", consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> findByCustomQuery(@RequestBody @Valid QueryRequest queryRequest) {
log.debug("Execute SQL statement {} with params {}", queryRequest.getSql(), queryRequest.getParams());
log.debug("Execute SQL statement {} with params {}", queryRequest.sql(), queryRequest.params());
return ResponseEntity.ok(readService.findByCustomQuery(queryRequest));
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/homihq/db2rest/rest/read/ReadService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.homihq.db2rest.rest.read;

import com.homihq.db2rest.rest.read.helper.*;
import com.homihq.db2rest.rest.read.model.QueryRequest;
import com.homihq.db2rest.rest.read.dto.QueryRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -49,8 +49,8 @@ public Object findAll(String schemaName, String tableName, String select, String


Object findByCustomQuery(QueryRequest queryRequest) {
return queryRequest.isSingle() ?
namedParameterJdbcTemplate.queryForMap(queryRequest.getSql(), queryRequest.getParams()) :
namedParameterJdbcTemplate.queryForList(queryRequest.getSql(), queryRequest.getParams());
return queryRequest.single() ?
namedParameterJdbcTemplate.queryForMap(queryRequest.sql(), queryRequest.params()) :
namedParameterJdbcTemplate.queryForList(queryRequest.sql(), queryRequest.params());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.homihq.db2rest.rest.read.model;
package com.homihq.db2rest.rest.read.dto;

public record CountResponse(long count) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.homihq.db2rest.rest.read.dto;

import jakarta.validation.constraints.NotEmpty;
import java.util.Map;

public record QueryRequest(@NotEmpty(message = "Sql statement cannot be empty") String sql, Map<String, Object> params,
boolean single) {
}
19 changes: 0 additions & 19 deletions src/main/java/com/homihq/db2rest/rest/read/model/QueryRequest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class MySQLContainerConfiguration {

private static final MySQLContainer mySQLContainer = (MySQLContainer) new MySQLContainer("mysql:8.2")
.withDatabaseName("sakila")
.withUsername("mysql")
.withPassword("mysql")
.withUsername("root")
//.withPassword("mysql")
.withReuse(true);

static {
Expand All @@ -31,7 +31,7 @@ public class MySQLContainerConfiguration {
@Bean("mySQLDataSource")
public DataSource dataSource() {
var dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName("com.mysql.jdbc.Driver");
dataSourceBuilder.driverClassName("com.mysql.cj.jdbc.Driver");
dataSourceBuilder.url(mySQLContainer.getJdbcUrl());
dataSourceBuilder.username(mySQLContainer.getUsername());
dataSourceBuilder.password(mySQLContainer.getPassword());
Expand Down
16 changes: 15 additions & 1 deletion src/test/resources/mysql/mysql-sakila.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions src/test/resources/pg/postgres-sakila.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.