require("dotenv").config();
console.log(process.env.USER);

const {awSQL, Structure} = require("../index");
const install = require("./install");

const instance = awSQL.createInstance("schwarze-drya.de", process.env.USER, process.env.PASS, {defaultDatabase: process.env.DATABASE, multipleStatements: true});

async function main(){
    const result = await instance.connect();
    console.log(result);
    await install();

    const databases = await instance.getDatabases();
    console.log(databases);
    const databasesWithoutSchema = await instance.getDatabases(true);
    console.log(databasesWithoutSchema);

    /*const tables = await instance.getTables(process.env.DATABASE);
    console.log(tables);

    //const dropResult = await instance.dropDatabase("awSQL_dev");
    //console.log(dropResult);

    const dropResult = await instance.dropTable("Customers");
    console.log(dropResult);

    //const createResult = await instance.createTable("Test").structure(new Structure().int("id", 255)).execute();
    //console.log(createResult);

    const totalResult = await instance.total("Shippers");
    console.log(totalResult);*/

    const filteredOrders = await instance.select("Orders")  // Select table 'Orders'
    // Filter by orders where CustomerID are our desired ids.
    // Note that the values of ? are pushed in order into the value-array
                                         .where("CustomerID = ? OR CustomerID = ?", [90, 34])
                                         .execute();
    console.log(filteredOrders);

    const orderedShipperNames = await instance.select("Shippers")
                                              .order("ShipperName")
                                              .execute();
    console.log(orderedShipperNames);
}

main();