Giter VIP home page Giter VIP logo

dynamic-table-query's Introduction

Dynamic Table Query by REST API

IMAGE ALT TEXT HERE

This is a simple Spring Boot application that allows you to execute dynamic SQL queries against a database using the javax.persistence.EntityManager API. The application exposes a REST endpoint that accepts a query parameter containing a SQL SELECT statement and returns the result set data as a list of JSON objects with named columns.

Requirements

  • Java 8 or higher
  • Spring Boot 2.5.0 or higher
  • H2 Database or any other relational database

Getting Started

  1. Clone this repository to your local machine.
  2. Open the project in your IDE.
  3. Run the application using mvn spring-boot:run or by running the DynamicQueryApplication class.
  4. Once the application is running, you can access the H2 Console by visiting http://localhost:8080/h2-console. Enter jdbc:h2:mem:dcbapp as the JDBC URL and click connect.
  5. You can then execute SQL queries using the executeDynamicQuery endpoint. The endpoint URL is http://localhost:8080/?query=. Replace with your desired SQL query.

Example

To execute a dynamic SQL query, make a GET request to the executeDynamicQuery endpoint with your desired SQL query as a parameter. For example, to retrieve all records from the employee table, you can make the following request:

GET http://localhost:8080/?query=SELECT * FROM employee

The response will be a JSON object containing the result set data. Here's an example response:

[
    {
        "ID": 1,
        "EMAIL": "[email protected]",
        "SALARY": 10000.00,
        "DEPARTMENT_ID": 1
    },
    {
        "ID": 2,
        "EMAIL": "[email protected]",
        "SALARY": 12000.00,
        "DEPARTMENT_ID": 1
    },
    {
        "ID": 3,
        "EMAIL": "[email protected]",
        "SALARY": 8000.00,
        "DEPARTMENT_ID": 2
    }
]
GET http://localhost:8080/?query=SELECT * FROM employee JOIN department ON employee.department_id = department.id
    [
        {
            "ID": 1,
            "EMAIL": "[email protected]",
            "SALARY": 10000,
            "DEPARTMENT_ID": 1,
            "NAME": "Engineering"
        },
        {
            "ID": 1,
            "EMAIL": "[email protected]",
            "SALARY": 12000,
            "DEPARTMENT_ID": 1,
            "NAME": "Engineering"
        },
        {
            "ID": 2,
            "EMAIL": "[email protected]",
            "SALARY": 8000,
            "DEPARTMENT_ID": 2,
            "NAME": "Sales"
        }
    ]

Limitations

This application is designed for demonstration and testing purposes only and should not be used in production environments. It does not provide any security or access control mechanisms and assumes that the database connection is trusted.

Contributing

If you find any issues with the project or want to contribute to its development, feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT License. See the LICENSE file for details.

dynamic-table-query's People

Contributors

buikhacnam avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.