├── LICENSE ├── README.adoc ├── vrp_ghmattimysql-js ├── __resource.lua ├── fxmanifest.lua ├── init.lua └── init_vrp.lua ├── vrp_ghmattimysql ├── __resource.lua ├── fxmanifest.lua ├── init.lua └── init_vrp.lua ├── vrp_icmysql ├── fxmanifest.lua ├── init.lua └── init_vrp.lua └── vrp_oxmysql ├── __resource.lua ├── fxmanifest.lua ├── init.lua └── init_vrp.lua /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 ImagicTheCat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | ifdef::env-github[] 2 | :tip-caption: :bulb: 3 | :note-caption: :information_source: 4 | :important-caption: :heavy_exclamation_mark: 5 | :caution-caption: :fire: 6 | :warning-caption: :warning: 7 | endif::[] 8 | 9 | = Driver list 10 | 11 | == icmysql 12 | 13 | [horizontal] 14 | name:: `icmysql` 15 | resource:: `vrp_icmysql` 16 | project:: https://github.com/IceClusters/icmysql/ 17 | 18 | [WARNING] 19 | The vRP database configuration is not supported; icmysql configuration must be used instead. + 20 | Connection string: `set mysqlCredentials_1 "host=127.0.0.1;user=root; password=; database=vrp; port=3306"` 21 | 22 | == oxmysql 23 | 24 | [horizontal] 25 | name:: `oxmysql` 26 | resource:: `vrp_oxmysql` 27 | project:: https://github.com/overextended/oxmysql/ 28 | 29 | NOTE: Legacy vRP users - Use the `vrp_oxmysql` resource found here (https://github.com/KokeroO/oxmysql-vrp-legacy) along with `oxmysql`. 30 | 31 | NOTE: oxmysql latest release is recommended. Lowest version usable is 2.0.1 32 | 33 | [WARNING] 34 | The vRP database configuration is not supported; oxmysql configuration must be used instead. + 35 | The `multipleStatements` option must be enabled in the connection string (e.g., `mysql://root:password@localhost/vrp?multipleStatements=true`). 36 | -------------------------------------------------------------------------------- /vrp_ghmattimysql-js/__resource.lua: -------------------------------------------------------------------------------- 1 | resource_manifest_version "44febabe-d386-4d18-afbe-5e627f4af937" 2 | 3 | description "vRP GHMattiMySQL (JS) db driver bridge" 4 | 5 | dependencies{ 6 | "vrp", 7 | "ghmattimysql" 8 | } 9 | 10 | -- server scripts 11 | server_scripts{ 12 | "@vrp/lib/utils.lua", 13 | "init.lua" 14 | } 15 | -------------------------------------------------------------------------------- /vrp_ghmattimysql-js/fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version "adamant" 2 | games {"gta5"} 3 | 4 | description "vRP GHMattiMySQL (JS) db driver bridge" 5 | 6 | dependencies{ 7 | "vrp", 8 | "ghmattimysql" 9 | } 10 | 11 | -- server scripts 12 | server_scripts{ 13 | "@vrp/lib/utils.lua", 14 | "init.lua" 15 | } 16 | -------------------------------------------------------------------------------- /vrp_ghmattimysql-js/init.lua: -------------------------------------------------------------------------------- 1 | local Proxy = module("vrp", "lib/Proxy") 2 | local vRP = Proxy.getInterface("vRP") 3 | 4 | async(function() 5 | vRP.loadScript("vrp_ghmattimysql-js", "init_vrp") 6 | end) 7 | -------------------------------------------------------------------------------- /vrp_ghmattimysql-js/init_vrp.lua: -------------------------------------------------------------------------------- 1 | local DBDriver = class("ghmattimysql-js", vRP.DBDriver) 2 | 3 | -- STATIC 4 | 5 | local function blob2string(blob) 6 | local data = {} 7 | for i, byte in ipairs(blob) do data[i] = string.char(byte) end 8 | return table.concat(data) 9 | end 10 | 11 | -- METHODS 12 | 13 | function DBDriver:onInit(cfg) 14 | self.queries = {} 15 | self.API = exports["ghmattimysql"] 16 | return self.API ~= nil 17 | end 18 | 19 | function DBDriver:onPrepare(name, query) 20 | self.queries[name] = query 21 | end 22 | 23 | function DBDriver:onQuery(name, params, mode) 24 | local query = self.queries[name] 25 | local _params = {_ = true} -- force as map 26 | for k,v in pairs(params) do _params[k] = v end 27 | 28 | local r = async() 29 | if mode == "execute" then 30 | self.API:execute(query, _params, function(data) 31 | r(data.affectedRows or 0) 32 | end) 33 | elseif mode == "scalar" then 34 | self.API:scalar(query, _params, function(scalar) 35 | r(scalar) 36 | end) 37 | else 38 | self.API:execute(query, _params, function(rows) 39 | -- last insert id backwards compatibility 40 | if query:find(";.-SELECT.+LAST_INSERT_ID%(%)") then rows = rows[#rows] end 41 | 42 | for _,row in pairs(rows) do 43 | for k,v in pairs(row) do 44 | if type(v) == "table" then 45 | row[k] = blob2string(v) 46 | end 47 | end 48 | end 49 | r(rows, #rows) 50 | end) 51 | end 52 | 53 | return r:wait() 54 | end 55 | 56 | async(function() 57 | vRP:registerDBDriver(DBDriver) 58 | end) 59 | -------------------------------------------------------------------------------- /vrp_ghmattimysql/__resource.lua: -------------------------------------------------------------------------------- 1 | resource_manifest_version "44febabe-d386-4d18-afbe-5e627f4af937" 2 | 3 | description "vRP GHMattiMySQL db driver bridge" 4 | 5 | dependencies{ 6 | "vrp", 7 | "GHMattiMySQL" 8 | } 9 | 10 | -- server scripts 11 | server_scripts{ 12 | "@vrp/lib/utils.lua", 13 | "init.lua" 14 | } 15 | -------------------------------------------------------------------------------- /vrp_ghmattimysql/fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version "adamant" 2 | games {"gta5"} 3 | 4 | description "vRP GHMattiMySQL db driver bridge" 5 | 6 | dependencies{ 7 | "vrp", 8 | "GHMattiMySQL" 9 | } 10 | 11 | -- server scripts 12 | server_scripts{ 13 | "@vrp/lib/utils.lua", 14 | "init.lua" 15 | } 16 | -------------------------------------------------------------------------------- /vrp_ghmattimysql/init.lua: -------------------------------------------------------------------------------- 1 | local Proxy = module("vrp", "lib/Proxy") 2 | local vRP = Proxy.getInterface("vRP") 3 | 4 | async(function() 5 | vRP.loadScript("vrp_ghmattimysql", "init_vrp") 6 | end) 7 | -------------------------------------------------------------------------------- /vrp_ghmattimysql/init_vrp.lua: -------------------------------------------------------------------------------- 1 | local DBDriver = class("ghmattimysql", vRP.DBDriver) 2 | 3 | -- STATIC 4 | 5 | local function blob2string(blob) 6 | for i,c in pairs(blob) do 7 | blob[i] = string.char(c) 8 | end 9 | 10 | return table.concat(blob) 11 | end 12 | 13 | -- METHODS 14 | 15 | function DBDriver:onInit(cfg) 16 | self.queries = {} 17 | self.API = exports["GHMattiMySQL"] 18 | if self.API then 19 | self.API:Query("SELECT 1") -- multiple Buffer issue fix 20 | end 21 | return self.API ~= nil 22 | end 23 | 24 | function DBDriver:onPrepare(name, query) 25 | self.queries[name] = query 26 | end 27 | 28 | function DBDriver:onQuery(name, params, mode) 29 | local query = self.queries[name] 30 | 31 | local _params = {} 32 | _params._ = true -- force as dictionary 33 | 34 | for k,v in pairs(params) do 35 | _params["@"..k] = v 36 | end 37 | 38 | local r = async() 39 | 40 | if mode == "execute" then 41 | self.API:QueryAsync(query, _params, function(affected) 42 | r(affected or 0) 43 | end) 44 | elseif mode == "scalar" then 45 | self.API:QueryScalarAsync(query, _params, function(scalar) 46 | r(scalar) 47 | end) 48 | else 49 | self.API:QueryResultAsync(query, _params, function(rows) 50 | for _,row in pairs(rows) do 51 | for k,v in pairs(row) do 52 | if type(v) == "table" then 53 | row[k] = blob2string(v) 54 | end 55 | end 56 | end 57 | 58 | r(rows, #rows) 59 | end) 60 | end 61 | 62 | return r:wait() 63 | end 64 | 65 | async(function() 66 | vRP:registerDBDriver(DBDriver) 67 | end) 68 | -------------------------------------------------------------------------------- /vrp_icmysql/fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version "adamant" 2 | games {"gta5"} 3 | 4 | description "vRP icmysql db driver bridge" 5 | 6 | dependencies{ 7 | "vrp", 8 | "icmysql" 9 | } 10 | 11 | -- server scripts 12 | server_scripts{ 13 | "@vrp/lib/utils.lua", 14 | "init.lua" 15 | } 16 | -------------------------------------------------------------------------------- /vrp_icmysql/init.lua: -------------------------------------------------------------------------------- 1 | local Proxy = module("vrp", "lib/Proxy") 2 | local vRP = Proxy.getInterface("vRP") 3 | 4 | async(function() 5 | vRP.loadScript("vrp_icmysql", "init_vrp") 6 | end) 7 | -------------------------------------------------------------------------------- /vrp_icmysql/init_vrp.lua: -------------------------------------------------------------------------------- 1 | local DBDriver = class("icmysql", vRP.DBDriver) 2 | 3 | -- STATIC 4 | 5 | local function blob2string(blob) 6 | local data = {} 7 | for index,byte in ipairs(blob) do 8 | table.insert(data, string.char(byte)) 9 | end 10 | 11 | return table.concat(data) 12 | end 13 | 14 | -- METHODS 15 | 16 | function DBDriver:onInit(cfg) 17 | self.queries = {} 18 | self.API = exports["icmysql"] 19 | return self.API ~= nil 20 | end 21 | 22 | function DBDriver:onPrepare(name, query) 23 | self.queries[name] = query 24 | end 25 | 26 | function DBDriver:onQuery(name, params, mode) 27 | local query = self.queries[name] 28 | 29 | local r = async() 30 | 31 | if mode == "execute" then 32 | self.API:Raw(query, params, function (affectedRows) 33 | r(affectedRows or 0) 34 | end) 35 | elseif mode == "scalar" then 36 | self.API:Scalar(query, params, function (result) 37 | r(result) 38 | end) 39 | else 40 | self.API:Query(query, params, function (result) 41 | -- last insert id backwards compatibility 42 | if query:find(";.-SELECT.+LAST_INSERT_ID%(%)") then 43 | r({ { id = result[1].insertId } }, result[1].affectedRows) 44 | end 45 | 46 | for _,row in pairs(result) do 47 | for k,v in pairs(row) do 48 | if type(v) == "table" then 49 | row[k] = blob2string(v) 50 | end 51 | end 52 | end 53 | 54 | r(result, #result) 55 | end) 56 | end 57 | 58 | return r:wait() 59 | end 60 | 61 | async(function() 62 | vRP:registerDBDriver(DBDriver) 63 | end) 64 | -------------------------------------------------------------------------------- /vrp_oxmysql/__resource.lua: -------------------------------------------------------------------------------- 1 | resource_manifest_version "44febabe-d386-4d18-afbe-5e627f4af937" 2 | 3 | description "vRP oxmysql db driver bridge" 4 | 5 | dependencies{ 6 | "vrp", 7 | "oxmysql" 8 | } 9 | 10 | -- server scripts 11 | server_scripts{ 12 | "@vrp/lib/utils.lua", 13 | "init.lua" 14 | } 15 | -------------------------------------------------------------------------------- /vrp_oxmysql/fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version "adamant" 2 | games {"gta5"} 3 | 4 | description "vRP oxmysql db driver bridge" 5 | 6 | dependencies{ 7 | "vrp", 8 | "oxmysql" 9 | } 10 | 11 | -- server scripts 12 | server_scripts{ 13 | "@vrp/lib/utils.lua", 14 | "init.lua" 15 | } 16 | -------------------------------------------------------------------------------- /vrp_oxmysql/init.lua: -------------------------------------------------------------------------------- 1 | local Proxy = module("vrp", "lib/Proxy") 2 | local vRP = Proxy.getInterface("vRP") 3 | 4 | async(function() 5 | vRP.loadScript("vrp_oxmysql", "init_vrp") 6 | end) 7 | -------------------------------------------------------------------------------- /vrp_oxmysql/init_vrp.lua: -------------------------------------------------------------------------------- 1 | local DBDriver = class("oxmysql", vRP.DBDriver) 2 | 3 | -- STATIC 4 | 5 | local function blob2string(blob) 6 | local data = {} 7 | for index,byte in ipairs(blob) do 8 | table.insert(data, string.char(byte)) 9 | end 10 | 11 | return table.concat(data) 12 | end 13 | 14 | -- METHODS 15 | 16 | function DBDriver:onInit(cfg) 17 | self.queries = {} 18 | self.API = exports["oxmysql"] 19 | return self.API ~= nil 20 | end 21 | 22 | function DBDriver:onPrepare(name, query) 23 | self.queries[name] = query 24 | end 25 | 26 | function DBDriver:onQuery(name, params, mode) 27 | local query = self.queries[name] 28 | 29 | local r = async() 30 | 31 | if mode == "execute" then 32 | self.API:update(query, params, function (affectedRows) 33 | r(affectedRows or 0) 34 | end) 35 | elseif mode == "scalar" then 36 | self.API:scalar(query, params, function (result) 37 | r(result) 38 | end) 39 | else 40 | self.API:query(query, params, function (result) 41 | -- last insert id backwards compatibility 42 | if query:find(";.-SELECT.+LAST_INSERT_ID%(%)") then 43 | r({ { id = result[1].insertId } }, result[1].affectedRows) 44 | end 45 | 46 | for _,row in pairs(result) do 47 | for k,v in pairs(row) do 48 | if type(v) == "table" then 49 | row[k] = blob2string(v) 50 | end 51 | end 52 | end 53 | 54 | r(result, #result) 55 | end) 56 | end 57 | 58 | return r:wait() 59 | end 60 | 61 | async(function() 62 | vRP:registerDBDriver(DBDriver) 63 | end) 64 | --------------------------------------------------------------------------------