@megaorm/utils v1.0.0
MegaORM Utils
This package provides utility functions to validate whether a value is a MegaORM driver or a connection.
Installation
To install this package, run the following command:
npm install @megaorm/utilsFunctions
isDriver(driver): Ensures that the given value is one of MegaORM's supported drivers: @megaorm/mysql, @megaorm/sqlite, or @megaorm/pg.
const { isDriver } = require('@megaorm/utils');
console.log(isDriver({})); // falseReturns
trueif the value is a valid MegaORM driver,falseotherwise.
isMySQL(driver): Ensures that the given value is a @megaorm/mysql driver.
const { isMySQL } = require('@megaorm/utils');
console.log(isMySQL({})); // falseReturns
trueif the value is the MySQL driver,falseotherwise.
isPostgreSQL(driver): Ensures that the given value is a @megaorm/pg driver.
const { isPostgreSQL } = require('@megaorm/utils');
console.log(isPostgreSQL({})); // falseReturns
trueif the value is the PostgreSQL driver,falseotherwise.
isSQLite(driver): Ensures that the given value is a @megaorm/sqlite driver.
const { isSQLite } = require('@megaorm/utils');
console.log(isSQLite({})); // falseReturns
trueif the value is the SQLite driver,falseotherwise.
isCon(connection): Ensures that the given value is a MegaConnection — a connection created by any MegaORM driver.
const { isCon } = require('@megaorm/utils');
console.log(isCon({})); // falseReturns
trueif the value is aMegaConnection,falseotherwise.
isPendingCon(connection): Ensures that the given value is a MegaPendingConnection — a connection that could not be closed by MegaPool.
const { isPendingCon } = require('@megaorm/utils');
console.log(isPendingCon({})); // falseReturns
trueif the value is aMegaPendingConnection,falseotherwise.
isPoolCon(connection): Ensures that the given value is a MegaPoolConnection — a connection created by MegaPool.
const { isPoolCon } = require('@megaorm/utils');
console.log(isPoolCon({})); // falseReturns
trueif the value is aMegaPoolConnection,falseotherwise.
Usage Examples
const { isDriver, isSQLite, isCon } = require('@megaorm/utils');
const { SQLite } = require('@megaorm/sqlite');
// Create a driver instance
const driver = new SQLite(':memory:');
// Ensure it's an SQLite driver instance
if (isSQLite(driver)) {
console.log('This is an SQLite driver!');
}
// Ensure it's a MegaORM driver instance (SQLite, PostgreSQL, MySQL)
if (isDriver(driver)) {
console.log('This is a MegaORM driver!');
}
// Create a connection
driver.create().then((connection) => {
// Ensure it's a MegaConnection
if (isCon(connection)) {
console.log('This is a MegaConnection!');
}
});11 months ago