function dbSetup() {
    return openDatabase("bids", '0.1', "", 200000);
}

function dbRegisterBid(db, data) {
    db.transaction(function(tx) {
        tx.executeSql(`
      CREATE TABLE IF NOT EXISTS bids 
      (id unique, brand, number, year, service_type, first_name, second_name, patronym, telephone, email, comment, date)
      ;
    `)

        tx.executeSql(`
      INSERT INTO bids 
        (id unique, brand, number, year, service_type, first_name, second_name, patronym, telephone, email, comment, date) 
      VALUES 
        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
        ;
    `, formatData(data));

    });
}

function bidsList(db) {
    var list = []
    db.transaction(function(tx) {
        tx.executeSql('SELECT * FROM bids', [], function(tx, results) {
            list = results
                // for (i = 0; i < len; i++) {
                //     msg = "<p><b>" + results.rows.item(i).log + "</b></p>";
                //     document.querySelector('#status').innerHTML += msg;
                // }
        }, null);
    });
    return list
}

// TODO: сделать как-нибудь по-другому
function formatData(data) {
    [
        genSortaUuid(),
        data["brand"],
        data["number"],
        data["year"],
        data["service_type"],
        data["first_name"],
        data["second_name"],
        data["patronym"],
        data["email"],
        data["comment"],
        new Date().toLocaleString()
    ]
}

function genSortaUuid() {
    return ((+new Date) + Math.random() * 10).toString(16)
}

Изменить пасту