1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

feat: tables options edit

This commit is contained in:
2020-11-16 17:16:39 +01:00
parent e49823f5c4
commit 0805b96a75
8 changed files with 221 additions and 13 deletions

View File

@ -267,6 +267,28 @@ export class MySQLClient extends AntaresCore {
});
}
/**
* SHOW ENGINES
*
* @returns {Array.<Object>} engines list
* @memberof MySQLClient
*/
async getEngines () {
const sql = 'SHOW ENGINES';
const results = await this.raw(sql);
return results.rows.map(row => {
return {
name: row.Engine,
support: row.Support,
comment: row.Comment,
transactions: row.Trasactions,
xa: row.XA,
savepoints: row.Savepoints
};
});
}
/**
* ALTER TABLE
*
@ -278,12 +300,19 @@ export class MySQLClient extends AntaresCore {
table,
additions,
deletions,
changes
changes,
options
} = params;
let sql = `ALTER TABLE \`${table}\` `;
const alterColumns = [];
// OPTIONS
if ('comment' in options) alterColumns.push(`COMMENT='${options.comment}'`);
if ('engine' in options) alterColumns.push(`ENGINE=${options.engine}`);
if ('autoIncrement' in options) alterColumns.push(`AUTO_INCREMENT=${+options.autoIncrement}`);
if ('collation' in options) alterColumns.push(`COLLATE='${options.collation}'`);
// ADD
additions.forEach(addition => {
const length = addition.numLength || addition.charLength || addition.datePrecision;
@ -325,6 +354,9 @@ export class MySQLClient extends AntaresCore {
sql += alterColumns.join(', ');
// RENAME
if (options.name) sql += `; RENAME TABLE \`${table}\` TO \`${options.name}\``;
return await this.raw(sql);
}