#
# Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

server:
  port: 8079
  host: 0.0.0.0
  features:
    print-details: true

tracing:
  service: jdbc-db

# docker run --rm --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=pokemon -e MYSQL_USER=user -e MYSQL_PASSWORD=password  mysql:5.7
db:
  source: jdbc
  connection:
    url: jdbc:mysql://127.0.0.1:3306/pokemon?useSSL=false
    username: user
    password: password
    poolName: mysql
    initializationFailTimeout: -1
    connectionTimeout: 2000
    helidon:
      pool-metrics:
        enabled: true
        # name prefix defaults to "db.pool." - if you have more than one client within a JVM, you may want to distinguish between them
        name-prefix: "hikari."
  services:
    tracing:
      - enabled: true
    metrics:
      - type: METER
  statements:
    ## Ping statement
    ping: "DO 0"
    ## Create database schema
    create-types: "CREATE TABLE Types (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)"
    create-pokemons: "CREATE TABLE Pokemons (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL, id_type INTEGER NOT NULL REFERENCES Type(id))"
    # Select all types
    select-all-types: "SELECT id, name FROM Types"
    # Select all pokemons without type information
    select-all-pokemons: "SELECT id, name, id_type FROM Pokemons"
    # Select pokemon by id
    select-pokemon-by-id: "SELECT id, name, id_type FROM Pokemons WHERE id = :id"
    # Select pokemon by name
    select-pokemon-by-name: "SELECT id, name, id_type FROM Pokemons WHERE name = ?"
    # Insert records into database
    insert-type: "INSERT INTO Types(id, name) VALUES(?, ?)"
    insert-pokemon: "INSERT INTO Pokemons(id, name, id_type) VALUES(?, ?, ?)"
    # Update name of pokemon specified by id
    update-pokemon-by-id: "UPDATE Pokemons SET name = :name, id_type = :idType WHERE id = :id"
    # Delete pokemon by id
    delete-pokemon-by-id: "DELETE FROM Pokemons WHERE id = :id"
    # Delete all types
    delete-all-types: "DELETE FROM Types"
    # Delete all pokemons
    delete-all-pokemons: "DELETE FROM Pokemons"
