I'm not sure how to iterate over an array and send each item a promise that is chained. I'm trying to define DBSchema.executeMigrations
down below (details in comments there).
Assume that migrations
will grow over time. So, it's just 3 args now, but could be 100 next year. I need this to iterate.
export class DBConnection {
exec(query): Promise<any> {
let _this = this;
return new Promise((resolve) => {
_this.get().then((db) => {
db.executeSql(query, {}).then(
(result) => {
resolve(result);
},
(err) => {
console.log('Unable to execute query: ' + err.message);
}
);
});
});
}
}
export class DBSchema {
constructor(public db_connection: DBConnection){};
static migrations = [
"CREATE TABLE IF NOT EXISTS events(id INTEGER PRIMARY KEY NOT NULL, title STRING)",
"CREATE TABLE IF NOT EXISTS news(id INTEGER PRIMARY KEY NOT NULL, title STRING)",
"CREATE TABLE IF NOT EXISTS whatever(id INTEGER PRIMARY KEY NOT NULL, title STRING)"
];
executeMigrations(): any {
// send each migration to db_connection.exec
// do it in order
// return a promise that resolves when all of them are done
}
}