[Standalone] OxMySQL - Lightweight MySQL wrapper

IBb97ru

About

Lightweight database middleware for FXServer which utilises node-mysql2 to communicate with a database and respond with the query results.


Features

  • Improved performance and compatibility with Lua wrapper
  • Resolves issues when using MySQL 8.0
  • Returns callbacks immediately, removing up to 50ms overhead
  • UI utility for easy query statistics

Note that UI is useful for quickly checking stuff while in game and developing but do not use it in production!

Installation & Usage

Common issues

Unable to establish a connection

This is usually the result of incorrect database settings or your password containing reserved characters (typically ; , / ? : @ & = + $ # ).

Ensure you have entered the correct database settings in the mysql_connection_string convar. You can try using the semicolon-separated format if your password contains reserved characters.

No such export … in resource oxmysql

Typically the result of failing to follow instructions.

Download the latest release build (not source) of oxmysql, and ensure it is starting before any resources that require it.

Before reporting any issue, please go trough documentation first!

66 Likes

:ox: It’s here :ox:

3 Likes

This looks good. Good release!

3 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

3 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:[email protected]/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 [email protected] 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