format SQL queries

This commit is contained in:
erik-sn committed 2020-09-26 20:53:13 -04:00
1 parent 929d9fc816
commit 1157906def
1 file changed
+41 -24
+41 -24
View File
@@ -39,29 +39,41 @@ ESX.RegisterServerCallback('phone:createTweet', function(source, cb, data)
local xPlayer = ESX.GetPlayerFromId(_source) local xPlayer = ESX.GetPlayerFromId(_source)
local _identifier = xPlayer.getIdentifier() local _identifier = xPlayer.getIdentifier()
MySQL.Async.execute('INSERT INTO npwd_twitter_tweets (`identifier`, `realUser`, `message`, `images`) VALUES (@identifier, @realUser, @message, @images)', MySQL.Async.execute([[
INSERT INTO npwd_twitter_tweets (`identifier`, `realUser`, `message`, `images`)
VALUES (@identifier, @realUser, @message, @images)
]],
{ {
['identifier'] = _identifier, identifier = _identifier,
['realUser'] = data.realUser, realUser = data.realUser,
['message'] = data.message, message = data.message,
['images'] = data.images images = data.images
}, function(result) },
function(result)
cb(result) cb(result)
end) end)
end) end)
function getProfile(identifier, cb) function getProfile(identifier, cb)
MySQL.Async.fetchAll('SELECT * FROM npwd_twitter_profiles WHERE identifier = @identifier', MySQL.Async.fetchAll([[
{ SELECT * FROM npwd_twitter_profiles
['identifier'] = identifier, WHERE identifier = @identifier
}, function(result) ]],
{ identifier = identifier },
function(result)
cb(result) cb(result)
end) end)
end end
function getProfileName(identifier, cb) function getProfileName(identifier, cb)
local defaultProfileName = '' -- handle any edge cases where the user does not exist or their name isn't populated local defaultProfileName = '' -- handle any edge cases where the user does not exist or their name isn't populated
MySQL.Async.fetchAll('SELECT first_name, last_name FROM users WHERE identifier = @identifier LIMIT 1', {['identifier'] = identifier }, function(users) MySQL.Async.fetchAll([[
SELECT first_name, last_name
FROM users
WHERE identifier = @identifier LIMIT 1
]],
{ identifier = identifier },
function(users)
-- no user found with this identifier -- no user found with this identifier
if next(users) == nil then if next(users) == nil then
cb(defaultProfileName) cb(defaultProfileName)
@@ -81,11 +93,12 @@ end
function createDefaultProfile(identifier, cb) function createDefaultProfile(identifier, cb)
getProfileName(identifier, function(profileName) getProfileName(identifier, function(profileName)
MySQL.Async.execute('INSERT INTO npwd_twitter_profiles (`identifier`, `profile_name`) VALUES (@identifier, @profile_name)', MySQL.Async.execute([[
{ INSERT INTO npwd_twitter_profiles (`identifier`, `profile_name`)
['identifier'] = identifier, VALUES (@identifier, @profile_name)
['profile_name'] = profileName, ]],
}, function(result) { identifier = identifier, profileName = profileName },
function(result)
if result == 1 then -- if we created the profile then return it if result == 1 then -- if we created the profile then return it
getProfile(identifier, cb) getProfile(identifier, cb)
else -- otherwise just give back the failed result else -- otherwise just give back the failed result
@@ -120,15 +133,19 @@ ESX.RegisterServerCallback('phone:getOrCreateTwitterProfile', function(source, c
end) end)
function updateProfile(identifier, data, cb) function updateProfile(identifier, data, cb)
MySQL.Async.execute('UPDATE npwd_twitter_profiles SET avatar_url = @avatar_url, profile_name = @profile_name, bio = @bio, location = @location, job = @job WHERE identifier = @identifier', MySQL.Async.execute([[
UPDATE npwd_twitter_profiles
SET avatar_url = @avatar_url, profile_name = @profile_name, bio = @bio, location = @location, job = @job WHERE identifier = @identifier
]],
{ {
['identifier'] = identifier, identifier = identifier,
['avatar_url'] = data.avatar_url, avatar_url= data.avatar_url,
['profile_name'] = data.profile_name, profile_name = data.profile_name,
['bio'] = data.bio, bio = data.bio,
['location'] = data.location, location = data.location,
['job'] = data.job, job = data.job,
}, function(result) },
function(result)
cb(result) cb(result)
end) end)
end end