mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Updated call signature of database-info lib
refs https://github.com/TryGhost/Toolbox/issues/174 - ok, iteration 3 on how this library should work - 95% of my use cases just need to pass an knex instance and return if it's mysql/sqlite - i don't want to have to initialize the class in this library to get that - this commit reworks the public interface to return a function with some simple `is*` functions for those uses cases, or to return the class otherwise
This commit is contained in:
parent
3e9c584589
commit
032e9db2f1
@ -1,4 +1,27 @@
|
|||||||
module.exports = class DatabaseInfo {
|
/**
|
||||||
|
* @param {import('knex')} knex
|
||||||
|
*/
|
||||||
|
module.exports = (knex) => {
|
||||||
|
const driver = knex.client.config.client;
|
||||||
|
|
||||||
|
return {
|
||||||
|
/**
|
||||||
|
* Returns if the driver used is for SQLite
|
||||||
|
*/
|
||||||
|
isSQLite: () => {
|
||||||
|
return ['sqlite3'].includes(driver);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the driver used is for MySQL
|
||||||
|
*/
|
||||||
|
isMySQL: () => {
|
||||||
|
return ['mysql', 'mysql2'].includes(driver);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.DatabaseInfo = class DatabaseInfo {
|
||||||
/**
|
/**
|
||||||
* @param {import('knex')} knex
|
* @param {import('knex')} knex
|
||||||
*/
|
*/
|
||||||
@ -81,29 +104,4 @@ module.exports = class DatabaseInfo {
|
|||||||
getVersion() {
|
getVersion() {
|
||||||
return this._databaseDetails.version;
|
return this._databaseDetails.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the driver used is for SQLite
|
|
||||||
*/
|
|
||||||
isSQLite() {
|
|
||||||
return ['sqlite3'].includes(this._driver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the driver used is for MySQL
|
|
||||||
*/
|
|
||||||
isMySQL() {
|
|
||||||
return ['mysql', 'mysql2'].includes(this._driver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This allows you to use a different DB connection than the one we initialized the lib with
|
|
||||||
*
|
|
||||||
* @param {import('knex')} knex
|
|
||||||
*
|
|
||||||
* @returns DatabaseInfo
|
|
||||||
*/
|
|
||||||
connection(knex) {
|
|
||||||
return new DatabaseInfo(knex);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user