[Standalone] OxMySQL - Lightweight MySQL wrapper

A wrapper for node-mysql2 to allow communication between FXServer and a MySQL database.

Features

  • Support for mysql-async and ghmattimysql syntax.
  • Promises / async query handling allowing for non-blocking and awaitable responses.
  • Improved performance and stability compared to other options.
  • Support for named and unnamed placeholders, improving performance and security.
  • Support for URI connection strings and semicolon separated values.
  • Improved parameter checking and error handling.
74 Likes

:ox: It’s here :ox:

3 Likes

This looks good. Good release!

4 Likes

Nice, im interested on the Performance,i will have to run a benchmark.

Overall awsome!

3 Likes

As we ran some benchmark tests, huge performance improvement was due to ScheduleResourceTick() that removes up to ~50ms overhead.

And of course node-mysql2 has some improvements also with integrated support for prepared statements.

Good issue to be mentioned is Feature request: Move to `mysql2` module which does at least seem maintained · Issue #38 · GHMatti/ghmattimysql · GitHub

4 Likes

Good job, I have a question that does not appear in the documentation, if I want to do a MySQL.ready with oxmysql how should it be done?

1 Like

@Dunak are you planning on adding transactions to the wrapper? Nice release btw!

2 Likes

There is no need to wait for ready event on mysql2.

Just execute the query and mysql2 pool will immediately initialise connection.

2 Likes

Of course, may be implemented in next release. Thank you!

3 Likes

Hey, So I only started playing around with dev-ing with the SDK yesterday, and used this module, with ox-inventory. I quickly found it was using the same mysql_connection_string as mysql-async/node-mysql, which meant I can’t mix and match modules, as obviously, this is so new that other modules haven’t switched to it yet.

Any ideas on how I could work around this? At this point I’m just playing with modules and seeing what works nicely with each other.

Thanks for the release Dunak. Thought you’d already put this up though. :stuck_out_tongue:

Glws, oh wait…

200

2 Likes

mysql-async is just ghmattimysql behind the scenes and both support the URI style string.

set mysql_connection_string "user=root;database=es_extended;password=password"
is instead formatted as
set mysql_connection_string "mysql://root:password@localhost/es_extended?"

Ahh, thank you! Most tutorials I saw had the 1st version!

3 Likes

For a noob who is interested in increasing performance, can you explain what I would need to change if I’m currently using MySQL-async? Would this just run alongside it or replace it? Would I need to change any scripts to work with it?

2 Likes

Of course you have to change your script to work with this

But to what extent I guess is my question. Just in the fxmanifest or in each server file and etc?

I have been following the project and it looks awesome, using the wrapper right now in my personal projects :slight_smile:

1 Like

This resource provides exports instead of importing script into every resource fxmanifest.

If you want to use this instead of mysql-async you will have to change every line of mysql-async query code to oxmysql export and remove mysql-async from fxmanifest.

To be honest I would first try this resource on development server to see if all queries are compatible.

This looks amazing, I’ve been waiting for something like this for a while.

Would it be possible to match the way MySQL.Async and Ghmatti uses the @'s in the {} parameters, like:

exports.oxmysql:fetch('SELECT * FROM `jobgrades` WHERE job=@job LIMIT 1', { ['job'] = k }, function(result)

From my understanding, it’s currently set to work like:

exports.oxmysql:fetch('SELECT * FROM `jobgrades` WHERE job=? LIMIT 1', { k }, function(result)

Much appreciated :slight_smile:

2 Likes