Giter VIP home page Giter VIP logo

oxmysql's Introduction

Introduction

Oxmysql is an alternative to the unmaintained mysql-async/ghmattimysql resources, utilising node-mysql2 rather than mysqljs.

As of v1.9.0 the preferred method of utilising oxmysql is via lib/MySQL, which can be loaded by adding @oxmysql/lib/MySQL.lua to your resource manifests. This resource should be 100% backwards compatible with mysql-async functionality on top of providing newer export wrappers and functionality.

Refer to issue #77 for information on replacing your queries from older versions of oxmysql or ghmattimysql.

Features

  • Support for URI connection strings and semicolon separated values
  • Asynchronous queries utilising mysql2/promises connection pool
  • Javascript async_retval exports supports promises across resources and runtimes
  • Support for placeholder values (named and unnamed) to improve query speed and increase security against SQL injection
  • Improved error checking when placeholders and parameters do not match
  • Lua promises in lib/MySQL.lua files for improved performance when awaiting a response
  • Support mysql-async syntax while providing newer (more accurate) names

Usage

-- Lua
MySQL.query('SELECT * from users WHERE identifier = ?', {identifier}), function(result)
    -- callback response
    -- same as MySQL.Async.fetchAll
end)
CreateThread(function()
    local result = MySQL.query.await('SELECT * from users WHERE identifier = ?', {identifier})
    -- await a promise to resolve
    -- same as MySQL.Sync.fetchAll
end)
// JS
exports.oxmysql.query('SELECT * from users WHERE identifier = ?', [identifier], (result) => {
    // callback response
})
(async() => {
    const result = await exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier])
    // await a promise to resolve
})()
exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier]).then((result) => {
    // utilise .then to resolve a promise like a callback
})

For more information regarding the use of queries, refer to the documentation linked above.

Placeholders

This allows queries to be properly prepared and escaped; the following lines are equivalent.

"SELECT group FROM users WHERE identifier = ?", {identifier}  
"SELECT group FROM users WHERE identifier = :identifier", {identifier = identifier}  
"SELECT group FROM users WHERE identifier = @identifier", {['@identifier'] = identifier}

You can also use the following syntax when you are uncertain about the column to select.

"SELECT ?? FROM users WHERE identifier = ?", {column, identifier}  
instead of using  
"SELECT "..column.." FROM users WHERE identifier = ?", {identifier}







Discord


oxmysql's People

Contributors

1a3dev avatar berkiebb avatar chaixshot avatar darksaid98 avatar dunak-debug avatar thelindat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.