ca_path:
  Alpine: /etc/ssl/cert.pem
  Arch: /etc/ssl/certs/ca-certificates.crt
  CentOS: /etc/pki/tls/certs/ca-bundle.crt
  Debian: /etc/ssl/certs/ca-certificates.crt
  Fedora: /etc/pki/tls/certs/ca-bundle.crt
  macOS: /etc/ssl/cert.pem
  RedHat: /etc/pki/tls/certs/ca-bundle.crt
  OpenSUSE: /etc/ssl/ca-bundle.pem
  Ubuntu: /etc/ssl/certs/ca-certificates.crt
  Windows: <path_to_ca_cert>
  others: <path_to_ca_cert>
client_data:
  - id: mysql_cli
    display_name: MySQL CLI
    language: shell
    content:
      - type: serverless
        connection_string: mysql -u '${username}' -h ${host} -P ${port} -D test --ssl-mode=VERIFY_IDENTITY --ssl-ca=${ca_root_path} --comments -p${password}
      - type: dedicated
        comment: |-
          # version >= 5.7.11
        connection_string: mysql -u '${username}' -h ${host} -P ${port} -D test --ssl-mode=VERIFY_IDENTITY --ssl-ca=ca.pem --comments -p${password}
  - id: mycli
    display_name: MyCLI
    language: shell
    content:
      - type: serverless
        connection_string: mycli -u '${username}' -h ${host} -P ${port} -D test --ssl-ca=${ca_root_path} --ssl-verify-server-cert -p${password}
      - type: dedicated
        connection_string: mycli -u '${username}' -h ${host} -P ${port} -D test --ssl-ca=ca.pem --ssl-verify-server-cert -p${password}
  - id: mysqlclient
    display_name: mysqlclient
    language: python
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires mysqlclient package ('pip3 install mysqlclient'). Please check https://pypi.org/project/mysqlclient/ for install guide.
        connection_string: |-
          host="${host}", 
          user="${username}", 
          password="${password}", 
          port=${port}, 
          database="test",  
          ssl={"ca": "${ca_root_path}"}
        connection_example: |-
          import MySQLdb
  
          connection = MySQLdb.connect(
            host="${host}",
            port=${port},
            user="${username}",
            password="${password}",
            database="test",
            ssl={
              "ca": "${ca_root_path}"
            }
          )

          with connection:
            with connection.cursor() as cursor:
              cursor.execute("SELECT DATABASE();")
              m = cursor.fetchone()
              print(m[0])
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires mysqlclient package ('pip3 install mysqlclient'). Please check https://pypi.org/project/mysqlclient/ for install guide.
        connection_string: |-
          host="${host}", 
          user="${username}", 
          password="${password}", 
          port=${port}, 
          database="test",  
          ssl={"ca": "ca.pem"}
        connection_example: |-
          import MySQLdb
          
          connection = MySQLdb.connect(
            host="${host}",
            port=${port},
            user="${username}",
            password="${password}",
            database="test",
            ssl={
              "ca": "ca.pem"
            }
          )

          with connection:
            with connection.cursor() as cursor:
              cursor.execute("SELECT DATABASE();")
              m = cursor.fetchone()
              print(m[0])
  - id: mysql_connector_java
    display_name: MySQL Connector/J
    language: java
    content:
      - type: serverless
        comment: /* Be sure to replace the parameters in the following connection string. */
        connection_string: jdbc:mysql://${host}:${port}/test?user=${username}&password=${password}&sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3
        connection_example: |-
          import java.sql.*;

          public class Connection {
            public static void main(String args[]) throws ClassNotFoundException {
              Class.forName("com.mysql.cj.jdbc.Driver");
              try {
                java.sql.Connection conn = DriverManager.getConnection(
                    "jdbc:mysql://${host}:${port}/test?user=${username}&password=${password}&sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3"
                );
                Statement stmt = conn.createStatement();
                try {
                  ResultSet rs = stmt.executeQuery("SELECT DATABASE();");
                  if (rs.next()) {
                    System.out.println("using db: " + rs.getString(1));
                  }
                } catch (Exception e) {
                   System.out.println("exec error: " + e);
                }
              } catch (Exception e) {
                System.out.println("connect error: " + e);
              }
            }
          }
      - type: dedicated
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
          /* version >= 8.0.28 */
        connection_string: |-
          jdbc:mysql://${host}:${port}/test?user=${username}&password=${password}&sslMode=VERIFY_IDENTITY&tlsVersions=TLSv1.2&trustCertificateKeyStoreUrl=file:<your_custom_truststore_path>&trustCertificateKeyStorePassword=<your_truststore_password>
        connection_example: |-
          import com.mysql.jdbc.Driver;
          import java.sql.*;
  
          class Main {
            public static void main(String args[]) throws SQLException, ClassNotFoundException {
              Class.forName("com.mysql.cj.jdbc.Driver");
              try {
                Connection conn = DriverManager.getConnection(
                    "jdbc:mysql://${host}:${port}/test?user=${username}&password=${password}&sslMode=VERIFY_IDENTITY&tlsVersions=TLSv1.2&trustCertificateKeyStoreUrl=file:<your_custom_truststore_path>&trustCertificateKeyStorePassword=<your_truststore_password>"
                );
                Statement stmt = conn.createStatement();
                try {
                  ResultSet rs = stmt.executeQuery("SELECT DATABASE();");
                  if (rs.next()) {
                    System.out.println("using db:" + rs.getString(1));
                  }
                } catch (Exception e) {
                  System.out.println("exec error:" + e);
                }
              } catch (Exception e) {
                System.out.println("connect error:" + e);
              }
            }
          }
  - id: go_mysql_driver
    display_name: Go MySQL Driver
    language: go
    content:
      - type: serverless
        comment: /* Be sure to replace the parameters in the following connection string. */
        connection_string: |-
          mysql.RegisterTLSConfig("tidb", &tls.Config{
            MinVersion: tls.VersionTLS12,
            ServerName: "${host}",
          })

          db, err := sql.Open("mysql", "${username}:${password}@tcp(${host}:${port})/test?tls=tidb")
        connection_example: |-
          package main
  
          import (
              "crypto/tls"
              "database/sql"
              "fmt"
              "github.com/go-sql-driver/mysql"
              "log"
          )
  
          func main() {
              mysql.RegisterTLSConfig("tidb", &tls.Config{
                MinVersion: tls.VersionTLS12,
                ServerName: "${username}",
              })
  
              db, err := sql.Open("mysql", "${username}:${password}@tcp(${host}:${port})/test?tls=tidb")
              if err != nil {
                log.Fatal("failed to connect database", err)
              }
              defer db.Close()
  
              var dbName string
              err = db.QueryRow("SELECT DATABASE();").Scan(&dbName)
              if err != nil {
                log.Fatal("failed to execute query", err)
              }
              fmt.Println(dbName)
          }
      - type: dedicated
        comment: /* Be sure to replace the parameters in the following connection string. */
        connection_string: |-
          rootCertPool := x509.NewCertPool()
          pem, err := ioutil.ReadFile("ca.pem")
          if err != nil {
              log.Fatal(err)
          }
          if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
              log.Fatal("Failed to append PEM.")
          }
          mysql.RegisterTLSConfig("tidb", &tls.Config{
              RootCAs:    rootCertPool,
              MinVersion: tls.VersionTLS12,
              ServerName: "${host}",
          })

          db, err := sql.Open("mysql", "${username}:${password}@tcp(${host}:${port})/test?tls=tidb")
        connection_example: |-
          package main

          import (
              "crypto/tls"
              "database/sql"
              "fmt"
              "github.com/go-sql-driver/mysql"
              "log"
          )

          func main() {
              rootCertPool := x509.NewCertPool()
              pem, err := ioutil.ReadFile("ca.pem")
              if err != nil {
                log.Fatal(err)
              }
              if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
                log.Fatal("Failed to append PEM.")
              }
              mysql.RegisterTLSConfig("tidb", &tls.Config{
                RootCAs:    rootCertPool,
                MinVersion: tls.VersionTLS12,
                ServerName: "${host}",
              })

              db, err := sql.Open("mysql", "${username}:${password}@tcp(${host}:${port})/test?tls=tidb")
              if err != nil {
                log.Fatal("failed to connect database", err)
              }
              defer db.Close()

              var dbName string
              err = db.QueryRow("SELECT DATABASE();").Scan(&dbName)
              if err != nil {
                log.Fatal("failed to execute query", err)
              }
              fmt.Println(dbName)
          }
  - id: node_mysql2
    display_name: Node MySQL 2
    language: javascript
    content:
      - type: serverless
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
          /* Requires mysql2 package('npm install --save mysql2'). Please check https://www.npmjs.com/package/mysql2 for install guide. */
        connection_string: |-
          var connection = mysql.createConnection({
            host: '${host}',
            port: ${port},
            user: '${username}',
            password: '${password}',
            database: 'test',
            ssl: {
              minVersion: 'TLSv1.2',
              rejectUnauthorized: true
            }
          });
        connection_example: |-
          var mysql = require('mysql2');

          var connection = mysql.createConnection({
            host: '${host}',
            port: ${port},
            user: '${username}',
            password: '${password}',
            database: 'test',
            ssl: {
              minVersion: 'TLSv1.2',
              rejectUnauthorized: true
            }
          });
          connection.connect(function(err) {
            if (err) {
              throw err
            }
            connection.query('SELECT DATABASE();', function(err, rows) {
              if (err) {
                throw err
              }
              console.log(rows[0]['DATABASE()']);
              connection.end()
            });
          });
      - type: dedicated
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
          /* Requires mysql2 package('npm install --save mysql2'). Please check https://www.npmjs.com/package/mysql2 for install guide. */
        connection_string: |-
          var connection = mysql.createConnection({
            host: '${host}',
            port: ${port},
            user: '${username}',
            password: '${password}',
            database: 'test',
            ssl: {
              ca: fs.readFileSync('ca.pem'),
              minVersion: 'TLSv1.2',
              rejectUnauthorized: true
            }
          });
        connection_example: |-
          var mysql = require('mysql2');

          var connection = mysql.createConnection({
            host: '${host}',
            port: ${port},
            user: '${username}',
            password: '${password}',
            database: 'test',
            ssl: {
              ca: fs.readFileSync('ca.pem'),
              minVersion: 'TLSv1.2',
              rejectUnauthorized: true
            }
          });
          connection.connect(function(err) {
            if (err) {
              throw err
            }
            connection.query('SELECT DATABASE();', function(err, rows) {
              if (err) {
                throw err
              }
              console.log(rows[0]['DATABASE()']);
              connection.end()
            });
          });
  - id: general
    display_name: General
    content:
      - type: serverless
        connection_string: |-
          Host: ${host}
          Username: ${username}
          Port: ${port}
          Password: ${password}
      - type: dedicated
        connection_string: |-
          Host: ${host}
          Username: ${username}
          Port: ${port}
          Password: ${password}
  - id: mybatis
    display_name: MyBatis
    language: xml
    content:
      - type: serverless
        comment: <!-- Be sure to replace the parameters in the following connection string. -->
        connection_string: |-
          <property name="driver" value="com.mysql.jdbc.Driver"/>
          <property name="url" value="jdbc:mysql://${host}:${port}/test?sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3"/>
          <property name="username" value="${username}"/>
          <property name="password" value="${password}"/>
      - type: dedicated
        comment: <!-- Be sure to replace the parameters in the following connection string. -->
        connection_string: |-
          <property name="driver" value="com.mysql.jdbc.Driver"/>
          <property name="url" value="jdbc:mysql://${host}:${port}/test?sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3&trustCertificateKeyStoreUrl=file:<your_custom_truststore_path>&trustCertificateKeyStorePassword=<your_truststore_password>"/>
          <property name="username" value="${username}"/>
          <property name="password" value="${password}"/>
  - id: hibernate
    display_name: Hibernate
    language: xml
    content:
      - type: serverless
        comment: <!-- Be sure to replace the parameters in the following connection string. -->
        connection_string: |-
          <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
          <property name="hibernate.dialect">org.hibernate.dialect.TiDBDialect</property>
          <property name="hibernate.connection.url">jdbc:mysql://${host}:${port}/test?sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3</property>
          <property name="hibernate.connection.username">${username}</property>
          <property name="hibernate.connection.password">${password}</property>
          <property name="hibernate.connection.autocommit">false</property>
      - type: dedicated
        comment: <!-- Be sure to replace the parameters in the following connection string. -->
        connection_string: |-
          <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
          <property name="hibernate.dialect">org.hibernate.dialect.TiDBDialect</property>
          <property name="hibernate.connection.url">jdbc:mysql://${host}:${port}/test?sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3&trustCertificateKeyStoreUrl=file:<your_custom_truststore_path>&trustCertificateKeyStorePassword=<your_truststore_password></property>
          <property name="hibernate.connection.username">${username}</property>
          <property name="hibernate.connection.password">${password}</property>
          <property name="hibernate.connection.autocommit">false</property>
  - id: spring_boot
    display_name: Spring Boot
    language: yaml
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
        connection_string: |-
          spring:
            datasource:
              url: jdbc:mysql://${host}:${port}/test?sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3
              username: ${username}
              password: ${password}
              driver-class-name: com.mysql.cj.jdbc.Driver
            jpa:
              show-sql: true
              database-platform: org.hibernate.dialect.TiDBDialect
              hibernate:
                ddl-auto: create-drop
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
        connection_string: |-
          spring:
            datasource:
              url: jdbc:mysql://${host}:${port}/test?sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3&trustCertificateKeyStoreUrl=file:<your_custom_truststore_path>&trustCertificateKeyStorePassword=<your_truststore_password>
              username: ${username}
              password: ${password}
              driver-class-name: com.mysql.cj.jdbc.Driver
            jpa:
              show-sql: true
              database-platform: org.hibernate.dialect.TiDBDialect
              hibernate:
                ddl-auto: create-drop
  - id: gorm
    display_name: GORM
    language: go
    content:
      - type: serverless
        comment: /* Be sure to replace the parameters in the following connection string. */
        connection_string: |-
          mysql.RegisterTLSConfig("tidb", &tls.Config{
            MinVersion: tls.VersionTLS12,
            ServerName: "${host}",
          })

          dsn := "${username}:${password}@tcp(${host}:${port})/test?tls=tidb"
        connection_example: |-
          package main

          import (
             "crypto/tls"
             "fmt"
             "github.com/go-sql-driver/mysql"
             gormmysql "gorm.io/driver/mysql"
             "gorm.io/gorm"
             "log"
          )

          func main() {
             mysql.RegisterTLSConfig("tidb", &tls.Config{
                MinVersion: tls.VersionTLS12,
                ServerName: "${host}",
             })
             dsn := "${username}:${password}@tcp(${host}:${port})/test?tls=tidb"

             db, err := gorm.Open(gormmysql.Open(dsn), &gorm.Config{})
             if err != nil {
                log.Fatal("failed to connect database", err)
             }

             var dbname string
             db.Raw("SELECT DATABASE()").Scan(&dbname)
             fmt.Println(dbname)
          }
      - type: dedicated
        comment: /* Be sure to replace the parameters in the following connection string. */
        connection_string: |-
          rootCertPool := x509.NewCertPool()
          pem, err := ioutil.ReadFile("ca.pem")
          if err != nil {
              log.Fatal(err)
          }
          if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
              log.Fatal("Failed to append PEM.")
          }
          mysql.RegisterTLSConfig("tidb", &tls.Config{
              RootCAs:    rootCertPool,
              MinVersion: tls.VersionTLS12,
              ServerName: "${host}",
          })

          dsn := "${username}:${password}@tcp(${host}:${port})/test?tls=tidb"
        connection_example: |-
          package main

          import (
             "crypto/tls"
             "crypto/x509"
             "fmt"
             "github.com/go-sql-driver/mysql"
             gormmysql "gorm.io/driver/mysql"
             "gorm.io/gorm"
             "io/ioutil"
             "log"
          )

          func main() {
             rootCertPool := x509.NewCertPool()
             pem, err := ioutil.ReadFile("ca.pem")
             if err != nil {
                log.Fatal(err)
             }
             if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
                log.Fatal("Failed to append PEM.")
             }
             mysql.RegisterTLSConfig("tidb", &tls.Config{
                RootCAs:    rootCertPool,
                MinVersion: tls.VersionTLS12,
                ServerName: "${host}",
             })

             dsn := "${username}:${password}@tcp(${host}:${port})/test?tls=tidb"

             db, err := gorm.Open(gormmysql.Open(dsn), &gorm.Config{})
             if err != nil {
                log.Fatal("failed to connect database", err)
             }

             var dbname string
             db.Raw("SELECT DATABASE()").Scan(&dbname)
             fmt.Println(dbname)
          }
  - id: prisma
    display_name: Prisma
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
        connection_string: |-
          datasource db {
            provider = "mysql"
            url      = "mysql://${username}:${password}@${host}:${port}/test?sslaccept=strict"
          }
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
        connection_string: |-
          datasource db {
            provider = "mysql"
            url      = "mysql://${username}:${password}@${host}:${port}/test?sslcert=ca.pem"
          }
  - id: sequelize_mysql2
    display_name: Sequelize (mysql2)
    language: javascript
    content:
      - type: serverless
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
          /* Requires mysql2 package('npm install --save mysql2'). Please check https://www.npmjs.com/package/mysql2 for install guide. */
          /* Requires sequelize package('npm install --save sequelize'). Please check https://www.npmjs.com/package/sequelize for install guide. */
        connection_string: |-
          const sequelize = new Sequelize("test", ${username}, ${password}, {
            host: '${host}',
            port: ${port},
            dialect: 'mysql',
            dialectOptions: {
              ssl: {
                minVersion: 'TLSv1.2',
                rejectUnauthorized: true
              }
            }
          });
        connection_example: |-
          const Sequelize = require('sequelize');

          const sequelize = new Sequelize("test", ${username}, ${password}, {
            host: '${host}',
            port: ${port},
            dialect: 'mysql',
            dialectOptions: {
              ssl: {
                minVersion: 'TLSv1.2',
                rejectUnauthorized: true
              }
            }
          });

          (async () => {
            try {
              const [results, metadata] = await sequelize.query("SHOW DATABASES");
              console.log(results);
            } catch (err) {
              console.error("error executing query:", err);
            } finally {
              await sequelize.close();
            }
          })();
      - type: dedicated
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
          /* Requires mysql2 package('npm install --save mysql2'). Please check https://www.npmjs.com/package/mysql2 for install guide. */
          /* Requires sequelize package('npm install --save sequelize'). Please check https://www.npmjs.com/package/sequelize for install guide. */
        connection_string: |-
          const sequelize = new Sequelize("test", ${username}, ${password}, {
            host: '${host}',
            port: ${port},
            dialect: 'mysql',
            dialectOptions: {
              ssl: {
                ca: fs.readFileSync('ca.pem'),
                minVersion: 'TLSv1.2',
                rejectUnauthorized: true
              }
            }
          });
        connection_example: |-
          const { Sequelize } = require('sequelize');
          const fs = require("fs");

          const sequelize = new Sequelize("test", ${username}, ${password}, {
            host: '${host}',
            port: ${port},
            dialect: 'mysql',
            dialectOptions: {
              ssl: {
                ca: fs.readFileSync('ca.pem'),
                minVersion: 'TLSv1.2',
                rejectUnauthorized: true
              }
            }
          });

          (async () => {
            try {
              const [results, metadata] = await sequelize.query("SHOW DATABASES");
              console.log(results);
            } catch (err) {
              console.error("error executing query:", err);
            } finally {
              await sequelize.close();
            }
          })();
  - id: django_tidb
    display_name: Django (django_tidb)
    language: python
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires django_tidb package ('pip3 install django_tidb'). Please check https://pypi.org/project/django_tidb/ for install guide.
        connection_string: |-
          DATABASES = {
              'default': {
                  'ENGINE': 'django_tidb',
                  'NAME': 'test',
                  'USER': '${username}',
                  'PASSWORD': '${password}',
                  'HOST': '${host}',
                  'PORT': '${port}',
                  'OPTIONS': {
                      'ssl': {
                          'sslmode': 'VERIFY_IDENTITY',
                          'ca': '${ca_root_path}'
                      }
                  }
              },
          }
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires django_tidb package ('pip3 install django_tidb'). Please check https://pypi.org/project/django_tidb/ for install guide.
        connection_string: |-
          DATABASES = {
              'default': {
                  'ENGINE': 'django_tidb',
                  'NAME': 'test',
                  'USER': '${username}',
                  'PASSWORD': '${password}',
                  'HOST': '${host}',
                  'PORT': '${port}',
                  'OPTIONS': {
                      'ssl': {
                          'sslmode': 'VERIFY_IDENTITY',
                          'ca': 'ca.pem'
                      }
                  }
              },
          }
  - id: sqlalchemy_mysqlclient
    display_name: SQLAlchemy (mysqlclient)
    language: python
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires mysqlclient package ('pip3 install mysqlclient'). Please check https://pypi.org/project/mysqlclient/ for install guide.
          # Requires sqlalchemy package ('pip3 install sqlalchemy'). Please check https://pypi.org/project/sqlalchemy/ for install guide.
        connection_string: |-
          DATABASE_URL = "mysql+mysqldb://${username}:${password}@${host}:${port}/test?ssl_ca=${ca_root_path}"
        connection_example: |-
          import os
          from sqlalchemy import create_engine, text

          DATABASE_URL = "mysql+mysqldb://${username}:${password}@${host}:${port}/test?ssl_ca=${ca_root_path}"
          engine = create_engine(DATABASE_URL)
          conn = engine.connect()
          res = conn.execute(text("SHOW DATABASES")).fetchall()
          print(res)
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires mysqlclient package ('pip3 install mysqlclient'). Please check https://pypi.org/project/mysqlclient/ for install guide.
          # Requires sqlalchemy package ('pip3 install sqlalchemy'). Please check https://pypi.org/project/sqlalchemy/ for install guide.
        connection_string: |-
          DATABASE_URL = "mysql+mysqldb://${username}:${password}@${host}:${port}/test?ssl_ca=ca.pem"
        connection_example: |-
          import os
          from sqlalchemy import create_engine, text

          DATABASE_URL = "mysql+mysqldb://${username}:${password}@${host}:${port}/test?ssl_ca=ca.pem"
          engine = create_engine(DATABASE_URL)
          conn = engine.connect()
          res = conn.execute(text("SHOW DATABASES")).fetchall()
          print(res)
  - id: mysql2_ruby
    display_name: Mysql2 (Ruby)
    language: ruby
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires mysql2 package ('gem install mysql2'). Please check https://github.com/brianmario/mysql2#readme for install guide.
        connection_string: |-
          client = Mysql2::Client.new(
              host: '${host}',
              username: '${username}',
              password: '${password}',
              port: ${port},
              database: 'test',
              ssl_mode: :verify_ca,
          )
        connection_example: |-
          #!/usr/bin/ruby
          require 'mysql2'

          begin
              client = Mysql2::Client.new(
                  host: '${host}',
                  username: '${username}',
                  password: '${password}',
                  port: ${port},
                  database: 'test',
                  ssl_mode: :verify_ca,
              )
              result = client.query('SHOW DATABASES')
              p result.first
              client.close if client
          end
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires mysql2 package ('gem install mysql2'). Please check https://github.com/brianmario/mysql2#readme for install guide.
        connection_string: |-
          client = Mysql2::Client.new(
              host: '${host}',
              username: '${username}',
              password: '${password}',
              port: ${port},
              database: 'test',
              ssl_mode: :verify_ca,
              sslca: 'ca.pem',
              sslverify: true
          )
        connection_example: |-
          #!/usr/bin/ruby
          require 'mysql2'

          begin
              client = Mysql2::Client.new(
                  host: '${host}',
                  username: '${username}',
                  password: '${password}',
                  port: ${port},
                  database: 'test',
                  ssl_mode: :verify_ca,
                  sslca: 'ca.pem',
                  sslverify: true
              )
              result = client.query('SHOW DATABASES')
              p result.first
              client.close if client
          end
  - id: active_record
    display_name: Active Record
    language: ruby
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
        connection_string: |-
          default: &default
            adapter: mysql2
            host: '${host}',
            username: '${username}',
            password: '${password}',
            port: ${port},
            database: 'test',
            ssl_mode: :verify_ca,
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
        connection_string: |-
          default: &default
            adapter: mysql2
            host: '${host}',
            username: '${username}',
            password: '${password}',
            port: ${port},
            database: 'test',
            ssl_mode: :verify_ca,
            sslca: 'ca.pem',
  - id: mysqli
    display_name: MySQLi
    language: php
    content:
      - type: serverless
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
        connection_string: |-
          $host = "${port}";
          $username = "${username}";
          $password = "${password}";
          $database = 'test';
          $port = ${port};
          $ca_root_path = "${ca_root_path}";
        connection_example: |-
          <?php
          $host = "${port}";
          $username = "${username}";
          $password = "${password}";
          $database = 'test';
          $port = ${port};
          $ca_root_path = "${ca_root_path}";

          $mysqli = mysqli_init();
          $mysqli->ssl_set(NULL, NULL, $ca_root_path, NULL, NULL);
          $mysqli->real_connect($host, $username, $password, $database, $port);
          $result = $mysqli->query('SHOW DATABASES');
          while ( $data = $result->fetch_array() ) {
                echo $data[0];
                echo "\n";
          }
          ?>
      - type: dedicated
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
        connection_string: |-
          $host = "${port}";
          $username = "${username}";
          $password = "${password}";
          $database = 'test';
          $port = ${port};
          $ca_root_path = "ca.pem";
        connection_example: |-
          <?php
          $host = "${port}";
          $username = "${username}";
          $password = "${password}";
          $database = 'test';
          $port = ${port};
          $ca_root_path = "ca.pem";

          $mysqli = mysqli_init();
          $mysqli->ssl_set(NULL, NULL, $ca_root_path, NULL, NULL);
          $mysqli->real_connect($host, $username, $password, $database, $port);
          $result = $mysqli->query('SHOW DATABASES');
          while ( $data = $result->fetch_array() ) {
                echo $data[0];
                echo "\n";
          }
          ?>
  - id: libmysqlclient
    display_name: libmysqlclient
    language: c++
    content:
      - type: serverless
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
          /* Requires libmysqlclient package. Please check https://dev.mysql.com/downloads/c-api/ for install guide. */
        connection_string: |-
          string host = "${host}";
          string username = "${username}";
          string password = "${password}";
          string database = "test";
          int port = ${port};
          int ssl_mode = SSL_MODE_VERIFY_IDENTITY;
          string ca_root_path = "${ca_root_path}";
        connection_example: |-
          #include <iostream>
          #include "mysql.h"

          using namespace std;

          int main() {
              MYSQL mysql;
              MYSQL *conn;
              MYSQL_RES *resultset;
              MYSQL_ROW row;
              int ssl_mode = SSL_MODE_VERIFY_IDENTITY;

              mysql_init(&mysql);
              mysql_options(&mysql, MYSQL_OPT_SSL_MODE, &ssl_mode);
              mysql_options(&mysql, MYSQL_OPT_SSL_CA, "${ca_root_path}");
              conn = mysql_real_connect(&mysql, "${host}", "${username}", "${password}", "test", ${port}, NULL, 0);
              mysql_query(conn, "SHOW DATABASES");
              resultset = mysql_store_result(conn);
              while((row = mysql_fetch_row(resultset))){
                  for (int i = 0; i < mysql_num_fields(resultset) ; i++)
                      cout << (row[i]) << endl;
              }
              mysql_free_result(resultset);
              mysql_close(conn) ;
          }
      - type: dedicated
        comment: |-
          /* Be sure to replace the parameters in the following connection string. */
          /* Requires libmysqlclient package. Please check https://dev.mysql.com/downloads/c-api/ for install guide. */
        connection_string: |-
          string host = "${host}";
          string username = "${username}";
          string password = "${password}";
          string database = "test";
          int port = ${port};
          int ssl_mode = SSL_MODE_VERIFY_IDENTITY;
          string ca_root_path = "ca.pem";
        connection_example: |-
          #include <iostream>
          #include "mysql.h"

          using namespace std;

          int main() {
              MYSQL mysql;
              MYSQL *conn;
              MYSQL_RES *resultset;
              MYSQL_ROW row;
              int ssl_mode = SSL_MODE_VERIFY_IDENTITY;
          
              mysql_init(&mysql);
              mysql_options(&mysql, MYSQL_OPT_SSL_MODE, &ssl_mode);
              mysql_options(&mysql, MYSQL_OPT_SSL_CA, "ca.pem");
              conn = mysql_real_connect(&mysql, "${host}", "${username}", "${password}", "test", ${port}, NULL, 0);
              mysql_query(conn, "SHOW DATABASES");
              resultset = mysql_store_result(conn);
              while((row = mysql_fetch_row(resultset))){
                  for (int i = 0; i < mysql_num_fields(resultset) ; i++)
                      cout << (row[i]) << endl;
              }
              mysql_free_result(resultset);
              mysql_close(conn) ;
          }
  - id: pymysql
    display_name: PyMySQL
    language: python
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires pymysql package ('pip3 install pymysql'). Please check https://pypi.org/project/pymysql/ for install guide.
        connection_string: |-
          host = '${host}',
          user = '${username}',
          port = ${port},
          password = '${password}',
          database = 'test',
          ssl_ca = '${ca_root_path}',
          ssl_verify_cert = True,
          ssl_verify_identity = True
        connection_example: |-
          import pymysql

          connection = pymysql.connect(host = '${host}',
                                       user = '${username}',
                                       port = ${port},
                                       password = '${password}',
                                       database = 'test',
                                       ssl_ca = '${ca_root_path}',
                                       ssl_verify_cert = True,
                                       ssl_verify_identity = True)
          cursor = connection.cursor()
          cursor.execute("SHOW DATABASES")
          data = cursor.fetchall()
          print(data)
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires pymysql package ('pip3 install pymysql'). Please check https://pypi.org/project/pymysql/ for install guide.
        connection_string: |-
          host = '${host}',
          user = '${username}',
          port = ${port},
          password = '${password}',
          database = 'test',
          ssl_ca = 'ca.pem',
          ssl_verify_cert = True,
          ssl_verify_identity = True
        connection_example: |-
          import pymysql

          connection = pymysql.connect(host = '${host}',
                                       user = '${username}',
                                       port = ${port},
                                       password = '${password}',
                                       database = 'test',
                                       ssl_ca = 'ca.pem',
                                       ssl_verify_cert = True,
                                       ssl_verify_identity = True)
          cursor = connection.cursor()
          cursor.execute("SHOW DATABASES")
          data = cursor.fetchall()
          print(data)
  - id: mysql_connector_python
    display_name: MySQL Connector/Python
    language: python
    content:
      - type: serverless
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires pymysql package ('pip3 install mysql-connector-python'). Please check https://pypi.org/project/mysql-connector-python/ for install guide.
        connection_string: |-
          host = '${host}',
          user = '${username}',
          port = ${port},
          password = '${password}',
          database = 'test',
          ssl_ca = '${ca_root_path}',
          ssl_verify_identity = True
        connection_example: |-
          import mysql.connector

          connection = mysql.connector.connect(host = '${host}',
                                       user = '${username}',
                                       port = ${port},
                                       password = '${password}',
                                       database = 'test',
                                       ssl_ca =' ${ca_root_path}',
                                       ssl_verify_identity = True)
          cursor = connection.cursor()
          cursor.execute("SHOW DATABASES")
          data = cursor.fetchall()
          print(data)
      - type: dedicated
        comment: |-
          # Be sure to replace the parameters in the following connection string.
          # Requires pymysql package ('pip3 install mysql-connector-python'). Please check https://pypi.org/project/mysql-connector-python/ for install guide.
        connection_string: |-
          host = '${host}',
          user = '${username}',
          port = ${port},
          password = '${password}',
          database = 'test',
          ssl_ca = 'ca.pem',
          ssl_verify_identity = True
        connection_example: |-
          import mysql.connector

          connection = mysql.connector.connect(host = '${host}',
                                       user = '${username}',
                                       port = ${port},
                                       password ='${password}',
                                       database = 'test',
                                       ssl_ca = 'ca.pem',
                                       ssl_verify_identity = True)
          cursor = connection.cursor()
          cursor.execute("SHOW DATABASES")
          data = cursor.fetchall()
          print(data)
  - id: mysql_rust
    display_name: mysql (Rust)
    language: rust
    content:
      - type: serverless
        comment: /* Be sure to replace the parameters in the following connection string. */
        connection_string: database_url = "mysql://${username}:${password}@${host}:${port}/test";
        connection_example: |-
          use mysql::*;
          use mysql::prelude::*;

          fn main() {
              let database_url = "mysql://${username}:${password}@${host}:${port}/test";
              let sslOpts = SslOpts::default();
              let builder = OptsBuilder::from_opts(Opts::from_url(&database_url).unwrap()).ssl_opts(sslOpts);
              let pool = Pool::new(builder).unwrap();
              let mut conn = pool.get_conn().unwrap();
              let val: Vec<String> = conn.query("SHOW DATABASES").unwrap();
              println!("{:?}", val)
          }
      - type: serverless
        comment: /* Be sure to replace the parameters in the following connection string. */
        connection_string: database_url = "mysql://${username}:${password}@${host}:${port}/test";
        connection_example: |-
          use mysql::*;
          use mysql::prelude::*;

          fn main() {
              let database_url = "mysql://${username}:${password}@${host}:${port}/test";
              let sslOpts = SslOpts::default();
              let builder = OptsBuilder::from_opts(Opts::from_url(&database_url).unwrap()).ssl_opts(sslOpts);
              let pool = Pool::new(builder).unwrap();
              let mut conn = pool.get_conn().unwrap();
              let val: Vec<String> = conn.query("SHOW DATABASES").unwrap();
              println!("{:?}", val)
          }
