'Sending info to database and retrieving as well as using for k,v, in pairs() do

Issue i have come across is i have an item, if you use this item it writes to the database with your id and the item name. which is correct and this is what i want to happen, but i want it to first look at the database and see if the item is already there and if so stop the insert.

This is the item.

QBCore.Functions.CreateUseableItem("pumpshotgun_bp", function(source, item)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    if Player.Functions.GetItemBySlot(item.slot) ~= nil then
        QBCore.Functions.TriggerCallback('sin-crafting:server:getCrafts', src, function(result)
            if result ~= nil then 
                TriggerClientEvent("sin-crafting:client:Update", source, "pumpshotgun_bp")
            end
        end)
    end
end)

after that i query the info to the database

QBCore.Functions.CreateCallback('sin-crafting:server:getCrafts', function(source, cb)
    local Player = QBCore.Functions.GetPlayer(source)
    local cid = Player.PlayerData.citizenid
    local printList = {}
    MySQL.query('SELECT * FROM player_crafts WHERE cid = ?', { Player.PlayerData.citizenid }, function(crafts, item)
        for k, v in pairs(crafts) do
            if v == nil then 
               
            end
            table.insert(printList,
                {
                    citizenid = v.citizenid, 
                    blueprint = v.blueprint, 
                }
            )
        end
        cb(json.encode(printList))
    end)
end)  

and then

the item then triggers this when used and changed info from the item_bp to the actual name for the database

RegisterNetEvent('sin-crafting:client:Update', function(data)
    if data == "pumpshotgun_bp" then
        TriggerServerEvent('sin-crafting:server:newBlueprint', 'pumpshotgun')
    end
end)

Problem now is when i use that item again it will write it again to the database and i dont want that i want instead to set up a notify script that will tell them they have already learned that.

This is the first half of my issue, the second half is pulling the list from the database and and checking it in the script. I really need help as I have been trying to do this for over a week now and cant find a way to do it

This is the config to use for the for k,v in pairs() do, <---which I cant figure out how to do right....

Config.Weapons = {
    "pumpshotgun",
    "dbshotgun",
    "assaultrifle",
    "smg",
    "combatpistol",
    "gusenberg",
    "microsmg",
    "carbinerifle",
    "compactrifle",
    "heavypistol",
    "machinepistol",
    "revolver",

    "rifle_silencer",
    "pistol_silencer",
    "smg_silencer",
    "shotgun_silencer",

    "weapon_optics",
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source