// Path: sane-dbc-core/src/main/java/com/novarto/sanedbc/core/interpreter/SyncDbInterpreter.java
// public class SyncDbInterpreter
// {
//     private final Try0<Connection, SQLException> ds;
// 
//     /**
//      * Construct an interpreter, given a piece of code which knows how to spawn connections, e.g. a Data Source, Connection Pool,
//      * Driver Manager, etc.
//      * @param ds - the data source, which can spawn connections
//      */
//     public SyncDbInterpreter(Try0<Connection, SQLException> ds)
//     {
//         this.ds = ds;
//     }
// 
//     /**
//      * Attempt to run this operation and return its result
//      * @param doOp the operation to run
//      * @param <A> the result type of the operation
//      * @return the successful result
//      * @throws RuntimeException if an {@link SQLException} is encountered
//      */
//     public <A> A submit(DB<A> doOp)
//     {
//         try (Connection c = ds.f())
//         {
//             return doOp.run(c);
//         }
//         catch (SQLException e)
//         {
//             throw new RuntimeException(e);
//         }
// 
//     }
// 
//     /**
//      * Attempt to run this operation and return its result. The operation is run transactionally - i.e. if any error is
//      * encountered, the operation is rolled back.
//      * @param doOp the operation to run
//      * @param <A> the result type of the operation
//      * @return the successful result
//      * @throws RuntimeException if an {@link SQLException} is encountered
//      */
//     public <A> A transact(DB<A> doOp)
//     {
// 
//         return submit(transactional(doOp));
// 
//     }
// }
// 
// Path: sane-dbc-core/src/main/java/com/novarto/sanedbc/core/ops/AggregateOp.java
// public class AggregateOp extends DB<Long>
// {
// 
//     private final SelectOp.List<Long> selectOp;
// 
//     public AggregateOp(String sql, TryEffect1<PreparedStatement, SQLException> binder)
//     {
//         this.selectOp = new SelectOp.List<>(sql, binder, x -> x.getLong(1));
//     }
// 
//     public AggregateOp(String sql)
//     {
//         this(sql, NO_BINDER);
//     }
// 
//     @Override public Long run(Connection c) throws SQLException
//     {
//         return selectOp.map(xs ->
//         {
// 
//             Iterator<Long> resultIterator = xs.iterator();
//             if (!resultIterator.hasNext())
//             {
//                 throw new IllegalStateException("result is empty");
// 
//             }
//             Long result = resultIterator.next();
// 
//             if (resultIterator.hasNext())
//             {
//                 throw new IllegalStateException("result has more than one row");
//             }
//             return result;
//         }).run(c);
//     }
// 
// }


import com.novarto.sanedbc.core.interpreter.SyncDbInterpreter;
import com.novarto.sanedbc.core.ops.AggregateOp;
import org.flywaydb.core.Flyway;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
package com.novarto.sanedbc.examples;




/**
 * Database migrations are a great way to control the state of an application in the database. This is an example of usage of
 * {@link Flyway} along with sane-dbc.
 * <p>
 * This example uses two migrations:
 * <ul>
 *     <li>Static sql file V1_1_DBInit.sql which is placed in resources dir
 *     <li>JDBC Java Migration {@link com.novarto.sanedbc.examples.flyway.V1_2__AlterFoo}
 * </ul>
 *
 * @see <a href="https://flywaydb.org/">https://flywaydb.org/</a>
 */
public class FlywayMigrationExample
{

    private static final Flyway FLYWAY = new Flyway();
    private static final String FLYWAY_JDBC_URL = "jdbc:hsqldb:mem:flyway";

    @BeforeClass
    public static void setup()
    {
        // set schema name
        FLYWAY.setSchemas("FLYWAY");

        // set datasource
        FLYWAY.setDataSource(FLYWAY_JDBC_URL, "sa", "");


        // set location folders which contain migrations that needs to be applied by flyway
        final String packageName = FlywayMigrationExample.class.getPackage().getName();
        final String packageFolder = packageName.replace(".", "/");
        final String migrationFolder = packageFolder + "/flyway";
        final List<String> migrationFolders = new ArrayList<>();
        migrationFolders.add(migrationFolder);
        migrationFolders.add("flyway");
        FLYWAY.setLocations(migrationFolders.toArray(new String[migrationFolders.size()]));

        // run migrations
        FLYWAY.migrate();
    }

    @Test
    public void checkMigrationsAreApplied()
    {
// Path: sane-dbc-core/src/main/java/com/novarto/sanedbc/core/interpreter/SyncDbInterpreter.java
// public class SyncDbInterpreter
// {
//     private final Try0<Connection, SQLException> ds;
// 
//     /**
//      * Construct an interpreter, given a piece of code which knows how to spawn connections, e.g. a Data Source, Connection Pool,
//      * Driver Manager, etc.
//      * @param ds - the data source, which can spawn connections
//      */
//     public SyncDbInterpreter(Try0<Connection, SQLException> ds)
//     {
//         this.ds = ds;
//     }
// 
//     /**
//      * Attempt to run this operation and return its result
//      * @param doOp the operation to run
//      * @param <A> the result type of the operation
//      * @return the successful result
//      * @throws RuntimeException if an {@link SQLException} is encountered
//      */
//     public <A> A submit(DB<A> doOp)
//     {
//         try (Connection c = ds.f())
//         {
//             return doOp.run(c);
//         }
//         catch (SQLException e)
//         {
//             throw new RuntimeException(e);
//         }
// 
//     }
// 
//     /**
//      * Attempt to run this operation and return its result. The operation is run transactionally - i.e. if any error is
//      * encountered, the operation is rolled back.
//      * @param doOp the operation to run
//      * @param <A> the result type of the operation
//      * @return the successful result
//      * @throws RuntimeException if an {@link SQLException} is encountered
//      */
//     public <A> A transact(DB<A> doOp)
//     {
// 
//         return submit(transactional(doOp));
// 
//     }
// }
// 
// Path: sane-dbc-core/src/main/java/com/novarto/sanedbc/core/ops/AggregateOp.java
// public class AggregateOp extends DB<Long>
// {
// 
//     private final SelectOp.List<Long> selectOp;
// 
//     public AggregateOp(String sql, TryEffect1<PreparedStatement, SQLException> binder)
//     {
//         this.selectOp = new SelectOp.List<>(sql, binder, x -> x.getLong(1));
//     }
// 
//     public AggregateOp(String sql)
//     {
//         this(sql, NO_BINDER);
//     }
// 
//     @Override public Long run(Connection c) throws SQLException
//     {
//         return selectOp.map(xs ->
//         {
// 
//             Iterator<Long> resultIterator = xs.iterator();
//             if (!resultIterator.hasNext())
//             {
//                 throw new IllegalStateException("result is empty");
// 
//             }
//             Long result = resultIterator.next();
// 
//             if (resultIterator.hasNext())
//             {
//                 throw new IllegalStateException("result has more than one row");
//             }
//             return result;
//         }).run(c);
//     }
// 
// }


// Path: sane-dbc-examples/src/test/java/com/novarto/sanedbc/examples/FlywayMigrationExample.java
import com.novarto.sanedbc.core.interpreter.SyncDbInterpreter;
import com.novarto.sanedbc.core.ops.AggregateOp;
import org.flywaydb.core.Flyway;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

package com.novarto.sanedbc.examples;




/**
 * Database migrations are a great way to control the state of an application in the database. This is an example of usage of
 * {@link Flyway} along with sane-dbc.
 * <p>
 * This example uses two migrations:
 * <ul>
 *     <li>Static sql file V1_1_DBInit.sql which is placed in resources dir
 *     <li>JDBC Java Migration {@link com.novarto.sanedbc.examples.flyway.V1_2__AlterFoo}
 * </ul>
 *
 * @see <a href="https://flywaydb.org/">https://flywaydb.org/</a>
 */
public class FlywayMigrationExample
{

    private static final Flyway FLYWAY = new Flyway();
    private static final String FLYWAY_JDBC_URL = "jdbc:hsqldb:mem:flyway";

    @BeforeClass
    public static void setup()
    {
        // set schema name
        FLYWAY.setSchemas("FLYWAY");

        // set datasource
        FLYWAY.setDataSource(FLYWAY_JDBC_URL, "sa", "");


        // set location folders which contain migrations that needs to be applied by flyway
        final String packageName = FlywayMigrationExample.class.getPackage().getName();
        final String packageFolder = packageName.replace(".", "/");
        final String migrationFolder = packageFolder + "/flyway";
        final List<String> migrationFolders = new ArrayList<>();
        migrationFolders.add(migrationFolder);
        migrationFolders.add("flyway");
        FLYWAY.setLocations(migrationFolders.toArray(new String[migrationFolders.size()]));

        // run migrations
        FLYWAY.migrate();
    }

    @Test
    public void checkMigrationsAreApplied()
    {
        SyncDbInterpreter dbi = new SyncDbInterpreter(