mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 22:22:50 +00:00
refactor(database): add new connection class and misc tweaks
Use disposable symbol to ensure connection cleanup. Improvements to internal types. Code splitting and removal of redundant variables.
This commit is contained in:
1 parent
19d55a21ed
commit
c38f646bb9
14 files changed
+162
-125
No files matched your search
+5
-4
@@ -1,3 +1,4 @@
|
||||
import type { ConnectionOptions } from 'mysql2';
|
||||
import { typeCast } from './utils/typeCast';
|
||||
|
||||
export const mysql_connection_string = GetConvar('mysql_connection_string', '');
|
||||
@@ -39,7 +40,7 @@ export const mysql_transaction_isolation_level = (() => {
|
||||
}
|
||||
})();
|
||||
|
||||
const parseUri = (connectionString: string) => {
|
||||
function parseUri(connectionString: string) {
|
||||
const splitMatchGroups = connectionString.match(
|
||||
new RegExp(
|
||||
'^(?:([^:/?#.]+):)?(?://(?:([^/?#]*)@)?([\\w\\d\\-\\u0100-\\uffff.%]*)(?::([0-9]+))?)?([^?#]+)?(?:\\?([^#]*))?$'
|
||||
@@ -65,11 +66,11 @@ const parseUri = (connectionString: string) => {
|
||||
};
|
||||
|
||||
return options;
|
||||
};
|
||||
}
|
||||
|
||||
export let convertNamedPlaceholders: null | ((query: string, parameters: Record<string, any>) => [string, any[]]);
|
||||
|
||||
export const connectionOptions = (() => {
|
||||
export function getConnectionOptions(): ConnectionOptions {
|
||||
const options: Record<string, any> = mysql_connection_string.includes('mysql://')
|
||||
? parseUri(mysql_connection_string)
|
||||
: mysql_connection_string
|
||||
@@ -110,7 +111,7 @@ export const connectionOptions = (() => {
|
||||
namedPlaceholders: false, // we use our own named-placeholders patch, disable mysql2s
|
||||
flags: flags,
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
RegisterCommand(
|
||||
'oxmysql_debug',
|
||||
|
||||
Reference in new issue
Block a user