MySQL Async Library
You can find it here with all the instructions : https://github.com/brouznouf/fivem-mysql-async
This lib does not replace EssentialMode, it offers however async methods and compatible API for people only needing Essential Mode for MySQL
The current API should be stable, but it may change before a first stable release.
Feel free to raise Issues/Pull request on Github
Current features
- Async method for mysql by using a callback
- Sync method also available but not recommended
Download
https://github.com/brouznouf/fivem-mysql-async/archive/3.3.1.zip
If for some reason you still want the C# Version it can be downloaded from https://github.com/brouznouf/fivem-mysql-async/tree/2.0
Changelog
3.3.2
- Removes whitespaces from a legacy connection string.
- Migrated client-side from JS -> LUA for reduced overhead.
- Added a new Server Status display in the UI that gives you hints on optimizing your mysql server (issues should be detected properly, advice might not to be reworked in wording and expanded upon in scope).
3.3.1
- Added
mysql_log_level
that lets you control on what is output in console. - Added
mysql_log_file_format
to specify the output log file. - Reworked the UI. UI Bundle-size lost ~550kB in size.
3.3.0
- Uses ghmattimysql now completely, shares almost the complete list of features.
- Enabled js-syntax, which allows nifty shortcuts:
MySQL.Async.fetchAll('SELECT * FROM ?? WHERE ?', {'users', {['id'] = id}})
-- Renders as: SELECT * FROM `users` WHERE `id` = @id; with parameter id being id
- The js-syntax also allows for bulk inserts.
- Switched to typescript.
- Blob field issue has been fixed and now returns arrays.
- Store feature has been added, it is useful for replacing reptitive queries, as the entire query string does not need to be resend to mysql-async
local queryId = MySQL.Sync.store('SELECT * FROM ?? WHERE ?')
--...
MySQL.Async.fetchAll(queryId, {'users', {['id'] = id}}, function(result)
print(json.encode(result))
end)
3.2.3
Changes
- Fix #129
- Fix transactions responding with
true
despite failing. - Implemented the command
mysql:debug
to toggle the debug printing #117. If it only redirects to file, it will only print to file.
3.2.2
- Fixed a possible timeout when resources were loading too slow.
- Added a warning against using MySQL 8, since the performance can be abysmal.
3.2.1
- Switch to mysql 2.18.1
- Fixed slow query warnings showing up properly, thanks to @Frosty-Ice
- Added Date + Time for File Logging, from @Neddings
- Updated all packages, frontend switched to Vuetify v2 (what a huge overhead).
- Moved to fxmanifest from __resource.lua, should work with redm.
- Fixed Sync transactions not working properly, thanks to @niekschoemaker
3.2.0
- Go back to mysql.js 2.15
- Add transactions
- Errors are now always red, unless the debug output is only written to files.
- Use stylus for styling
3.1.1
- Removed excessive error reporting.
- Removed
MySQL.Ready
's reliance on events
3.1.0
- Breaking: keepAlive queries are now triggered via the connection string.
- Added a GUI available for admins with the
mysql
command. - Added rerouting debug output to a log file.
3.0.12
- Added keepAlive queries
3.0.11
- Fixed some scope errors.
- Fixed the debug print.
3.0.10
- I fucked up.
3.0.9
- Fixed an empty object returned by fetchScalar, thanks to @PichotM and mikroware.
- Updated the dependencies to the latest versions, thanks to mikroware.
3.0.8
- Fixes mysql-async not parsing the BIT column, which would return a buffer otherwise.
3.0.7
- Added a version to the resource.lua so scripts can ask for the version by querying the metadata.
- Refactor to use Promises in preparation for adding transactions.
- Make the error on the missing connection string clearer.
- Added a warning on queries that take more than 500ms. Time can be controlled by setting
set mysql_slow_query_warning <time-in-ms>
e.g.
set mysql_slow_query_warning 50
to print all queries that take more than one server-tick to complete. Setting it to 0 should disable the slow query warnings.
3.0.6
- Fixes multiple statements partially. See FrBillyD’s , (french) example on how to fix it. e.g.
local result = MySQL.Sync.fetchAll(Query .. Query2, Parameters)
return result[2][1]
when the second query is the select (hence the 2 in the result).
- Debug print shows now the resource requesting the mysql-query.
3.0.5
- DateTime, DateTime2, Timestamp, Timestamp2, Date, Year should now behave properly. Is cast to ms, not to seconds.
- Time, Time2 are currently not parsed.
- It should be STABLE now on Linux without any leakage. Many thanks to @Doacola for running tests showing stable ram.
3.0.4
- Fixes the issue above (datetime, datetime2, timestamp2 is now cast to seconds)
3.0.3
- Fixed that dates were not returned as in 2.x. Timestamps are now returned in seconds. DateTime is tableified.
- For this fix to work you must not have dateStrings=true on your connection string.
- I probably introduced some bugs with this.
- Some rough progress was made with getting 3.x to run stable on linux.
3.0.2
- Allow multiple statements per query string on the legacy connection string
- Support bignumbers by default on the legacy connection string
3.0.1
- Parse both types of connection strings into options. No need to change it anymore.
- Fixed an issue that
MySQL.ready
might not trigger on resource restart.onMySQLReady
will still trigger only once, but MySQL.ready should work now properly.
3.0.0
- Release
3.0.0-rc.0
- Migrated entire library to node.js
Breaking : The console variablemysql_connection_string
needs to be formated now likemysql://username:password@host/database?dateStrings=true
additional options can be chained like in urls, first with ? then with &. The options can be gotten from https://github.com/mysqljs/mysql#connection-options- Breaking : Transactions are not included in this release candidate.
- Threaded options are no longer needed and will be removed as of 3.1.0
Previous Versions
Change Log Version 2.X
2.1.2
- Added default options for connection strings and mysql_debug, so it should not error anymore, hopefully.
- SslMode is set to none by default contributed by @Syntasu
2.1.1
- Updated MySqlConnector to a Custom 0.38.0 Release; This fixes the sessions leaking on heavy contention.
2.1.0
- Updated MySqlConnector to a Custom 0.37.1 Release. I am not sure if I lost performance on Async queries somewhere along the way from 0.26/2.0.2; can someone compare?
- Added Threaded operations. They work the same way as sync calls, but are slower as they are not executed on the server thread. You call them by using
MySQL.Threaded.execute/insert/fetchAll/fetchScalar
. If you are experiencing timeouts (replace some async queries with them). If you are experiencing hitches, replace some sync queries with them. - Added Transactions; they do not have a Threaded option yet.
2.0.4
- Updated MySqlConnector to a Custom 0.36.1 Release (Differences will be on my MySqlConnector branch once I reach the up to date version 0.37.0). This should improve performance, reduce CPU load, and contains tons of bugfixes.
2.0.3
- Updated MySqlConnector to 0.28.2 (the last version to actually work with mysql-async) Thanks to @IceHax testing it once.
2.0.2
- Fix receiveing null result on fetch scalar
2.0.1
- Remove native call on exception to avoid fatal error
2.0.0
- Better logging, split time between connection / query / reading
- Add mysql_debug config for activation / deactiving log of queries
- Fix bug when returning null on fetchScalar
- Add “MySQL.ready” function, use this function insted of the onMySQLReady event
- Update underlying lib
2.0.0-beta6
- Fix file name for linux
2.0.0-beta5
- Readd pooling
2.0.0-beta4
- Fix hard bug with fields and value being null cause of using IsDbNullAsync
- Better exception message
- Better error detection
- Now show parameters in the log
Previous not for Beta 3:
It is now FULLY Async, before only the query execution was async, now it’s everything when using Async functions (Opening connecting, Query Execution and Result reading are async)
2.0.0-beta3 - Don’t use it it’s broken !
- Complete rewrite, should be more stable and faster for async version
- Add mysql_debug convar (default to false) true = print query statements
- Add insert methods which allow to execute a query and return the last insert id from the database
- Add a vstudio project, to give more trust about what is done and allow better contribution
- Update to last version of the underlying lib
2.0.0-beta2
- Fix a memory leak
- Upgrade underlying mysql lib to fix some bugs (0.19.5 to 0.23.0)
2.0.0-beta1
- Small but existing BC Break on the new API (read the upgrade guide)
- FXServer Only
- No more support for essential mode API (you should update to the new API before upgrading to 2.0)
Change Log Version 1.X
1.0.0
- No changes since 0.2.2, it just stable enough to release it under a stable version
0.2.2
- Close connection before calling user callback, so in case of error connection is still properly closed
- Fix bad transformations of fields, .NET object were present in result which used in TriggerEvent would faild as MessagePack don’t know how to transform it
- Add a optional script to clear connections every 10sec
0.2.1
- Fix bug of not closing connections, due to this pooling has been desactivated, will reactivate once i have proper time to debug this.
0.2.0
- Remove coroutine support as it was leaking thread due to the way of using it
- Stabilize connections on mysql (correctly open / close)
- Fix many bugs about specific parameters and null value on a Select queries
- Add query log (with execution time of the query)
0.1.0
- Release