mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 06:28:54 +00:00
refactor: minor cleanup and formatting
This commit is contained in:
1 parent
dbe107e669
commit
e685ff5f4c
3 files changed
+48
-56
No files matched your search
+17
-21
@@ -8,28 +8,24 @@ if (connectionString === '') {
|
||||
}
|
||||
|
||||
const dbOptions = (() => {
|
||||
if (connectionString.includes('mysql://')) return { uri: connectionString };
|
||||
const options = connectionString
|
||||
.replace(/(?:host(?:name)|ip|server|data\s?source|addr(?:ess)?)=/gi, 'host=')
|
||||
.replace(/(?:user\s?(?:id|name)?|uid)=/gi, 'user=')
|
||||
.replace(/(?:pwd|pass)=/gi, 'password=')
|
||||
.replace(/(?:db)=/gi, 'database=')
|
||||
.split(';')
|
||||
.reduce((connectionInfo, parameter) => {
|
||||
const [key, value] = parameter.split('=');
|
||||
connectionInfo[key] = value;
|
||||
return connectionInfo;
|
||||
}, {});
|
||||
const options = connectionString.includes('mysql://')
|
||||
? { uri: connectionString }
|
||||
: (options = connectionString
|
||||
.replace(/(?:host(?:name)|ip|server|data\s?source|addr(?:ess)?)=/gi, 'host=')
|
||||
.replace(/(?:user\s?(?:id|name)?|uid)=/gi, 'user=')
|
||||
.replace(/(?:pwd|pass)=/gi, 'password=')
|
||||
.replace(/(?:db)=/gi, 'database=')
|
||||
.split(';')
|
||||
.reduce((connectionInfo, parameter) => {
|
||||
const [key, value] = parameter.split('=');
|
||||
connectionInfo[key] = value;
|
||||
return connectionInfo;
|
||||
}, {}));
|
||||
|
||||
options.namedPlaceholders = true;
|
||||
options.typeCast = parseTypes;
|
||||
|
||||
return options;
|
||||
})();
|
||||
|
||||
const createConnection = () => {
|
||||
return createPool({
|
||||
...dbOptions,
|
||||
namedPlaceholders: true,
|
||||
typeCast: parseTypes,
|
||||
});
|
||||
};
|
||||
|
||||
export const pool = createConnection();
|
||||
export const pool = createPool(dbOptions);
|
||||
Reference in new issue
Block a user