Commit Graph
68 Commits
Author SHA1 Message Date
Linden 17841acc45 refactor(db): loop createConnectionPool until success 2023-11-28 12:01:55 +11:00
Linden 3fef918000 fix(db/connection): don't establish connection from getPoolConnection
Should prevent connection timeouts when queries are
called during server startup.
2023-11-28 12:01:55 +11:00
Linden 0f5f397814 refactor(db/connection): tweak waitForConnection logic 2023-11-28 12:01:55 +11:00
Linden 0398abc501 refactor(database): move pool and connection variables
Mostly reorganising module.
Added getPoolConnection helper.
2023-09-15 14:36:31 +10:00
Linden a065c1c545 fix(db/rawExecute): don't unpack responses for rawExecute
Oversight when implementing the rawExecute export. Technically breaking..
Return ResultSetHeader rather than just a number for affectedRows or insertId.
2023-09-06 13:29:04 +10:00
Linden 86aaf157fa fix: rename printError function
This apparently conflicts with and overrides a global used in cfx's JS runtime.
2023-09-06 12:31:22 +10:00
Linden 958e18d07f fix(database/rawTransaction): don't error on transaction failure
This was a compatibility-breaking change.
2023-08-08 18:14:34 +10:00
Linden 924fd6a3cf refactor: improve error handling 2023-07-28 17:21:13 +10:00
Linden f3e9aa52d9 refactor(database): use setCallback 2023-07-28 06:09:35 +10:00
Linden e07947d3b9 refactor(logger): more consistent error output 2023-07-20 16:10:51 +10:00
Linden 77251b3739 refactor: type improvements 2023-07-20 16:10:08 +10:00
Linden 4870c56045 refactor(database): general code review/cleanup 2023-07-19 23:57:20 +10:00
Linden fbc2542136 fix(utils/parseTransaction): properly handle arrays of queries 2023-07-19 20:16:23 +10:00
Linden 11b7433398 refactor(database): output db version in connection message 2023-07-19 19:52:02 +10:00
Linden 45aadf7442 refactor(logger): only enable profiling with debugging
Breaks slow query warnings, but most people just set the number higher
once they get warnings anyway.
Also fixes some issues:
- profile duration formatting and time (sec to ms).
- incorrect log query/param index.
2023-07-12 15:38:47 +10:00
Linden bdbe86c0f7 fix(database): handle profiles for >100 statements in batch queries
Profiling is limited to the last 100 queries on a connection.
Clearing profiles after every 100th query should work well enough.
2023-07-12 13:18:55 +10:00
Linden a8cdc5d1a1 refactor(logger): add profileBatchStatements 2023-07-12 13:16:08 +10:00
Linden 51c84a30ca refactor(database/rawExecute): split batched query logs 2023-07-12 11:30:49 +10:00
Linden e57a983bc0 refactor(database/rawTransaction): per-query profiling 2023-07-12 11:24:03 +10:00
Linden b2387fc33a refactor: minor tweaks and cleanup
Primarily moving connectionOptions fully to config.
Removed exported resource name.
Include error code and number when database connection fails.
2023-07-12 00:05:29 +10:00
Linden 197b92891a refactor(database): query profiling 2023-07-11 18:40:03 +10:00
Linden ef7f4156df chore: update dependencies
mysql2 patch no longer includes types, profiling, or connection attributes.
2023-07-11 17:23:56 +10:00
Linden fa0068e798 refactor(database): use mysql2/promise
Better code-flow.
Other minor changes to config.
Remove profiling (temp).
2023-07-11 16:33:01 +10:00
Linden 1829ded03c fix: don't throw errors outside of promises 2023-06-18 04:14:33 +10:00
Linden 11b21f8ed2 refactor(db): rename serverReady variable 2023-06-13 02:23:33 +10:00
Linden e8f1abcab7 feat(rawExecute): "prepare" alternative without unpacking
See #179. Always return an array of row results (or null).
Parameters are now optional (though preferred).
2023-06-06 14:37:05 +10:00
Linden 5a949b9546 fix(database): throw Error before creating promise
Promises, even when resolved/rejected immediately after their creation, will
destroy any useful information from a stack trace when used over
events/exports.

Since some people still use the exports rather than MySQL/lib.lua, and for
some reason don't know the correct syntax for Lua exports (i.e. using
exports.oxmysql.query instead of the CORRECT exports.oxmysql:query) it's
comically common for an "untraceable" error to get spit out.

Will this help? No. Will everyone expect me to solve their issues? Yes.

Go update your scripts to use MySQL/lib.lua and we can all get along
stress-free.
2022-11-18 08:58:43 +11:00
Linden bc8a874743 refactor(database): waitForConnection 2022-11-08 17:29:05 +11:00
Linden 2a5e110e29 fix(database/rawExecute): append extra null values 2022-11-08 16:57:51 +11:00
Linden 25f8feb793 fix(execute): handle nil values in nested arrays
Lua tables are msgpacked with the "without_hole" setting.
Nested tables being sent with "prepare" failed to account for
nil values in tables unpacking into objects.
2022-11-08 15:17:01 +11:00
Linden 8fe63bc88a chore: update dependencies and patch 2022-09-21 13:57:55 +10:00
Linden 521aa8f03d refactor: move connectionOptions to config
We'll also ensure namedPlaceholders is boolean and export the object.
2022-08-13 16:22:45 +10:00
Linden d80615bddc fix(db): handle errors during callbacks
Handles errors that would previously disappear into the void or show as 'undefined'.

In Lua this would only occur if yielding during the query callback response.

Cross runtime error handling is suffering.
2022-06-26 04:02:50 +10:00
Niek fd8ab04f1a fix(error-events): Add invokingResource to error data (#129) 2022-06-26 04:01:05 +10:00
Linden 5fc56caddf fix(db/rawQuery): handle uncaught promise
oxmysql is unexpectedly catching errors thrown by the Lua runtime
when an error occurs during a function reference.
This lead to an 'undefined' error being thrown, specifically when
yielding a thread during the function reference.

Not really an oxmysql bug, so this should just be a temporary workaround.
2022-06-24 14:14:37 +10:00
Niek 655ee7309f feature: Add event to error handling (#128) 2022-06-22 02:32:22 +10:00
Linden 15884fbc82 refactor: error handling
Meant to push this before release.
Ensures errors are handled as before, regardless of using exports
or lib/mysql; for compatibility.
2022-06-18 16:32:07 +10:00
Linden a76ce68e9c fix(db): supportBigNumbers
BIGINT columns will lose precision at a certain length.
This connection flag will typecast to a string in those situations.

Resolves #121.
2022-06-18 14:14:03 +10:00
Linden bccd6a1035 fix: error handling when using callbacks
Only allow manual error handling when using the await/sync methods,
or when calling the default exports.

Async/Callback returns need to throw errors for compatibility.
2022-06-17 21:40:27 +10:00
Linden 21e73c17b8 refactor(db/execute): mysql2 callback api
Attempt #2; last attempt had some connection issue.
Minor performance improvement, more noticeable with bulk queries.
2022-06-16 18:09:09 +10:00
Linden 340ca48012 refactor: error handling
Add boolean to disable throwing error for query.
Reject promises when using _async exports.
Return errors as strings instead of Error (fails to serialise).

Fixes #122
2022-06-04 14:50:49 +10:00
Linden 56729ef9c1 fix(db): ignore errors during ref call 2022-05-12 08:49:29 +10:00
Linden 5d69db51da refactor(database): new URI parser 2022-04-30 04:13:31 +10:00
Linden c07fa4a451 refactor(transaction): support new transaction syntax
Adds a third accepted syntax for transactions, distinct from the mysql-async
compatible implementations.
2022-04-21 13:25:40 +10:00
Linden da83eff989 revert(execute): transaction api
Somebody, somewhere, will experience compatibility issues with any
change made to oxmysql.
2022-04-21 12:07:47 +10:00
Linden 050eef58b9 fix(execute): revert to promise api
Several reports of increased chances to hit a deadlock since v2.2.2, and
three reports of a timeout during prepare since v2.2.4.
Simpler to revert to the old prepare function and api (with improvements)
than to work out the solution.

Look into rewriting prepare in the future or including the mariadb connector,
which doesn't suffer from the same perf issues.
2022-04-03 06:10:13 +11:00
Linden fa1cdcc668 fix(execute): incorrect response parsing
Fixes several regressions and issues from ef0dfaa.
Sending a single parameter would set 'single' to true, ignoring multiple
results from the database and returning 'null'.
SELECT should not trigger transactions, not the other way around.
Results should not be parsed when no callback is defined.
2022-04-03 03:52:07 +11:00
Linden c9e402ccdc fix(query): less verbose errors 2022-04-02 01:37:56 +11:00
Linden ef0dfaac84 refactor(execute): remove mysql2 promise api
Changing from promises to callbacks gives ~20% increased performance.
Single prepared statements won't use transactions (no extra overhead).
2022-03-30 05:54:54 +11:00
Linden 7b01898959 refactor(transaction): individual transaction logging
I should bother patching mysql2 types, but idc
2022-03-27 08:55:20 +11:00